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:
Tarik Gul
2024-08-19 00:51:19 +03:00
committed by GitHub
parent 1921d75d01
commit e2b4e0d3e6
3 changed files with 89 additions and 18 deletions
+8
View File
@@ -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
});
}