Fix unlocking/redeemable calc with currentEra (#1572)

* Fix unlocking/redeemable calc with currentEra

* typo

* >= 0 for era check

* Reverse >= 0, it is only 0

* Pass isVesting flag via balances.all
This commit is contained in:
Jaco Greeff
2019-11-14 18:27:25 +01:00
committed by GitHub
parent f89867a9ae
commit c44cb1858e
4 changed files with 38 additions and 36 deletions
+10 -4
View File
@@ -31,17 +31,23 @@ function calcBalances ([accountId, bestNumber, [freeBalance, reservedBalance, lo
}
}
// offset = balance locked at genesis, perBlock is the unlock amount
// Calculate the vesting balances,
// - offset = balance locked at genesis,
// - perBlock is the unlock amount
const { offset: vestingTotal, perBlock } = vesting.unwrapOr(createType('VestingSchedule'));
const vestedNow = createType('Balance', perBlock.mul(bestNumber));
const vestedBalance = createType('Balance', vestedNow.gt(vestingTotal) ? new BN(0) : bnMax(new BN(0), freeBalance.sub(vestingTotal).add(vestedNow)));
const availableBalance = createType('Balance', bnMax(new BN(0), (vestedBalance.gtn(0) ? vestedBalance : freeBalance).sub(lockedBalance)));
const vestedBalance = createType('Balance', perBlock.mul(bestNumber));
const isVesting = vestedBalance.lt(vestingTotal);
// see what is availble with the current vested amount taken into account
const freeWithVesting = freeBalance.sub(vestingTotal).add(vestedBalance);
const availableBalance = createType('Balance', bnMax(new BN(0), (isVesting ? freeWithVesting : freeBalance).sub(lockedBalance)));
return {
accountId,
accountNonce,
availableBalance,
freeBalance,
isVesting,
lockedBalance,
lockedBreakdown,
reservedBalance,