Check freeBalance with bondExtra, not availableBalance (#1825)
This commit is contained in:
parent
56df244640
commit
f415732fe7
@ -54,7 +54,7 @@ class BondExtra extends TxComponent<Props, State> {
|
||||
|
||||
public render (): React.ReactNode {
|
||||
const { balances_all = ZERO_BALANCE, isOpen, onClose, stashId, t } = this.props;
|
||||
const { extrinsic, maxAdditional, maxBalance = balances_all.availableBalance } = this.state;
|
||||
const { extrinsic, maxAdditional, maxBalance = balances_all.freeBalance } = this.state;
|
||||
const canSubmit = !!maxAdditional && maxAdditional.gtn(0) && maxAdditional.lte(maxBalance);
|
||||
|
||||
if (!isOpen) {
|
||||
@ -145,11 +145,11 @@ class BondExtra extends TxComponent<Props, State> {
|
||||
}
|
||||
|
||||
private setMaxBalance = (): void => {
|
||||
const { api, system_accountNonce = ZERO, balances_fees = ZERO_FEES, balances_all = ZERO_BALANCE } = this.props;
|
||||
const { api, balances_fees = ZERO_FEES, balances_all = ZERO_BALANCE } = this.props;
|
||||
const { maxAdditional } = this.state;
|
||||
|
||||
const { transactionBaseFee, transactionByteFee } = balances_fees;
|
||||
const { availableBalance } = balances_all;
|
||||
const { accountNonce, freeBalance } = balances_all;
|
||||
|
||||
let prevMax = new BN(0);
|
||||
let maxBalance = new BN(1);
|
||||
@ -161,10 +161,10 @@ class BondExtra extends TxComponent<Props, State> {
|
||||
? api.tx.staking.bondExtra(maxAdditional)
|
||||
: null;
|
||||
|
||||
const txLength = calcTxLength(extrinsic, system_accountNonce);
|
||||
const txLength = calcTxLength(extrinsic, accountNonce);
|
||||
const fees = transactionBaseFee.add(transactionByteFee.mul(txLength));
|
||||
|
||||
maxBalance = bnMax(availableBalance.sub(fees), ZERO);
|
||||
maxBalance = bnMax(freeBalance.sub(fees), ZERO);
|
||||
}
|
||||
|
||||
this.nextState({
|
||||
@ -185,7 +185,6 @@ export default withMulti(
|
||||
withApi,
|
||||
withCalls<Props>(
|
||||
'derive.balances.fees',
|
||||
['derive.balances.all', { paramName: 'stashId' }],
|
||||
['query.system.accountNonce', { paramName: 'stashId' }]
|
||||
['derive.balances.all', { paramName: 'stashId' }]
|
||||
)
|
||||
);
|
||||
|
||||
@ -375,7 +375,7 @@ class Account extends React.PureComponent<Props, State> {
|
||||
|
||||
// only show a "Bond Additional" button if this stash account actually doesn't bond everything already
|
||||
// staking_ledger.total gives the total amount that can be slashed (any active amount + what is being unlocked)
|
||||
const canBondExtra = balances_all && balances_all.availableBalance.gtn(0);
|
||||
const canBondExtra = balances_all && balances_all.freeBalance.gtn(0);
|
||||
|
||||
return (
|
||||
<Menu
|
||||
|
||||
@ -6,8 +6,6 @@ import { DerivedFees, DerivedBalances, DerivedHeartbeats } from '@polkadot/api-d
|
||||
import { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
|
||||
import { EraPoints } from '@polkadot/types/interfaces';
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
export type Nominators = Record<string, string[]>;
|
||||
|
||||
export interface ComponentProps {
|
||||
@ -23,7 +21,6 @@ export interface ComponentProps {
|
||||
export interface CalculateBalanceProps {
|
||||
balances_fees?: DerivedFees;
|
||||
balances_all?: DerivedBalances;
|
||||
system_accountNonce?: BN;
|
||||
}
|
||||
|
||||
export type AccountFilter = 'all' | 'controller' | 'session' | 'stash' | 'unbonded';
|
||||
|
||||
@ -33,7 +33,6 @@ interface Props extends BareProps, ApiProps {
|
||||
onEnter?: () => void;
|
||||
placeholder?: string;
|
||||
stashId: string;
|
||||
system_accountNonce?: BN;
|
||||
value?: BN | string;
|
||||
withEllipsis?: boolean;
|
||||
withLabel?: boolean;
|
||||
@ -104,7 +103,7 @@ class InputBalanceBonded extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
private setMaxBalance = (): void => {
|
||||
const { api, balances_fees = ZERO_FEES, balances_all = ZERO_BALANCE, controllerId, destination, extrinsicProp, system_accountNonce = ZERO } = this.props;
|
||||
const { api, balances_fees = ZERO_FEES, balances_all = ZERO_BALANCE, controllerId, destination, extrinsicProp } = this.props;
|
||||
const { transactionBaseFee, transactionByteFee } = balances_fees;
|
||||
const { freeBalance } = balances_all;
|
||||
let prevMax = new BN(0);
|
||||
@ -124,7 +123,7 @@ class InputBalanceBonded extends React.PureComponent<Props, State> {
|
||||
extrinsic = api.tx.staking.bonExtra(prevMax);
|
||||
}
|
||||
|
||||
const txLength = calcTxLength(extrinsic, system_accountNonce);
|
||||
const txLength = calcTxLength(extrinsic, balances_all.accountNonce);
|
||||
const fees = transactionBaseFee.add(transactionByteFee.mul(txLength));
|
||||
|
||||
maxBalance = bnMax(freeBalance.sub(fees), ZERO);
|
||||
@ -157,7 +156,6 @@ export default withMulti(
|
||||
withApi,
|
||||
withCalls<Props>(
|
||||
'derive.balances.fees',
|
||||
['derive.balances.all', { paramName: 'stashId' }],
|
||||
['query.system.accountNonce', { paramName: 'stashId' }]
|
||||
['derive.balances.all', { paramName: 'stashId' }]
|
||||
)
|
||||
);
|
||||
|
||||
@ -11,8 +11,8 @@ const ZERO_BALANCE: DerivedBalances = {
|
||||
accountId: createType('AccountId'),
|
||||
accountNonce: createType('Index'),
|
||||
availableBalance: createType('Balance'),
|
||||
lockedBalance: createType('Balance'),
|
||||
freeBalance: createType('Balance'),
|
||||
lockedBalance: createType('Balance'),
|
||||
reservedBalance: createType('Balance'),
|
||||
vestedBalance: createType('Balance'),
|
||||
votingBalance: createType('Balance')
|
||||
|
||||
@ -42,7 +42,6 @@ interface Props extends I18nProps {
|
||||
extrinsic?: IExtrinsic | null;
|
||||
isSendable: boolean;
|
||||
onChange?: (hasAvailable: boolean) => void;
|
||||
system_accountNonce?: BN;
|
||||
tip?: BN;
|
||||
}
|
||||
|
||||
@ -64,7 +63,7 @@ export const calcTxLength = (extrinsic?: IExtrinsic | null, nonce?: BN, tip?: BN
|
||||
);
|
||||
};
|
||||
|
||||
export function FeeDisplay ({ accountId, balances_all = ZERO_BALANCE, balances_fees = ZERO_FEES_BALANCES, className, contract_fees = ZERO_FEES_CONTRACT, extrinsic, isSendable, onChange, system_accountNonce = ZERO, t, tip }: Props): React.ReactElement<Props> | null {
|
||||
export function FeeDisplay ({ accountId, balances_all = ZERO_BALANCE, balances_fees = ZERO_FEES_BALANCES, className, contract_fees = ZERO_FEES_CONTRACT, extrinsic, isSendable, onChange, t, tip }: Props): React.ReactElement<Props> | null {
|
||||
const { api } = useContext(ApiContext);
|
||||
const [state, setState] = useState<State>({
|
||||
allFees: ZERO,
|
||||
@ -89,7 +88,7 @@ export function FeeDisplay ({ accountId, balances_all = ZERO_BALANCE, balances_f
|
||||
const fn = api.findCall(extrinsic.callIndex);
|
||||
const extMethod = fn.method;
|
||||
const extSection = fn.section;
|
||||
const txLength = calcTxLength(extrinsic, system_accountNonce, tip);
|
||||
const txLength = calcTxLength(extrinsic, balances_all.accountNonce, tip);
|
||||
|
||||
const isSameExtrinsic = state.extMethod === extMethod && state.extSection === extSection;
|
||||
const extraAmount = isSameExtrinsic
|
||||
@ -125,7 +124,7 @@ export function FeeDisplay ({ accountId, balances_all = ZERO_BALANCE, balances_f
|
||||
isReserved,
|
||||
overLimit
|
||||
});
|
||||
}, [accountId, balances_all, balances_fees, extra, extrinsic, system_accountNonce, tip]);
|
||||
}, [accountId, balances_all, balances_fees, extra, extrinsic, balances_all.accountNonce, tip]);
|
||||
|
||||
if (!accountId) {
|
||||
return null;
|
||||
@ -249,7 +248,6 @@ export default translate(
|
||||
withCalls<Props>(
|
||||
'derive.balances.fees',
|
||||
['derive.balances.all', { paramName: 'accountId' }],
|
||||
'derive.contracts.fees',
|
||||
['query.system.accountNonce', { paramName: 'accountId' }]
|
||||
'derive.contracts.fees'
|
||||
)(FeeDisplay)
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user