fix: multisig data disappears while signing multiple multisig tx's from same account (#11552)

* fix: prevent duplicate trigger increments in useMultisigApprovals hook

* chore: lint
This commit is contained in:
rajk93 2025-05-15 12:25:11 +05:30 committed by GitHub
parent fc6e5086a6
commit 7ef2b3e71f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<string>('');
// 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