From e63f6252cb8fffe8014bb345a6c5e2b9fe6d5a04 Mon Sep 17 00:00:00 2001 From: Onno Visser <23527729+onnovisser@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:57:20 +0200 Subject: [PATCH] fix foreign assets --- centrifuge-js/src/modules/pools.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/centrifuge-js/src/modules/pools.ts b/centrifuge-js/src/modules/pools.ts index 1c30f4e230..bb8a96f689 100644 --- a/centrifuge-js/src/modules/pools.ts +++ b/centrifuge-js/src/modules/pools.ts @@ -43,7 +43,7 @@ type CurrencyRole = 'PermissionedAssetManager' | 'PermissionedAssetIssuer' export type PoolRoleInput = AdminRole | { TrancheInvestor: [trancheId: string, permissionedTill: number] } -export type CurrencyKey = string | { ForeignAsset: number } | { Tranche: [string, string] } +export type CurrencyKey = string | { ForeignAsset: string } | { Tranche: [string, string] } export type CurrencyMetadata = { key: CurrencyKey @@ -2951,10 +2951,20 @@ export function findBalance>( return balances.find((balance) => looksLike(balance.currency.key, key)) } -function parseCurrencyKey(key: CurrencyKey): CurrencyKey { - if (typeof key !== 'string' && 'Tranche' in key) { - return { - Tranche: [key.Tranche[0].replace(/\D/g, ''), key.Tranche[1]], +export function parseCurrencyKey(key: CurrencyKey | { foreignAsset: number | string }): CurrencyKey { + if (typeof key === 'object') { + if ('Tranche' in key) { + return { + Tranche: [key.Tranche[0].replace(/\D/g, ''), key.Tranche[1]], + } + } else if ('ForeignAsset' in key) { + return { + ForeignAsset: String(key.ForeignAsset).replace(/\D/g, ''), + } + } else if ('foreignAsset' in key) { + return { + ForeignAsset: String(key.foreignAsset).replace(/\D/g, ''), + } } } return key