Skip to content

Commit

Permalink
fix: runtime typing
Browse files Browse the repository at this point in the history
  • Loading branch information
filo87 committed Jul 2, 2024
1 parent 2aee5df commit 7441ce7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/chaintypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const loansRuntimeApiMethodsV3: DefinitionsCallEntry['methods'] = {
type: 'u64',
},
],
type: 'Vec<CashflowPayment>',
type: 'Result<Vec<CashflowPayment<Balance>>, SpRuntimeDispatchError>',
},
}

Expand Down
9 changes: 7 additions & 2 deletions src/helpers/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//find out types: const a = createType(api.registry, '[u8;32]', 18)
import { AugmentedCall, AugmentedRpc, PromiseRpcResult } from '@polkadot/api/types'
import { Enum, Null, Struct, u128, u32, u64, U8aFixed, Option, Vec, Bytes } from '@polkadot/types'
import { Enum, Null, Struct, u128, u32, u64, U8aFixed, Option, Vec, Bytes, Result } from '@polkadot/types'
import { AccountId32, Perquintill, Balance } from '@polkadot/types/interfaces'
import { ITuple, Observable } from '@polkadot/types/types'

Expand Down Expand Up @@ -435,6 +435,8 @@ export interface CashflowPayment extends Struct {
interest: Balance
}

export interface DispatchError extends Enum {}

export type LoanAsset = ITuple<[collectionId: u64, itemId: u128]>
export type LoanCreatedEvent = ITuple<[poolId: u64, loanId: u64, loanInfo: LoanInfoCreated]>
export type LoanClosedEvent = ITuple<[poolId: u64, loanId: u64, collateralInfo: LoanAsset]>
Expand Down Expand Up @@ -498,7 +500,10 @@ export type ExtendedRpc = typeof api.rpc & {
export type ExtendedCall = typeof api.call & {
loansApi: {
portfolio: AugmentedCall<'promise', (poolId: string) => Observable<Vec<ITuple<[u64, LoanInfoActivePortfolio]>>>>
expectedCashflows: AugmentedCall<'promise', (poolId: string, loanId: string) => Observable<Vec<CashflowPayment>>>
expectedCashflows: AugmentedCall<
'promise',
(poolId: string, loanId: string) => Observable<Result<Vec<CashflowPayment>, DispatchError>>
>
}
poolsApi: {
nav: AugmentedCall<'promise', (poolId: string) => Observable<Option<PoolNav>>>
Expand Down
3 changes: 2 additions & 1 deletion src/mappings/services/assetCashflowService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ export class AssetCashflowService extends AssetCashflow {
logger.info(`Calling runtime API loansApi.expectedCashflows(${poolId}, ${assetId})`)
const response = await apiCall.loansApi.expectedCashflows(poolId, assetId)
logger.info(JSON.stringify(response))
if(!response.isOk) return
await this.clearAssetCashflows(_assetId)
const saves = response.map((cf) => {
const saves = response.asOk.map((cf) => {
const { when, principal, interest } = cf
const timestamp = new Date(when.toNumber() * 1000)
const cashflow = this.init(_assetId, timestamp, principal.toBigInt(), interest.toBigInt())
Expand Down

0 comments on commit 7441ce7

Please sign in to comment.