Skip to content

Commit

Permalink
Merge pull request #121 from CityOfZion/CU-86a5x0q43-1
Browse files Browse the repository at this point in the history
CU-86a5x0q43 - BS Swap - Bug - availableTokensToUse has tokens that d…
  • Loading branch information
thiagocbalducci authored Dec 14, 2024
2 parents f69a83f + 040d71d commit 02ffcb7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-neo3",
"comment": "Fix error when trying to send a value with more decimal places than the token supports ",
"type": "patch"
}
],
"packageName": "@cityofzion/bs-neo3"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-swap",
"comment": "Fix error when trying to send a value with more decimal places than the token supports",
"type": "patch"
}
],
"packageName": "@cityofzion/bs-swap"
}
5 changes: 4 additions & 1 deletion packages/bs-neo3/src/BSNeo3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ export class BSNeo3<BSName extends string = string>
{
type: 'Integer',
value: intent.tokenDecimals
? u.BigInteger.fromDecimal(intent.amount, intent.tokenDecimals).toString()
? u.BigInteger.fromDecimal(
Number(intent.amount).toFixed(intent.tokenDecimals),
intent.tokenDecimals
).toString()
: intent.amount,
},
{ type: 'Any', value: null },
Expand Down
10 changes: 8 additions & 2 deletions packages/bs-swap/src/services/SimpleSwapService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ export class SimpleSwapService<BSName extends string = string> implements SwapSe
this.#amountToUseMinMax = { value: range }

if (shouldRecalculateAmountToUse) {
this.#amountToUse = { value: range.min }
this.#amountToUse = {
value: this.#tokenToUse.value.decimals
? Number(range.min).toFixed(this.#tokenToUse.value.decimals)
: range.min,
}
}

if (shouldRecalculateAmountToReceive) {
Expand Down Expand Up @@ -229,7 +233,9 @@ export class SimpleSwapService<BSName extends string = string> implements SwapSe
}

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

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

0 comments on commit 02ffcb7

Please sign in to comment.