add available balance to interbtc derive (#6810)
Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
This commit is contained in:
parent
c074af3037
commit
ff7ba51375
@ -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<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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user