Adjust w/ function detection for proxy & multisig (#8552)
This commit is contained in:
parent
534bbba6f6
commit
530b89cd16
@ -11,7 +11,7 @@ import styled from 'styled-components';
|
||||
import { Button, FilterInput, SortDropdown, SummaryBox, Table } from '@polkadot/react-components';
|
||||
import { useAccounts, useApi, useDelegations, useFavorites, useIpfs, useLedger, useLoadingDelay, useProxies, useToggle } from '@polkadot/react-hooks';
|
||||
import { keyring } from '@polkadot/ui-keyring';
|
||||
import { BN_ZERO } from '@polkadot/util';
|
||||
import { BN_ZERO, isFunction } from '@polkadot/util';
|
||||
|
||||
import CreateModal from '../modals/Create';
|
||||
import ImportModal from '../modals/Import';
|
||||
@ -68,10 +68,25 @@ function Overview ({ className = '', onStatusChange }: Props): React.ReactElemen
|
||||
|
||||
// We use favorites only to check if it includes some element,
|
||||
// so Object is better than array for that because hashmap access is O(1).
|
||||
const favoritesMap = useMemo(() => Object.fromEntries(favorites.map((x) => [x, true])), [favorites]);
|
||||
const favoritesMap = useMemo(
|
||||
() => Object.fromEntries(favorites.map((x) => [x, true])),
|
||||
[favorites]
|
||||
);
|
||||
|
||||
const accountsWithInfo = useMemo(() =>
|
||||
allAccounts
|
||||
// detect multisigs
|
||||
const hasPalletMultisig = useMemo(
|
||||
() => isFunction((api.tx.multisig || api.tx.utility)?.approveAsMulti),
|
||||
[api]
|
||||
);
|
||||
|
||||
// proxy support
|
||||
const hasPalletProxy = useMemo(
|
||||
() => isFunction(api.tx.proxy?.addProxy),
|
||||
[api]
|
||||
);
|
||||
|
||||
const accountsWithInfo = useMemo(
|
||||
() => allAccounts
|
||||
.map((address, index): SortedAccount => {
|
||||
const deleg = delegations && delegations[index]?.isDelegating && delegations[index]?.asDelegating;
|
||||
const delegation: Delegation | undefined = (deleg && {
|
||||
@ -86,18 +101,18 @@ function Overview ({ className = '', onStatusChange }: Props): React.ReactElemen
|
||||
delegation,
|
||||
isFavorite: favoritesMap[address ?? ''] ?? false
|
||||
};
|
||||
})
|
||||
, [allAccounts, favoritesMap, delegations]);
|
||||
}),
|
||||
[allAccounts, favoritesMap, delegations]
|
||||
);
|
||||
|
||||
const accountsMap = useMemo(() => {
|
||||
const ret: Record<string, SortedAccount> = {};
|
||||
|
||||
accountsWithInfo.forEach(function (x) {
|
||||
const accountsMap = useMemo(
|
||||
() => accountsWithInfo.reduce<Record<string, SortedAccount>>((ret, x) => {
|
||||
ret[x.address] = x;
|
||||
});
|
||||
|
||||
return ret;
|
||||
}, [accountsWithInfo]);
|
||||
return ret;
|
||||
}, {}),
|
||||
[accountsWithInfo]
|
||||
);
|
||||
|
||||
const header = useRef([
|
||||
[t('accounts'), 'start', 3],
|
||||
@ -258,13 +273,13 @@ function Overview ({ className = '', onStatusChange }: Props): React.ReactElemen
|
||||
)}
|
||||
<Button
|
||||
icon='plus'
|
||||
isDisabled={!(api.tx.multisig || api.tx.utility) || !hasAccounts}
|
||||
isDisabled={!hasPalletMultisig || !hasAccounts}
|
||||
label={t<string>('Multisig')}
|
||||
onClick={toggleMultisig}
|
||||
/>
|
||||
<Button
|
||||
icon='plus'
|
||||
isDisabled={!api.tx.proxy || !hasAccounts}
|
||||
isDisabled={!hasPalletProxy || !hasAccounts}
|
||||
label={t<string>('Proxied')}
|
||||
onClick={toggleProxy}
|
||||
/>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user