Use balances.all when possible and show existential deposit (#1258)
* use balances.all when possible and show existential deposit * indentation * lint
This commit is contained in:
parent
141e93cef6
commit
1b1046cf85
@ -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,
|
||||
|
||||
@ -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<Props, State> {
|
||||
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<Props, State> {
|
||||
<>
|
||||
{
|
||||
isNoEffect
|
||||
? <div><Icon name='warning sign' />{t('The final recipient balance is less than the existential amount and will not be reflected')}</div>
|
||||
? <div>
|
||||
<Icon name='warning sign' />
|
||||
{t('The final recipient balance is less or equal to {{existentialDeposit}} (the existential amount) and will not be reflected',
|
||||
{
|
||||
replace: {
|
||||
existentialDeposit: formatBalance(fees.existentialDeposit)
|
||||
}
|
||||
}
|
||||
)}
|
||||
</div>
|
||||
: undefined
|
||||
}
|
||||
{
|
||||
@ -93,6 +102,6 @@ export default withMulti(
|
||||
Transfer,
|
||||
translate,
|
||||
withCalls<Props>(
|
||||
['derive.balances.votingBalance', { paramName: 'recipientId' }]
|
||||
['derive.balances.all', { paramName: 'recipientId' }]
|
||||
)
|
||||
);
|
||||
|
||||
@ -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<Props, State> {
|
||||
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<Props, State> {
|
||||
.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<Props, State> {
|
||||
}
|
||||
|
||||
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<Props, State> {
|
||||
}
|
||||
{
|
||||
isRemovable && hasAvailable
|
||||
? <div><Icon name='ban' />{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.')}</div>
|
||||
? <div>
|
||||
<Icon name='ban' />
|
||||
{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)
|
||||
}
|
||||
}
|
||||
)}
|
||||
</div>
|
||||
: undefined
|
||||
}
|
||||
{this.renderTransfer()}
|
||||
@ -231,7 +240,7 @@ export class FeeDisplay extends React.PureComponent<Props, State> {
|
||||
export default translate(
|
||||
withCalls<Props>(
|
||||
'derive.balances.fees',
|
||||
['derive.balances.votingBalance', { paramName: 'accountId' }],
|
||||
['derive.balances.all', { paramName: 'accountId' }],
|
||||
['query.system.accountNonce', { paramName: 'accountId' }]
|
||||
)(FeeDisplay)
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user