From 35f57b9c00f89c746a9c61dbe426c3ba01673238 Mon Sep 17 00:00:00 2001 From: Onno Visser Date: Tue, 12 Sep 2023 18:04:50 +0200 Subject: [PATCH] Centrifuge App: Fix foreign assets (#1577) --- 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