import { useEffect } from 'react' ; import { useRemoteControlledDialog } from '@masknet/shared' ; import { TransactionState , TransactionStateType } from '@masknet/web3-shared-evm' ; import { WalletMessages } from '../../plugins/Wallet/messages' ; export function useTransactionDialog ( event , state , stateType , resetCallback ) { const { open , setDialog } = useRemoteControlledDialog ( WalletMessages . events . transactionDialogUpdated , ( ev ) => { if ( ev . open ) return ; if ( state . type !== stateType ) return ; resetCallback ( ) ; } ) ; useEffect ( ( ) => { if ( state . type === TransactionStateType . UNKNOWN ) return ; setDialog ( { open : open || state . type === TransactionStateType . WAIT_FOR_CONFIRMING , state : state , ... event , } ) ; } , [ state ] ) ; }