From c4115a693efbe147f2a8699dbe110a1727400075 Mon Sep 17 00:00:00 2001 From: Thibaut Sardan Date: Mon, 9 Dec 2024 18:14:42 +0100 Subject: [PATCH] check wc account and network --- packages/ui/src/components/CallInfo.tsx | 23 +++++++++++---- .../modals/WalletConnectSessionProposal.tsx | 5 ++-- .../modals/WalletConnectSigning.tsx | 28 ++++++++++++++++++- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/packages/ui/src/components/CallInfo.tsx b/packages/ui/src/components/CallInfo.tsx index 382e7693..28651cc3 100644 --- a/packages/ui/src/components/CallInfo.tsx +++ b/packages/ui/src/components/CallInfo.tsx @@ -52,7 +52,12 @@ const isWhiteListedCall = (type: string, value: string) => { 'Staking.nominate', 'Proxy.add_proxy', 'Proxy.remove_proxy', - 'Proxy.kill_pure' + 'Proxy.kill_pure', + 'ConvictionVoting.delegate', + 'ConvictionVoting.vote', + 'ConvictionVoting.remove_vote', + 'ConvictionVoting.undelegate', + 'ConvictionVoting.unlock' ].includes(`${type}.${value}`) } @@ -71,7 +76,9 @@ const formatBalance = (amount: bigint, label: string, chainInfo: ChainInfoHuman, const eachFieldRendered = (value: Record, chainInfo: ChainInfoHuman, id: string) => { // for transfer, nomination, staking, bounties - const bigIntKey = ['value', 'fee', 'max_additional'].find((key) => typeof value[key] === 'bigint') + const bigIntKey = ['value', 'fee', 'max_additional', 'balance'].find( + (key) => typeof value[key] === 'bigint' + ) if (bigIntKey) { return formatBalance(value[bigIntKey], bigIntKey, chainInfo, id) @@ -120,9 +127,15 @@ const eachFieldRendered = (value: Record, chainInfo: ChainInfoHuman } // that's an Account with MultiAddress.Id - const multiAddressKey = ['dest', 'beneficiary', 'curator', 'delegate', 'spawner'].find( - (key) => typeof value[key] === 'object' && value[key].type === 'Id' - ) + const multiAddressKey = [ + 'dest', + 'beneficiary', + 'curator', + 'delegate', + 'spawner', + 'to', + 'target' + ].find((key) => typeof value[key] === 'object' && value[key].type === 'Id') if (multiAddressKey) { return ( diff --git a/packages/ui/src/components/modals/WalletConnectSessionProposal.tsx b/packages/ui/src/components/modals/WalletConnectSessionProposal.tsx index 5d92dc9a..843ecf42 100644 --- a/packages/ui/src/components/modals/WalletConnectSessionProposal.tsx +++ b/packages/ui/src/components/modals/WalletConnectSessionProposal.tsx @@ -72,7 +72,8 @@ const WalletConnectSessionProposal = ({ onClose, className, sessionProposal }: P polkadot: { accounts: accountsToShare, methods, - events + events, + chains } } }) @@ -81,7 +82,7 @@ const WalletConnectSessionProposal = ({ onClose, className, sessionProposal }: P onClose() refresh() }) - }, [accountsToShare, events, methods, onClose, refresh, sessionProposal, web3wallet]) + }, [accountsToShare, chains, events, methods, onClose, refresh, sessionProposal, web3wallet]) const onReject = useCallback(() => { if (!web3wallet || !sessionProposal) return diff --git a/packages/ui/src/components/modals/WalletConnectSigning.tsx b/packages/ui/src/components/modals/WalletConnectSigning.tsx index b3795e23..154c5bf1 100644 --- a/packages/ui/src/components/modals/WalletConnectSigning.tsx +++ b/packages/ui/src/components/modals/WalletConnectSigning.tsx @@ -27,6 +27,7 @@ import { useMultisigProposalNeededFunds } from '../../hooks/useMultisigProposalN import { useCheckBalance } from '../../hooks/useCheckBalance' import { formatBigIntBalance } from '../../utils/formatBnBalance' import { getErrorMessageReservedFunds } from '../../utils/getErrorMessageReservedFunds' +import { useGetWalletConnectNamespace } from '../../hooks/useWalletConnectNamespace' export interface SigningModalProps { onClose: () => void @@ -37,6 +38,7 @@ export interface SigningModalProps { const ProposalSigning = ({ onClose, className, request, onSuccess }: SigningModalProps) => { const { api, chainInfo } = useApi() + const { currentNamespace } = useGetWalletConnectNamespace() const [isSubmitting, setIsSubmitting] = useState(false) const { web3wallet } = useWalletConnect() const { @@ -81,6 +83,30 @@ const ProposalSigning = ({ onClose, className, request, onSuccess }: SigningModa address: selectedAccount?.address }) + useEffect(() => { + const requestedChainId = request.params.chainId + if (requestedChainId !== currentNamespace) { + setErrorMessage( + `Wrong selected network in Multix. Please reject, then select the correct network and resubmit the transaction. Request with namespace: ${requestedChainId}` + ) + } + }, [currentNamespace, originAddress, request.params.chainId]) + + const isCorrectMultiproxySelected = useMemo( + () => + selectedMultiProxy?.proxy === originAddress || + selectedMultiProxy?.multisigs.map(({ address }) => address).includes(originAddress), + [selectedMultiProxy, originAddress] + ) + + useEffect(() => { + if (!isCorrectMultiproxySelected) { + setErrorMessage( + `Wrong multisig selected in Multix. Please reject, then select the correct multisig and resubmit the transaction. Request with address: ${originAddress}` + ) + } + }, [isCorrectMultiproxySelected, originAddress]) + useEffect(() => { if (multisigProposalNeededFunds !== 0n && !hasSignerEnoughFunds) { const requiredBalanceString = formatBigIntBalance( @@ -260,7 +286,7 @@ const ProposalSigning = ({ onClose, className, request, onSuccess }: SigningModa callData, name: getExtrinsicName(callInfo?.section, callInfo?.method) }} - expanded + expanded={!errorMessage} />