Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CU-86a5x0q43 - BS Swap - Bug - availableTokensToUse has tokens that d… #121

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading