Skip to content

Commit

Permalink
fix: remove event listener in ummount
Browse files Browse the repository at this point in the history
  • Loading branch information
AMIRKHANEF committed Dec 3, 2024
1 parent 904f1c0 commit 4e8d690
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions packages/extension-polkagate/src/hooks/useAssetsBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export default function useAssetsBalances (accounts: AccountJson[] | null, setAl
return;
}

worker.addEventListener('message', (messageEvent: MessageEvent<string>) => {
const handleMessage = (messageEvent: MessageEvent<string>) => {
const message = messageEvent.data;

if (!message) {
Expand Down Expand Up @@ -384,7 +384,13 @@ export default function useAssetsBalances (accounts: AccountJson[] | null, setAl
console.log('_assets :::', _assets);

combineAndSetAssets(_assets);
});
};

worker.addEventListener('message', handleMessage);

return () => {
worker.removeEventListener('message', handleMessage);
};
}, [combineAndSetAssets, handleRequestCount, worker]);

const fetchAssetOnRelayChain = useCallback((_addresses: string[], chainName: string) => {
Expand Down
10 changes: 8 additions & 2 deletions packages/extension-polkagate/src/hooks/useNFT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function useNFT (accountsFromContext: AccountJson[] | null) {
setFetching(true);
worker.postMessage({ functionName: NFT_FUNCTION_NAME, parameters: { addresses } });

worker.addEventListener('message', (messageEvent: MessageEvent<string>) => {
const handleMessage = (messageEvent: MessageEvent<string>) => {
const NFTs = messageEvent.data;

if (!NFTs) {
Expand Down Expand Up @@ -68,7 +68,13 @@ export default function useNFT (accountsFromContext: AccountJson[] | null) {
saveToStorage(parsedNFTsInfo.results);

// setFetching(false);
});
};

worker.addEventListener('message', handleMessage);

return () => {
worker.removeEventListener('message', handleMessage);
};
}, [notify, saveToStorage, t, worker]);

useEffect(() => {
Expand Down

0 comments on commit 4e8d690

Please sign in to comment.