diff --git a/packages/page-accounts/src/Accounts/useMultisigApprovals.ts b/packages/page-accounts/src/Accounts/useMultisigApprovals.ts index 466e1b13ec..358ebfff0e 100644 --- a/packages/page-accounts/src/Accounts/useMultisigApprovals.ts +++ b/packages/page-accounts/src/Accounts/useMultisigApprovals.ts @@ -4,7 +4,7 @@ import type { Option, StorageKey } from '@polkadot/types'; import type { H256, Multisig } from '@polkadot/types/interfaces'; -import { useEffect, useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { createNamedHook, useApi, useBlockEvents, useIncrement, useIsMountedRef } from '@polkadot/react-hooks'; @@ -14,20 +14,29 @@ function useMultisigApprovalsImpl (address: string): [H256, Multisig][] | undefi const [multiInfos, setMultiInfos] = useState<[H256, Multisig][] | undefined>(); const [trigger, incTrigger] = useIncrement(1); const mountedRef = useIsMountedRef(); + const prevEventsRef = useRef(''); // increment the trigger by looking at all events // - filter the by multisig module (old utility is not supported) // - find anything data item where the type is AccountId - // - increment the trigger when at least one matches our address + // - increment the trigger when at least one matches our address and is different from previous multisig events useEffect((): void => { - events - .some(({ record: { event: { data, section } } }) => - section === 'multisig' && - data.some((item) => - item.toRawType() === 'AccountId' && - item.eq(address) - ) - ) && incTrigger(); + const multisigEvents = events.filter(({ record: { event: { data, section } } }) => + section === 'multisig' && + data.some((item) => + item.toRawType() === 'AccountId' && + item.eq(address) + ) + ); + + if (multisigEvents.length) { + const eventsHash = JSON.stringify(multisigEvents.map((e) => e.key)); + + if (eventsHash !== prevEventsRef.current) { + prevEventsRef.current = eventsHash; + incTrigger(); + } + } }, [address, events, incTrigger]); // query all the entries for the multisig, extracting approvals with their hash