Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
feat: add reconnecting logic to normal swaps (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 authored Mar 11, 2019
1 parent 7b38103 commit 8da500e
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/views/swap/swapActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const handleSwapStatus = (data, source, dispatch, callback) => {
break;

default:
console.log(`Unknown swap status: ${data}`);
console.log(`Unknown swap status: ${JSON.stringify(data)}`);
break;
}
};
Expand All @@ -119,9 +119,29 @@ export const startListening = (dispatch, swapId, callback) => {
})
);

source.onmessage = event => {
const data = JSON.parse(event.data);
source.onerror = () => {
source.close();

console.log(`Lost connection to Boltz`);
const url = `${boltzApi}/swapstatus`;

const interval = setInterval(() => {
axios
.post(url, {
id: swapId,
})
.then(statusReponse => {
clearInterval(interval);

handleSwapStatus(data, source, dispatch, callback);
console.log(`Reconnected to Boltz`);

startListening(dispatch, swapId, callback);
handleSwapStatus(statusReponse.data, source, dispatch, callback);
});
}, 1000);
};

source.onmessage = event => {
handleSwapStatus(JSON.parse(event.data), source, dispatch, callback);
};
};

0 comments on commit 8da500e

Please sign in to comment.