Fix accounts not showing with no democracy (#3149)
* Fix accounts not showing with no democracy * Update packages/page-accounts/src/Accounts/Account.tsx * Adjust for Edgeware * Update packages/page-accounts/src/Accounts/Account.tsx * API dep
This commit is contained in:
parent
347de67bce
commit
a678583648
@ -347,36 +347,38 @@ function Account ({ account: { address, meta }, className = '', delegation, filt
|
||||
<AddressMini value={meta.parentAddress} />
|
||||
)}
|
||||
</td>
|
||||
<td className='address ui--media-1500'>
|
||||
{isDelegateOpen && (
|
||||
<DelegateModal
|
||||
amount={delegation?.amount}
|
||||
conviction={delegation?.conviction}
|
||||
delegatedAccount={delegation?.accountDelegated}
|
||||
delegatingAccount={address}
|
||||
key='modal-delegate'
|
||||
onClose={toggleDelegate}
|
||||
/>
|
||||
)}
|
||||
{isUndelegateOpen && (
|
||||
<UndelegateModal
|
||||
accountDelegating={address}
|
||||
key='modal-delegate'
|
||||
onClose={toggleUndelegate}
|
||||
/>
|
||||
)}
|
||||
{delegation && (
|
||||
<AddressMini
|
||||
summary={
|
||||
<div>
|
||||
<FormatBalance value={delegation.amount} />
|
||||
<div>{delegation.conviction.toString()}</div>
|
||||
</div>
|
||||
}
|
||||
value={delegation.accountDelegated}
|
||||
/>
|
||||
)}
|
||||
</td>
|
||||
{api.api.query.democracy?.votingOf && (
|
||||
<td className='address ui--media-1500'>
|
||||
{isDelegateOpen && (
|
||||
<DelegateModal
|
||||
amount={delegation?.amount}
|
||||
conviction={delegation?.conviction}
|
||||
delegatedAccount={delegation?.accountDelegated}
|
||||
delegatingAccount={address}
|
||||
key='modal-delegate'
|
||||
onClose={toggleDelegate}
|
||||
/>
|
||||
)}
|
||||
{isUndelegateOpen && (
|
||||
<UndelegateModal
|
||||
accountDelegating={address}
|
||||
key='modal-delegate'
|
||||
onClose={toggleUndelegate}
|
||||
/>
|
||||
)}
|
||||
{delegation && (
|
||||
<AddressMini
|
||||
summary={
|
||||
<div>
|
||||
<FormatBalance value={delegation.amount} />
|
||||
<div>{delegation.conviction.toString()}</div>
|
||||
</div>
|
||||
}
|
||||
value={delegation.accountDelegated}
|
||||
/>
|
||||
)}
|
||||
</td>
|
||||
)}
|
||||
<td className='number'>
|
||||
<CryptoType accountId={address} />
|
||||
</td>
|
||||
@ -521,27 +523,27 @@ function Account ({ account: { address, meta }, className = '', delegation, filt
|
||||
{t('Multisig approvals')}
|
||||
</Menu.Item>
|
||||
])}
|
||||
{delegation?.accountDelegated && createMenuGroup([
|
||||
(<Menu.Item
|
||||
{api.api.query.democracy?.votingOf && delegation?.accountDelegated && createMenuGroup([
|
||||
<Menu.Item
|
||||
key='changeDelegate'
|
||||
onClick={toggleDelegate}
|
||||
>
|
||||
{t('Change democracy delegation')}
|
||||
</Menu.Item>),
|
||||
(<Menu.Item
|
||||
</Menu.Item>,
|
||||
<Menu.Item
|
||||
key='undelegate'
|
||||
onClick={toggleUndelegate}
|
||||
>
|
||||
{t('Undelegate')}
|
||||
</Menu.Item>)
|
||||
</Menu.Item>
|
||||
])}
|
||||
{!delegation?.accountDelegated && createMenuGroup([
|
||||
(<Menu.Item
|
||||
{api.api.query.democracy?.votingOf && !delegation?.accountDelegated && createMenuGroup([
|
||||
<Menu.Item
|
||||
key='delegate'
|
||||
onClick={toggleDelegate}
|
||||
>
|
||||
{t('Delegate democracy votes')}
|
||||
</Menu.Item>)
|
||||
</Menu.Item>
|
||||
])}
|
||||
<ChainLock
|
||||
className='accounts--network-toggle'
|
||||
|
||||
@ -72,7 +72,7 @@ function Overview ({ className = '', onStatusChange }: Props): React.ReactElemen
|
||||
const [filterOn, setFilter] = useState<string>('');
|
||||
const [sortedAccountsWithDelegation, setSortedAccountsWithDelegation] = useState<SortedAccount[]>([]);
|
||||
const [{ sortedAccounts, sortedAddresses }, setSorted] = useState<Sorted>({ sortedAccounts: [], sortedAddresses: [] });
|
||||
const delegations = useCall<Voting[]>(api.query.democracy.votingOf.multi, [sortedAddresses]);
|
||||
const delegations = useCall<Voting[]>(api.query.democracy?.votingOf?.multi, [sortedAddresses]);
|
||||
|
||||
useEffect((): void => {
|
||||
const sortedAccounts = sortAccounts(allAccounts, favorites);
|
||||
@ -82,31 +82,31 @@ function Overview ({ className = '', onStatusChange }: Props): React.ReactElemen
|
||||
}, [allAccounts, favorites]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!delegations?.length) {
|
||||
if (api.query.democracy?.votingOf && !delegations?.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const sortedAccountsWithDelegation = sortedAccounts?.map((account, index) => {
|
||||
let delegation: Delegation | undefined;
|
||||
setSortedAccountsWithDelegation(
|
||||
sortedAccounts?.map((account, index) => {
|
||||
let delegation: Delegation | undefined;
|
||||
|
||||
if (delegations[index].isDelegating) {
|
||||
const _delegation = delegations[index].asDelegating;
|
||||
if (delegations && delegations[index].isDelegating) {
|
||||
const { balance: amount, conviction, target } = delegations[index].asDelegating;
|
||||
|
||||
delegation = {
|
||||
accountDelegated: _delegation.target.toString(),
|
||||
amount: _delegation.balance,
|
||||
conviction: _delegation.conviction
|
||||
};
|
||||
}
|
||||
delegation = {
|
||||
accountDelegated: target.toString(),
|
||||
amount,
|
||||
conviction
|
||||
};
|
||||
}
|
||||
|
||||
return ({
|
||||
...account,
|
||||
delegation
|
||||
});
|
||||
});
|
||||
|
||||
setSortedAccountsWithDelegation(sortedAccountsWithDelegation);
|
||||
}, [delegations, sortedAccounts]);
|
||||
return ({
|
||||
...account,
|
||||
delegation
|
||||
});
|
||||
})
|
||||
);
|
||||
}, [api, delegations, sortedAccounts]);
|
||||
|
||||
const _setBalance = useCallback(
|
||||
(account: string, balance: BN) =>
|
||||
@ -124,14 +124,14 @@ function Overview ({ className = '', onStatusChange }: Props): React.ReactElemen
|
||||
const header = useMemo(() => [
|
||||
[t('accounts'), 'start', 3],
|
||||
[t('parent'), 'address'],
|
||||
[t('delegation'), 'address ui--media-1500'],
|
||||
api.query.democracy?.votingOf && [t('delegation'), 'address ui--media-1500'],
|
||||
[t('type')],
|
||||
[t('tags'), 'start'],
|
||||
[t('transactions'), 'ui--media-1500'],
|
||||
[t('balances')],
|
||||
[],
|
||||
[undefined, 'mini ui--media-1400']
|
||||
], [t]);
|
||||
], [api, t]);
|
||||
|
||||
const footer = useMemo(() => (
|
||||
<tr>
|
||||
|
||||
@ -5,10 +5,12 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
type HeaderDef = [React.ReactNode?, string?, number?, (() => void)?];
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
filter?: React.ReactNode;
|
||||
header: [React.ReactNode?, string?, number?, (() => void)?][];
|
||||
header: (null | undefined | HeaderDef)[];
|
||||
isEmpty: boolean;
|
||||
}
|
||||
|
||||
@ -21,7 +23,7 @@ function Head ({ className = '', filter, header, isEmpty }: Props): React.ReactE
|
||||
</tr>
|
||||
)}
|
||||
<tr>
|
||||
{header.map(([label, className = 'default', colSpan = 1, onClick], index) =>
|
||||
{header.filter((h): h is HeaderDef => !!h).map(([label, className = 'default', colSpan = 1, onClick], index) =>
|
||||
<th
|
||||
className={className}
|
||||
colSpan={colSpan}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user