From d8d1db5ba27e79a9c21ac1ddfb0f0795c3f3745d Mon Sep 17 00:00:00 2001 From: Thibaut Sardan <33178835+Tbaut@users.noreply.github.com> Date: Thu, 16 Jul 2020 12:25:30 +0200 Subject: [PATCH] Move delegation column to badge (#3202) * move delegation column to badge * lint * Update packages/page-accounts/src/Accounts/Account.tsx * add previous rather than _ * fix x0.1 bug reseting to x1 * ? on a new line --- .../page-accounts/src/Accounts/Account.tsx | 58 ++++++++----------- packages/page-accounts/src/Accounts/index.tsx | 6 +- .../src/Accounts/modals/Delegate.tsx | 49 ++++++++++++---- 3 files changed, 64 insertions(+), 49 deletions(-) diff --git a/packages/page-accounts/src/Accounts/Account.tsx b/packages/page-accounts/src/Accounts/Account.tsx index a89dd4aba9..70001192e2 100644 --- a/packages/page-accounts/src/Accounts/Account.tsx +++ b/packages/page-accounts/src/Accounts/Account.tsx @@ -16,7 +16,6 @@ import { ApiPromise } from '@polkadot/api'; import { getLedger } from '@polkadot/react-api'; import { AddressInfo, AddressMini, AddressSmall, Badge, Button, ChainLock, CryptoType, Forget, Icon, IdentityIcon, LinkExternal, Menu, Popup, StatusContext, Tags } from '@polkadot/react-components'; import { useAccountInfo, useApi, useCall, useToggle } from '@polkadot/react-hooks'; -import { FormatBalance } from '@polkadot/react-query'; import { Option } from '@polkadot/types'; import keyring from '@polkadot/ui-keyring'; import { BN_ZERO, formatBalance, formatNumber } from '@polkadot/util'; @@ -258,6 +257,14 @@ function Account ({ account: { address, meta }, className = '', delegation, filt info='0' /> )} + {delegation?.accountDelegated && ( + ('This account has a governance delegation')} + icon='calendar-check' + onClick={toggleDelegate} + /> + )} @@ -268,6 +275,16 @@ function Account ({ account: { address, meta }, className = '', delegation, filt onClose={toggleBackup} /> )} + {isDelegateOpen && ( + + )} {isDeriveOpen && ( )} + {isUndelegateOpen && ( + + )} {meta.parentAddress && ( )} - {api.api.query.democracy?.votingOf && ( - - {isDelegateOpen && ( - - )} - {isUndelegateOpen && ( - - )} - {delegation && ( - - -
{delegation.conviction.toString()}
- - } - value={delegation.accountDelegated} - /> - )} - - )} diff --git a/packages/page-accounts/src/Accounts/index.tsx b/packages/page-accounts/src/Accounts/index.tsx index 342615c7dc..0f485418fb 100644 --- a/packages/page-accounts/src/Accounts/index.tsx +++ b/packages/page-accounts/src/Accounts/index.tsx @@ -124,20 +124,18 @@ function Overview ({ className = '', onStatusChange }: Props): React.ReactElemen const header = useMemo(() => [ [t('accounts'), 'start', 3], [t('parent'), 'address ui--media-1200'], - 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'] - ], [api, t]); + ], [t]); const footer = useMemo(() => ( - {api.query.democracy?.votingOf && } @@ -146,7 +144,7 @@ function Overview ({ className = '', onStatusChange }: Props): React.ReactElemen - ), [api, balanceTotal]); + ), [balanceTotal]); const filter = useMemo(() => (
diff --git a/packages/page-accounts/src/Accounts/modals/Delegate.tsx b/packages/page-accounts/src/Accounts/modals/Delegate.tsx index 5cb3d8f2df..c4aea832aa 100644 --- a/packages/page-accounts/src/Accounts/modals/Delegate.tsx +++ b/packages/page-accounts/src/Accounts/modals/Delegate.tsx @@ -15,26 +15,37 @@ import { useTranslation } from '../../translate'; import ValidateAmount from './InputValidateAmount'; interface Props { - amount?: BN; - conviction?: Conviction; - delegatedAccount?: string; - delegatingAccount?: string; onClose: () => void; + previousAmount?: BN; + previousConviction?: Conviction; + previousDelegatedAccount?: string; + previousDelegatingAccount?: string; } -function Delegate ({ amount: _amount, conviction: _conviction, delegatedAccount: _delegatedAccount, delegatingAccount: _delegatingAccount, onClose }: Props): React.ReactElement { +function Delegate ({ onClose, previousAmount, previousConviction, previousDelegatedAccount, previousDelegatingAccount }: Props): React.ReactElement { const { t } = useTranslation(); const [amountError, setAmountError] = useState(null); const [maxBalance] = useState(); - const [amount, setAmount] = useState(_amount); - const [delegatingAccount, setDelegatingAccount] = useState(_delegatingAccount || null); - const [delegatedAccount, setDelegatedAccount] = useState(_delegatedAccount || null); - const [conviction, setConviction] = useState(_conviction?.toNumber() || 1); + const [amount, setAmount] = useState(previousAmount); + const [delegatingAccount, setDelegatingAccount] = useState(previousDelegatingAccount || null); + const [delegatedAccount, setDelegatedAccount] = useState(previousDelegatedAccount || null); + const defaultConviction = previousConviction === undefined + ? 1 + : previousConviction.toNumber(); + const [conviction, setConviction] = useState(defaultConviction); + + const isDirty = amount?.toString() !== previousAmount?.toString() || + delegatedAccount !== previousDelegatedAccount || + delegatingAccount !== previousDelegatingAccount || + conviction !== previousConviction?.toNumber(); return ( ('Delegate democracy vote')} + header={previousDelegatedAccount + ? t('democracy vote delegation') + : t('delegate democracy vote') + } size='large' > @@ -92,12 +103,26 @@ function Delegate ({ amount: _amount, conviction: _conviction, delegatedAccount: + {previousDelegatedAccount && ( + ('Undelegate')} + onStart={onClose} + params={[]} + tx='democracy.undelegate' + /> + )} ('Delegate')} + label={previousDelegatedAccount + ? t('Save delegation') + : t('Delegate') + } onStart={onClose} params={[delegatedAccount, conviction, amount]} tx='democracy.delegate'