From ff7ba513755f255d833194cbcb271d42bc4f86fa Mon Sep 17 00:00:00 2001 From: Greg Hill Date: Mon, 10 Jan 2022 17:08:53 +0000 Subject: [PATCH] add available balance to interbtc derive (#6810) Signed-off-by: Gregory Hill --- packages/apps-config/src/api/spec/interbtc.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/apps-config/src/api/spec/interbtc.ts b/packages/apps-config/src/api/spec/interbtc.ts index 126b5ca678..c07cf7836e 100644 --- a/packages/apps-config/src/api/spec/interbtc.ts +++ b/packages/apps-config/src/api/spec/interbtc.ts @@ -13,6 +13,7 @@ import { combineLatest, map } from 'rxjs'; import { DeriveBalancesAll } from '@polkadot/api-derive/types'; import { memo } from '@polkadot/api-derive/util'; import { TypeRegistry, U128 } from '@polkadot/types'; +import { Balance } from '@polkadot/types/interfaces'; import { BN, formatBalance } from '@polkadot/util'; function balanceOf (number: number | string): U128 { @@ -32,6 +33,12 @@ function defaultAccountBalance (): DeriveBalancesAll { } as any; } +interface OrmlAccountData { + free: Balance, + reserved: Balance, + frozen: Balance, +} + export function getBalance ( instanceId: string, api: ApiInterfaceRx @@ -41,10 +48,12 @@ export function getBalance ( return memo( instanceId, (account: string): Observable => - combineLatest([api.query.tokens.accounts(account, { Token: nativeToken })]).pipe( - map(([data]: [any]): DeriveBalancesAll => { + combineLatest<[any]>([api.query.tokens.accounts(account, { Token: nativeToken })]).pipe( + map(([data]: [OrmlAccountData]): DeriveBalancesAll => { return { ...defaultAccountBalance(), + accountId: api.registry.createType('AccountId', account), + availableBalance: api.registry.createType('Balance', data.free.sub(data.frozen)), freeBalance: data.free, lockedBalance: data.frozen, reservedBalance: data.reserved