From 2f62471db2025fb09e6569c9478e844019e44f62 Mon Sep 17 00:00:00 2001 From: Dust Date: Fri, 13 Dec 2024 22:52:21 -0300 Subject: [PATCH] CU-86a5x0q43 - BS Swap - Bug - availableTokensToUse has tokens that do not have decimals --- .../CU-86a5x0q43_2024-12-14-02-03.json | 10 ++++++++ .../CU-86a5x0q43_2024-12-14-01-53.json | 10 ++++++++ packages/blockchain-service/src/functions.ts | 4 ++++ packages/bs-swap/src/apis/SimpleSwapApi.ts | 23 ++++++++++--------- .../bs-swap/src/services/SimpleSwapService.ts | 5 +++- 5 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 common/changes/@cityofzion/blockchain-service/CU-86a5x0q43_2024-12-14-02-03.json create mode 100644 common/changes/@cityofzion/bs-swap/CU-86a5x0q43_2024-12-14-01-53.json diff --git a/common/changes/@cityofzion/blockchain-service/CU-86a5x0q43_2024-12-14-02-03.json b/common/changes/@cityofzion/blockchain-service/CU-86a5x0q43_2024-12-14-02-03.json new file mode 100644 index 0000000..f6cd6bb --- /dev/null +++ b/common/changes/@cityofzion/blockchain-service/CU-86a5x0q43_2024-12-14-02-03.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/blockchain-service", + "comment": "Add normalizeHash function", + "type": "minor" + } + ], + "packageName": "@cityofzion/blockchain-service" +} \ No newline at end of file diff --git a/common/changes/@cityofzion/bs-swap/CU-86a5x0q43_2024-12-14-01-53.json b/common/changes/@cityofzion/bs-swap/CU-86a5x0q43_2024-12-14-01-53.json new file mode 100644 index 0000000..d7d0aa5 --- /dev/null +++ b/common/changes/@cityofzion/bs-swap/CU-86a5x0q43_2024-12-14-01-53.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/bs-swap", + "comment": "Fix bug where availableTokensToUse has tokens that do not have decimals", + "type": "patch" + } + ], + "packageName": "@cityofzion/bs-swap" +} \ No newline at end of file diff --git a/packages/blockchain-service/src/functions.ts b/packages/blockchain-service/src/functions.ts index 3923dbe..34e2546 100644 --- a/packages/blockchain-service/src/functions.ts +++ b/packages/blockchain-service/src/functions.ts @@ -135,3 +135,7 @@ export async function fetchAccountsForBlockchainServices { #axios: AxiosInstance @@ -42,17 +43,17 @@ export class SimpleSwapApi { if (chainsByServiceNameEntry) { blockchain = chainsByServiceNameEntry[0] - if (!hash) { - const token = options.blockchainServicesByName[blockchain].tokens.find( - token => currency.ticker?.toLowerCase().startsWith(token.symbol.toLowerCase()) - ) - - if (token) { - hash = token.hash - decimals = token.decimals - name = token.name - symbol = token.symbol - } + const token = options.blockchainServicesByName[blockchain].tokens.find( + item => + (hash && normalizeHash(hash) === normalizeHash(item.hash)) || + (currency.ticker && currency.ticker.toLowerCase().startsWith(item.symbol.toLowerCase())) + ) + + if (token) { + hash = token.hash + decimals = token.decimals + name = token.name + symbol = token.symbol } } diff --git a/packages/bs-swap/src/services/SimpleSwapService.ts b/packages/bs-swap/src/services/SimpleSwapService.ts index 5f74533..6e1109b 100644 --- a/packages/bs-swap/src/services/SimpleSwapService.ts +++ b/packages/bs-swap/src/services/SimpleSwapService.ts @@ -198,7 +198,10 @@ export class SimpleSwapService implements SwapSe blockchainServicesByName: this.#blockchainServicesByName, chainsByServiceName: this.#chainsByServiceName, }) - this.#availableTokensToUse = { loading: false, value: tokens } + + const filteredTokens = tokens.filter(token => token.blockchain && token.decimals !== undefined && token.hash) + + this.#availableTokensToUse = { loading: false, value: filteredTokens } } async setTokenToUse(token: SwapServiceToken | null): Promise {