import { Observable , combineLatest } from 'rxjs' ; import { map } from 'rxjs/operators' ; import { ApiInterfaceRx } from '@polkadot/api/types' ; import { CurrencyId , AccountId , Position } from '@acala-network/types/interfaces' ; import { memo } from '@polkadot/api-derive/util' ; import { DerivedUserLoan } from '../types/loan' ; import { getAllCollateralCurrencyIds } from '../utils' ; name description param { ( AccountId | string ) } account param { ( CurrencyId | string ) } currency export function loan ( instanceId , api ) { return memo ( instanceId , ( account , currency ) => api . query . loans . positions < Position > ( currency , account ) . pipe ( map ( ( result ) => { const { debit , collateral } = result ; return { account , currency , debit , collateral } ; } ) ) ) ; } name description param { ( AccountId | string ) } account export function allLoans ( instanceId , api ) { return memo ( instanceId , ( account ) => { const collateralCurrencyIds = getAllCollateralCurrencyIds ( api ) ; const loanQuery = loan ( instanceId , api ) ; return combineLatest ( collateralCurrencyIds . map ( ( currency ) => loanQuery ( account , currency ) ) ) ; } ) ; }