Take unlocking and redeemable into account to bond more funds (#3348)

* take unlocking and redeemable into account

* spacing
This commit is contained in:
Thibaut Sardan 2020-08-06 13:35:39 +02:00 committed by GitHub
parent 687d5fcbc0
commit a6315aa915
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,7 +37,9 @@ function BondExtra ({ controllerId, onClose, stakingInfo, stashId }: Props): Rea
useEffect((): void => {
if (stakingInfo && stakingInfo.stakingLedger && stashBalance) {
const available = stashBalance.freeBalance.sub(stakingInfo.stakingLedger.active.unwrap());
const sumUnlocking = stakingInfo.unlocking?.reduce((acc, { value }) => acc.add(value), BN_ZERO) || BN_ZERO;
const redeemable = stakingInfo.redeemable || BN_ZERO;
const available = stashBalance.freeBalance.sub(stakingInfo.stakingLedger.active.unwrap()).sub(sumUnlocking).sub(redeemable);
setStartBalance(
available.gt(api.consts.balances.existentialDeposit)