Skip to content

Commit

Permalink
fix: swap update subscription on WS reconnect (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 authored Nov 7, 2024
1 parent f94e7cd commit 419eb52
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/components/SwapChecker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ class BoltzWebSocket {
this.ws?.close();
};

public subscribeUpdates = (ids: string[]) => {
if (ids.every((id) => this.relevantIds.has(id))) {
// "force" skips the check if we already subscribed to all the ids
public subscribeUpdates = (ids: string[], force = false) => {
if (!force && ids.every((id) => this.relevantIds.has(id))) {
return;
}

Expand All @@ -102,7 +103,10 @@ class BoltzWebSocket {
this.ws = new WebSocket(BoltzWebSocket.formatWsUrl(url));

this.ws.onopen = () => {
this.subscribeUpdates(Array.from(this.relevantIds.values()));
this.subscribeUpdates(
Array.from(this.relevantIds.values()),
true,
);
};
this.ws.onclose = (error) => {
log.warn("WebSocket closed", error);
Expand Down

0 comments on commit 419eb52

Please sign in to comment.