From 530b89cd16b59126318b81af8fa0c2f6e69b4447 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 15 Dec 2022 16:45:05 +0200 Subject: [PATCH] Adjust w/ function detection for proxy & multisig (#8552) --- packages/page-accounts/src/Accounts/index.tsx | 45 ++++++++++++------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/packages/page-accounts/src/Accounts/index.tsx b/packages/page-accounts/src/Accounts/index.tsx index 3c2f23a2f0..9609772332 100644 --- a/packages/page-accounts/src/Accounts/index.tsx +++ b/packages/page-accounts/src/Accounts/index.tsx @@ -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 = {}; - - accountsWithInfo.forEach(function (x) { + const accountsMap = useMemo( + () => accountsWithInfo.reduce>((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 )}