diff --git a/libs/web3/src/lib/use-ethereum-transaction-toasts.tsx b/libs/web3/src/lib/use-ethereum-transaction-toasts.tsx index f0e49b482..0e0c365b4 100644 --- a/libs/web3/src/lib/use-ethereum-transaction-toasts.tsx +++ b/libs/web3/src/lib/use-ethereum-transaction-toasts.tsx @@ -1,4 +1,5 @@ import type { ReactNode } from 'react'; +import { useEffect } from 'react'; import { useAssetsDataProvider } from '@vegaprotocol/assets'; import { EtherscanLink } from '@vegaprotocol/environment'; import { formatNumber, toBigNum } from '@vegaprotocol/utils'; @@ -218,12 +219,19 @@ export const useEthereumTransactionToasts = () => { [onClose] ); - useEthTransactionStore.subscribe( - (state) => compact(state.transactions.filter((tx) => tx?.dialogOpen)), - (txs) => { - txs.forEach((tx) => { - setToast(fromEthTransaction(tx)); - }); - } - ); + // Only register a subscription once + useEffect(() => { + const unsubscribe = useEthTransactionStore.subscribe( + (state) => compact(state.transactions.filter((tx) => tx?.dialogOpen)), + (txs) => { + txs.forEach((tx) => { + setToast(fromEthTransaction(tx)); + }); + } + ); + + return () => { + unsubscribe(); + }; + }, []); };