Filter non-zero proxy delays (#6388)
* Filter non-zero proxy delays * Check * type import
This commit is contained in:
parent
cecb5fb5b0
commit
f254b44bb7
@ -1,10 +1,12 @@
|
||||
// Copyright 2017-2021 @polkadot/react-signer authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { SubmittableExtrinsic } from '@polkadot/api/types';
|
||||
import type { QueueTx } from '@polkadot/react-components/Status/types';
|
||||
import type { Option, Vec } from '@polkadot/types';
|
||||
import type { AccountId, BalanceOf, Call, Multisig, ProxyDefinition, ProxyType } from '@polkadot/types/interfaces';
|
||||
import type { AccountId, BalanceOf, Call, Multisig } from '@polkadot/types/interfaces';
|
||||
import type { NodeRuntimeProxyType, PalletProxyProxyDefinition } from '@polkadot/types/lookup';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { AddressFlags, AddressProxy } from './types';
|
||||
|
||||
@ -13,7 +15,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
import { InputAddress, MarkError, Modal, Toggle } from '@polkadot/react-components';
|
||||
import { useAccounts, useApi, useIsMountedRef } from '@polkadot/react-hooks';
|
||||
import { isFunction } from '@polkadot/util';
|
||||
import { BN_ZERO, isFunction } from '@polkadot/util';
|
||||
|
||||
import Password from './Password';
|
||||
import { useTranslation } from './translate';
|
||||
@ -43,7 +45,7 @@ interface PasswordState {
|
||||
interface ProxyState {
|
||||
address: string;
|
||||
isProxied: boolean;
|
||||
proxies: [string, ProxyType][];
|
||||
proxies: [string, BN, NodeRuntimeProxyType][];
|
||||
proxiesFilter: string[];
|
||||
}
|
||||
|
||||
@ -57,7 +59,7 @@ function findCall (tx: Call | SubmittableExtrinsic<'promise'>): { method: string
|
||||
}
|
||||
}
|
||||
|
||||
function filterProxies (allAccounts: string[], tx: Call | SubmittableExtrinsic<'promise'>, proxies: [string, ProxyType][]): string[] {
|
||||
function filterProxies (allAccounts: string[], tx: Call | SubmittableExtrinsic<'promise'>, proxies: [string, BN, NodeRuntimeProxyType][]): string[] {
|
||||
// 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));
|
||||
@ -66,8 +68,9 @@ function filterProxies (allAccounts: string[], tx: Call | SubmittableExtrinsic<'
|
||||
const { method, section } = findCall(tx);
|
||||
|
||||
return proxies
|
||||
.filter(([address, proxy]): boolean => {
|
||||
if (!allAccounts.includes(address)) {
|
||||
.filter(([address, delay, proxy]): boolean => {
|
||||
// FIXME Change when we add support for delayed proxies
|
||||
if (!allAccounts.includes(address) || !delay.isZero()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -128,10 +131,10 @@ async function queryForMultisig (api: ApiPromise, requestAddress: string, proxyA
|
||||
async function queryForProxy (api: ApiPromise, allAccounts: string[], address: string, tx: SubmittableExtrinsic<'promise'>): Promise<ProxyState | null> {
|
||||
if (isFunction(api.query.proxy?.proxies)) {
|
||||
const { isProxied } = extractExternal(address);
|
||||
const [_proxies] = await api.query.proxy.proxies<ITuple<[Vec<ITuple<[AccountId, ProxyType]> | ProxyDefinition>, BalanceOf]>>(address);
|
||||
const [_proxies] = await api.query.proxy.proxies<ITuple<[Vec<ITuple<[AccountId, NodeRuntimeProxyType]> | PalletProxyProxyDefinition>, BalanceOf]>>(address);
|
||||
const proxies = api.tx.proxy.addProxy.meta.args.length === 3
|
||||
? (_proxies as ProxyDefinition[]).map(({ delegate, proxyType }): [string, ProxyType] => [delegate.toString(), proxyType])
|
||||
: (_proxies as [AccountId, ProxyType][]).map(([delegate, proxyType]): [string, ProxyType] => [delegate.toString(), proxyType]);
|
||||
? (_proxies as PalletProxyProxyDefinition[]).map(({ delay, delegate, proxyType }): [string, BN, NodeRuntimeProxyType] => [delegate.toString(), delay, proxyType])
|
||||
: (_proxies as [AccountId, NodeRuntimeProxyType][]).map(([delegate, proxyType]): [string, BN, NodeRuntimeProxyType] => [delegate.toString(), BN_ZERO, proxyType]);
|
||||
const proxiesFilter = filterProxies(allAccounts, tx, proxies);
|
||||
|
||||
if (proxiesFilter.length) {
|
||||
@ -153,7 +156,7 @@ function Address ({ currentItem, onChange, onEnter, passwordError, requestAddres
|
||||
const [isProxyActive, setIsProxyActive] = useState(true);
|
||||
const [multiInfo, setMultInfo] = useState<MultiState | null>(null);
|
||||
const [proxyInfo, setProxyInfo] = useState<ProxyState | null>(null);
|
||||
const [{ isUnlockCached, signPassword }, setSignPassword] = useState<PasswordState>({ isUnlockCached: false, signPassword: '' });
|
||||
const [{ isUnlockCached, signPassword }, setSignPassword] = useState<PasswordState>(() => ({ isUnlockCached: false, signPassword: '' }));
|
||||
|
||||
const [signAddress, flags] = useMemo(
|
||||
(): [string, AddressFlags] => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user