Skip to content

Commit

Permalink
fix foreign assets
Browse files Browse the repository at this point in the history
  • Loading branch information
onnovisser committed Sep 12, 2023
1 parent 2e038db commit e63f625
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2951,10 +2951,20 @@ export function findBalance<T extends Pick<AccountCurrencyBalance, 'currency'>>(
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
Expand Down

0 comments on commit e63f625

Please sign in to comment.