Skip to content

Commit

Permalink
CU-86a5x0q43 - BS Swap - Bug - availableTokensToUse has tokens that d…
Browse files Browse the repository at this point in the history
…o not have decimals
  • Loading branch information
dustr94 committed Dec 14, 2024
1 parent cdc79f4 commit fa36e9a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
25 changes: 16 additions & 9 deletions packages/bs-swap/src/apis/SimpleSwapApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
SimpleSwapApiGetRangeResponse,
SimpleSwapServiceInitParams,
} from '../types/simpleSwap'
import { Token } from '@cityofzion/blockchain-service'

export class SimpleSwapApi<BSName extends string = string> {
#axios: AxiosInstance
Expand Down Expand Up @@ -42,17 +43,23 @@ export class SimpleSwapApi<BSName extends string = string> {
if (chainsByServiceNameEntry) {
blockchain = chainsByServiceNameEntry[0]

if (!hash) {
const token = options.blockchainServicesByName[blockchain].tokens.find(
token => currency.ticker?.toLowerCase().startsWith(token.symbol.toLowerCase())
let token: Token | undefined

if (hash) {
token = options.blockchainServicesByName[blockchain].tokens.find(item => hash!.replace('0x', '') === item.hash)
}

if (!token) {
token = options.blockchainServicesByName[blockchain].tokens.find(
item => currency.ticker?.toLowerCase().startsWith(item.symbol.toLowerCase())
)
}

if (token) {
hash = token.hash
decimals = token.decimals
name = token.name
symbol = token.symbol
}
if (token) {
hash = token.hash
decimals = token.decimals
name = token.name
symbol = token.symbol
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/bs-swap/src/services/SimpleSwapService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ export class SimpleSwapService<BSName extends string = string> implements SwapSe
blockchainServicesByName: this.#blockchainServicesByName,
chainsByServiceName: this.#chainsByServiceName,
})
this.#availableTokensToUse = { loading: false, value: tokens }

const filteredTokens = tokens.filter(token => token.blockchain && token.decimals && token.hash)

this.#availableTokensToUse = { loading: false, value: filteredTokens }
}

async setTokenToUse(token: SwapServiceToken<BSName> | null): Promise<void> {
Expand Down

0 comments on commit fa36e9a

Please sign in to comment.