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 16, 2024
1 parent 9d29c3e commit 2ec7844
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/bs-swap/src/services/SimpleSwapService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Account,
BlockchainService,
formatString,
isCalculableFee,
SwapService,
SwapServiceEvents,
Expand Down Expand Up @@ -167,11 +168,11 @@ export class SimpleSwapService<BSName extends string = string> implements SwapSe
const apiRange = await this.#api.getRange(this.#tokenToUse.value, this.#tokenToReceive.value!)
range = {
min: this.#tokenToUse.value.decimals
? Number(apiRange.min).toFixed(this.#tokenToUse.value.decimals)
? formatString(apiRange.min, this.#tokenToUse.value.decimals)
: apiRange.min,
max:
this.#tokenToUse.value.decimals && apiRange.max
? Number(apiRange.max).toFixed(this.#tokenToUse.value.decimals)
? formatString(apiRange.max, this.#tokenToUse.value.decimals)
: apiRange.max,
}
}
Expand All @@ -181,7 +182,7 @@ export class SimpleSwapService<BSName extends string = string> implements SwapSe
if (shouldRecalculateAmountToUse) {
this.#amountToUse = {
value: this.#tokenToUse.value.decimals
? Number(range.min).toFixed(this.#tokenToUse.value.decimals)
? formatString(range.min, this.#tokenToUse.value.decimals)
: range.min,
}
}
Expand Down Expand Up @@ -243,7 +244,8 @@ export class SimpleSwapService<BSName extends string = string> implements SwapSe

async setAmountToUse(amount: string | null): Promise<void> {
this.#amountToUse = {
value: this.#tokenToUse.value?.decimals ? Number(amount).toFixed(this.#tokenToUse.value.decimals) : amount,
value:
this.#tokenToUse.value?.decimals && amount ? formatString(amount, this.#tokenToUse.value.decimals) : amount,
}

debounce(this.#recalculateValues.bind(this), 500)(['amountToReceive'])
Expand Down

0 comments on commit 2ec7844

Please sign in to comment.