diff --git a/packages/react-signer/src/Address.tsx b/packages/react-signer/src/Address.tsx index 530cc01953..a2f47d99d3 100644 --- a/packages/react-signer/src/Address.tsx +++ b/packages/react-signer/src/Address.tsx @@ -60,12 +60,26 @@ function findCall (tx: Call | SubmittableExtrinsic<'promise'>): { method: string } function filterProxies (allAccounts: string[], tx: Call | SubmittableExtrinsic<'promise'>, proxies: [string, BN, NodeRuntimeProxyType][]): string[] { + // get the call info + const { method, section } = findCall(tx); + // check an array of calls to all have proxies as the address const checkCalls = (address: string, txs: Call[]): boolean => !txs.some((tx) => !filterProxies(allAccounts, tx, proxies).includes(address)); - // get the call info - const { method, section } = findCall(tx); + // inspect nested calls, e.g. batch, ensuring that the proxy address + // is applicable to the containing calls + const checkNested = (address: string): boolean => + section === 'utility' && ( + ( + ['batch', 'batchAll'].includes(method) && + checkCalls(address, tx.args[0] as Vec) + ) || + ( + ['asLimitedSub'].includes(method) && + checkCalls(address, [tx.args[0] as Call]) + ) + ); return proxies .filter(([address, delay, proxy]): boolean => { @@ -77,21 +91,43 @@ function filterProxies (allAccounts: string[], tx: Call | SubmittableExtrinsic<' switch (proxy.toString()) { case 'Any': return true; + case 'Governance': - return ['council', 'democracy', 'elections', 'electionsPhragmen', 'phragmenElection', 'poll', 'society', 'technicalCommittee', 'tips', 'treasury'].includes(section); + return checkNested(address) || ( + ['council', 'democracy', 'elections', 'electionsPhragmen', 'phragmenElection', 'poll', 'society', 'technicalCommittee', 'tips', 'treasury'].includes(section) + ); + case 'IdentityJudgement': - return section === 'identity' && method === 'provideJudgement'; + return checkNested(address) || ( + section === 'identity' && + method === 'provideJudgement' + ); + case 'NonTransfer': - return !(section === 'balances' || (section === 'indices' && method === 'transfer') || (section === 'vesting' && method === 'vestedTransfer')); + return !( + section === 'balances' || + ( + section === 'indices' && + method === 'transfer' + ) || + ( + section === 'vesting' && + method === 'vestedTransfer' + ) + ); + case 'Staking': - return section === 'staking' || - (section === 'utility' && ( - (method === 'batch' && checkCalls(address, tx.args[0] as Vec)) || - (method === 'asLimitedSub' && checkCalls(address, [tx.args[0] as Call])) - )); + return checkNested(address) || ( + section === 'staking' + ); + case 'SudoBalances': - return (section === 'sudo' && (method === 'sudo' && findCall(tx.args[0] as Call).section === 'balances')) || - (section === 'utility' && (method === 'batch' && checkCalls(address, tx.args[0] as Vec))); + return checkNested(address) || ( + section === 'sudo' && + method === 'sudo' && + findCall(tx.args[0] as Call).section === 'balances' + ); + default: // any unknown proxy types apply to all - leave it to the user to filter return true;