Skip to content

Commit

Permalink
fix: web socket initiate twice bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
LijuJoseJJ committed Mar 24, 2022
1 parent b944774 commit d2ab853
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions wallet/src/hooks/User/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const UserProvider = ({ children }) => {

let messageEventHandler;
React.useEffect(() => {
const {socket, zkpKeys} = state;
const { socket, zkpKeys } = state;
if (!socket) return;
if (messageEventHandler) {
socket.removeEventListener('message', messageEventHandler);
Expand All @@ -126,9 +126,11 @@ export const UserProvider = ({ children }) => {
await acc; // Acc is a promise so we await it before processing the next one;
return blockProposedEventHandler(curr, [zkpKeys.ivk], [zkpKeys.nsk]); // TODO Should be array
}, Promise.resolve());
} else if (parsed.type === 'blockProposed') await blockProposedEventHandler(parsed.data, zkpKeys.ivk, zkpKeys.nsk);
} else if (parsed.type === 'blockProposed') {
await blockProposedEventHandler(parsed.data, zkpKeys.ivk, zkpKeys.nsk);
}
// TODO Rollback Handler
}
};

socket.addEventListener('message', messageEventHandler);
}, [state.zkpKeys]);
Expand Down

0 comments on commit d2ab853

Please sign in to comment.