From 1b1046cf856a069a105441407cb2aae45e519b29 Mon Sep 17 00:00:00 2001 From: Thibaut Sardan <33178835+Tbaut@users.noreply.github.com> Date: Sat, 1 Jun 2019 08:12:03 +0200 Subject: [PATCH] Use balances.all when possible and show existential deposit (#1258) * use balances.all when possible and show existential deposit * indentation * lint --- packages/app-accounts/src/modals/Transfer.tsx | 3 +-- packages/ui-signer/src/Checks/Transfer.tsx | 23 +++++++++++------ packages/ui-signer/src/Checks/index.tsx | 25 +++++++++++++------ 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/packages/app-accounts/src/modals/Transfer.tsx b/packages/app-accounts/src/modals/Transfer.tsx index 9096cfc81f..3c9fe6c565 100644 --- a/packages/app-accounts/src/modals/Transfer.tsx +++ b/packages/app-accounts/src/modals/Transfer.tsx @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { ApiProps } from '@polkadot/ui-api/types'; -import { DerivedFees, DerivedBalances } from '@polkadot/api-derive/types'; +import { DerivedFees } from '@polkadot/api-derive/types'; import { I18nProps } from '@polkadot/ui-app/types'; import { SubmittableExtrinsic } from '@polkadot/api/promise/types'; @@ -21,7 +21,6 @@ import translate from '../translate'; type Props = ApiProps & I18nProps & { balances_fees?: DerivedFees, - balances_votingBalance?: DerivedBalances, onClose: () => void, recipientId?: string, senderId?: string, diff --git a/packages/ui-signer/src/Checks/Transfer.tsx b/packages/ui-signer/src/Checks/Transfer.tsx index 6c1a563af1..361e191fcc 100644 --- a/packages/ui-signer/src/Checks/Transfer.tsx +++ b/packages/ui-signer/src/Checks/Transfer.tsx @@ -19,7 +19,7 @@ import { ZERO_BALANCE } from './constants'; type Props = I18nProps & { amount: BN | Compact, fees: DerivedFees, - balances_votingBalance?: DerivedBalances, + balances_all?: DerivedBalances, recipientId: string, onChange: (fees: ExtraFees) => void }; @@ -38,16 +38,16 @@ export class Transfer extends React.PureComponent { isNoEffect: false }; - static getDerivedStateFromProps ({ amount, balances_votingBalance = ZERO_BALANCE, fees, onChange }: Props): State { + static getDerivedStateFromProps ({ amount, balances_all = ZERO_BALANCE, fees, onChange }: Props): State { let extraFees = new BN(fees.transferFee); - if (balances_votingBalance.votingBalance.isZero()) { + if (balances_all.votingBalance.isZero()) { extraFees = extraFees.add(fees.creationFee); } const extraAmount = amount instanceof Compact ? amount.toBn() : new BN(amount); - const isCreation = balances_votingBalance.votingBalance.isZero() && fees.creationFee.gtn(0); - const isNoEffect = extraAmount.add(balances_votingBalance.votingBalance).lte(fees.existentialDeposit); + const isCreation = balances_all.votingBalance.isZero() && fees.creationFee.gtn(0); + const isNoEffect = extraAmount.add(balances_all.votingBalance).lte(fees.existentialDeposit); const extraWarn = isCreation || isNoEffect; const update = { extraAmount, @@ -72,7 +72,16 @@ export class Transfer extends React.PureComponent { <> { isNoEffect - ?
{t('The final recipient balance is less than the existential amount and will not be reflected')}
+ ?
+ + {t('The final recipient balance is less or equal to {{existentialDeposit}} (the existential amount) and will not be reflected', + { + replace: { + existentialDeposit: formatBalance(fees.existentialDeposit) + } + } + )} +
: undefined } { @@ -93,6 +102,6 @@ export default withMulti( Transfer, translate, withCalls( - ['derive.balances.votingBalance', { paramName: 'recipientId' }] + ['derive.balances.all', { paramName: 'recipientId' }] ) ); diff --git a/packages/ui-signer/src/Checks/index.tsx b/packages/ui-signer/src/Checks/index.tsx index 4ad9273ee1..57909a45f9 100644 --- a/packages/ui-signer/src/Checks/index.tsx +++ b/packages/ui-signer/src/Checks/index.tsx @@ -33,7 +33,7 @@ type State = ExtraFees & { type Props = I18nProps & { balances_fees?: DerivedFees, - balances_votingBalance?: DerivedBalances, + balances_all?: DerivedBalances, accountId?: string | null, extrinsic?: IExtrinsic | null, isSendable: boolean, @@ -66,7 +66,7 @@ export class FeeDisplay extends React.PureComponent { overLimit: false }; - static getDerivedStateFromProps ({ accountId, balances_votingBalance = ZERO_BALANCE, extrinsic, balances_fees = ZERO_FEES, system_accountNonce = new BN(0) }: Props, prevState: State): State | null { + static getDerivedStateFromProps ({ accountId, balances_all = ZERO_BALANCE, extrinsic, balances_fees = ZERO_FEES, system_accountNonce = new BN(0) }: Props, prevState: State): State | null { if (!accountId || !extrinsic) { return null; } @@ -91,9 +91,9 @@ export class FeeDisplay extends React.PureComponent { .add(balances_fees.transactionByteFee.muln(txLength)); const allTotal = extraAmount.add(allFees); - const hasAvailable = balances_votingBalance.freeBalance.gte(allTotal); - const isRemovable = balances_votingBalance.votingBalance.sub(allTotal).lte(balances_fees.existentialDeposit); - const isReserved = balances_votingBalance.freeBalance.isZero() && balances_votingBalance.reservedBalance.gtn(0); + const hasAvailable = balances_all.availableBalance.gtn(0); + const isRemovable = balances_all.votingBalance.sub(allTotal).lte(balances_fees.existentialDeposit); + const isReserved = balances_all.freeBalance.isZero() && balances_all.reservedBalance.gtn(0); const allWarn = extraWarn; const overLimit = txLength >= MAX_SIZE_BYTES; @@ -121,7 +121,7 @@ export class FeeDisplay extends React.PureComponent { } render () { - const { accountId, className, isSendable, t } = this.props; + const { accountId, balances_fees, className, isSendable, t } = this.props; const { allFees, allTotal, allWarn, hasAvailable, isRemovable, isReserved, overLimit } = this.state; if (!accountId) { @@ -159,7 +159,16 @@ export class FeeDisplay extends React.PureComponent { } { isRemovable && hasAvailable - ?
{t('Submitting this transaction will drop the account balance to below the existential amount, which can result in the account being removed from the chain state associated funds burned.')}
+ ?
+ + {t('Submitting this transaction will drop the account balance to below the existential amount ({{existentialDeposit}}), which can result in the account being removed from the chain state and its associated funds burned.', + { + replace: { + existentialDeposit: formatBalance(balances_fees && balances_fees.existentialDeposit) + } + } + )} +
: undefined } {this.renderTransfer()} @@ -231,7 +240,7 @@ export class FeeDisplay extends React.PureComponent { export default translate( withCalls( 'derive.balances.fees', - ['derive.balances.votingBalance', { paramName: 'accountId' }], + ['derive.balances.all', { paramName: 'accountId' }], ['query.system.accountNonce', { paramName: 'accountId' }] )(FeeDisplay) );