fix(governance): dont start listening for pending eth events until connected (#3996)

This commit is contained in:
Matthew Russell 2023-05-30 13:48:01 -07:00 committed by GitHub
parent ef25552311
commit 653ca034f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,32 +3,32 @@ import { usePendingBalancesStore } from './use-pending-balances-manager';
import type { Contract } from 'ethers'; import type { Contract } from 'ethers';
import { useListenForPendingEthEvents } from './use-listen-for-pending-eth-events'; import { useListenForPendingEthEvents } from './use-listen-for-pending-eth-events';
import { prepend0x } from '@vegaprotocol/smart-contracts'; import { prepend0x } from '@vegaprotocol/smart-contracts';
import { useWeb3React } from '@web3-react/core';
export const useListenForStakingEvents = ( export const useListenForStakingEvents = (
contract: Contract | undefined, contract: Contract | undefined,
vegaPublicKey: string | null, vegaPublicKey: string | null,
numberOfConfirmations: number numberOfConfirmations: number
) => { ) => {
const { account } = useWeb3React();
const { addPendingTxs, removePendingTx, resetPendingTxs } = const { addPendingTxs, removePendingTx, resetPendingTxs } =
usePendingBalancesStore((state) => ({ usePendingBalancesStore((state) => ({
addPendingTxs: state.addPendingTxs, addPendingTxs: state.addPendingTxs,
removePendingTx: state.removePendingTx, removePendingTx: state.removePendingTx,
resetPendingTxs: state.resetPendingTxs, resetPendingTxs: state.resetPendingTxs,
})); }));
const addFilter = useMemo( const addFilter = useMemo(() => {
() => if (!account || !vegaPublicKey || !contract) return null;
vegaPublicKey && contract return contract.filters.Stake_Deposited(
? contract.filters.Stake_Deposited(null, null, prepend0x(vegaPublicKey)) null,
: null, null,
[contract, vegaPublicKey] prepend0x(vegaPublicKey)
); );
const removeFilter = useMemo( }, [contract, vegaPublicKey, account]);
() => const removeFilter = useMemo(() => {
vegaPublicKey && contract if (!account || !vegaPublicKey || !contract) return null;
? contract.filters.Stake_Removed(null, null, prepend0x(vegaPublicKey)) return contract.filters.Stake_Removed(null, null, prepend0x(vegaPublicKey));
: null, }, [contract, vegaPublicKey, account]);
[contract, vegaPublicKey]
);
/** /**
* Listen for all add stake events * Listen for all add stake events