Skip to content

Commit

Permalink
fix(blockchain-link): stop ripple ping timeout if api disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonlesisz authored and mroz22 committed Jan 29, 2025
1 parent 967fc34 commit 0342e33
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/blockchain-link/src/workers/baseWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export abstract class BaseWorker<API> {
return true;
}
if (data.type === MESSAGES.DISCONNECT) {
this.disconnect();
await this.disconnect();
this.post({ id, type: RESPONSES.DISCONNECTED, payload: true });

return true;
Expand Down
11 changes: 4 additions & 7 deletions packages/blockchain-link/src/workers/ripple/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,7 @@ class RippleWorker extends BaseWorker<RippleAPI> {
}

disconnect() {
if (this.api) {
this.api.disconnect();
}
return this.api?.disconnect();
}

async messageHandler(event: { data: MessageTypes.Message }) {
Expand Down Expand Up @@ -508,10 +506,9 @@ class RippleWorker extends BaseWorker<RippleAPI> {
if (this.pingTimeout) {
clearTimeout(this.pingTimeout);
}
this.pingTimeout = setTimeout(
() => this.onPing(),
this.settings.pingTimeout || DEFAULT_PING_TIMEOUT,
);
this.pingTimeout = this.api?.isConnected()
? setTimeout(() => this.onPing(), this.settings.pingTimeout || DEFAULT_PING_TIMEOUT)
: undefined;
}

async onPing() {
Expand Down

0 comments on commit 0342e33

Please sign in to comment.