Rework api.derive.balance.{account, all} to work with the new frame account data (#5955)
* Rework api.derive.balance.account to work with the new frame account data * Ensure api.derive.balances.all correctly returns transferable * Remove null from transferable * set back to null
This commit is contained in:
@@ -54,11 +54,19 @@ function calcLocked (api: DeriveApi, bestNumber: BlockNumber, locks: (PalletBala
|
||||
|
||||
function calcShared (api: DeriveApi, bestNumber: BlockNumber, data: DeriveBalancesAccountData, locks: (PalletBalancesBalanceLock | BalanceLockTo212)[]): DeriveBalancesAllAccountData {
|
||||
const { allLocked, lockedBalance, lockedBreakdown, vestingLocked } = calcLocked(api, bestNumber, locks);
|
||||
let transferable = null;
|
||||
|
||||
if (data.frameSystemAccountInfo?.frozen) {
|
||||
const frozenReserveDiff = data.frameSystemAccountInfo.frozen.sub(data.reservedBalance);
|
||||
|
||||
transferable = api.registry.createType('Balance', allLocked ? 0 : data?.freeBalance.sub(bnMax(frozenReserveDiff, api.consts.balances.existentialDeposit)));
|
||||
}
|
||||
|
||||
return objectSpread({}, data, {
|
||||
availableBalance: api.registry.createType('Balance', allLocked ? 0 : bnMax(new BN(0), data?.freeBalance ? data.freeBalance.sub(lockedBalance) : new BN(0))),
|
||||
lockedBalance,
|
||||
lockedBreakdown,
|
||||
transferable,
|
||||
vestingLocked
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user