From 653ca034f271a70212dd072f488f3822c5034613 Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Tue, 30 May 2023 13:48:01 -0700 Subject: [PATCH] fix(governance): dont start listening for pending eth events until connected (#3996) --- .../hooks/use-listen-for-staking-events.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/apps/governance/src/hooks/use-listen-for-staking-events.ts b/apps/governance/src/hooks/use-listen-for-staking-events.ts index 4302d3c9c..56f03d854 100644 --- a/apps/governance/src/hooks/use-listen-for-staking-events.ts +++ b/apps/governance/src/hooks/use-listen-for-staking-events.ts @@ -3,32 +3,32 @@ import { usePendingBalancesStore } from './use-pending-balances-manager'; import type { Contract } from 'ethers'; import { useListenForPendingEthEvents } from './use-listen-for-pending-eth-events'; import { prepend0x } from '@vegaprotocol/smart-contracts'; +import { useWeb3React } from '@web3-react/core'; export const useListenForStakingEvents = ( contract: Contract | undefined, vegaPublicKey: string | null, numberOfConfirmations: number ) => { + const { account } = useWeb3React(); const { addPendingTxs, removePendingTx, resetPendingTxs } = usePendingBalancesStore((state) => ({ addPendingTxs: state.addPendingTxs, removePendingTx: state.removePendingTx, resetPendingTxs: state.resetPendingTxs, })); - const addFilter = useMemo( - () => - vegaPublicKey && contract - ? contract.filters.Stake_Deposited(null, null, prepend0x(vegaPublicKey)) - : null, - [contract, vegaPublicKey] - ); - const removeFilter = useMemo( - () => - vegaPublicKey && contract - ? contract.filters.Stake_Removed(null, null, prepend0x(vegaPublicKey)) - : null, - [contract, vegaPublicKey] - ); + const addFilter = useMemo(() => { + if (!account || !vegaPublicKey || !contract) return null; + return contract.filters.Stake_Deposited( + null, + null, + prepend0x(vegaPublicKey) + ); + }, [contract, vegaPublicKey, account]); + const removeFilter = useMemo(() => { + if (!account || !vegaPublicKey || !contract) return null; + return contract.filters.Stake_Removed(null, null, prepend0x(vegaPublicKey)); + }, [contract, vegaPublicKey, account]); /** * Listen for all add stake events