Skip to content

Commit

Permalink
add available balance to interbtc derive (polkadot-js#6810)
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Hill <[email protected]>
  • Loading branch information
gregdhill authored Jan 10, 2022
1 parent c074af3 commit ff7ba51
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/apps-config/src/api/spec/interbtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -32,6 +33,12 @@ function defaultAccountBalance (): DeriveBalancesAll {
} as any;
}

interface OrmlAccountData {
free: Balance,
reserved: Balance,
frozen: Balance,
}

export function getBalance (
instanceId: string,
api: ApiInterfaceRx
Expand All @@ -41,10 +48,12 @@ export function getBalance (
return memo(
instanceId,
(account: string): Observable<DeriveBalancesAll> =>
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
Expand Down

0 comments on commit ff7ba51

Please sign in to comment.