diff --git a/common/changes/@cityofzion/bs-neo3/CU-86a5x0q43-1_2024-12-14-02-48.json b/common/changes/@cityofzion/bs-neo3/CU-86a5x0q43-1_2024-12-14-02-48.json new file mode 100644 index 0000000..3212589 --- /dev/null +++ b/common/changes/@cityofzion/bs-neo3/CU-86a5x0q43-1_2024-12-14-02-48.json @@ -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" +} \ No newline at end of file diff --git a/common/changes/@cityofzion/bs-swap/CU-86a5x0q43-1_2024-12-14-02-48.json b/common/changes/@cityofzion/bs-swap/CU-86a5x0q43-1_2024-12-14-02-48.json new file mode 100644 index 0000000..2bec506 --- /dev/null +++ b/common/changes/@cityofzion/bs-swap/CU-86a5x0q43-1_2024-12-14-02-48.json @@ -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" +} \ No newline at end of file diff --git a/packages/bs-neo3/src/BSNeo3.ts b/packages/bs-neo3/src/BSNeo3.ts index f2e732f..d11f456 100644 --- a/packages/bs-neo3/src/BSNeo3.ts +++ b/packages/bs-neo3/src/BSNeo3.ts @@ -127,7 +127,10 @@ export class BSNeo3 { 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 }, diff --git a/packages/bs-swap/src/services/SimpleSwapService.ts b/packages/bs-swap/src/services/SimpleSwapService.ts index 6e1109b..e7fc7ab 100644 --- a/packages/bs-swap/src/services/SimpleSwapService.ts +++ b/packages/bs-swap/src/services/SimpleSwapService.ts @@ -170,7 +170,11 @@ export class SimpleSwapService 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) { @@ -229,7 +233,9 @@ export class SimpleSwapService implements SwapSe } async setAmountToUse(amount: string | null): Promise { - 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']) }