Skip to content

Commit

Permalink
Merge pull request #1312 from AmbireTech/fix/swap-amount-without-zero
Browse files Browse the repository at this point in the history
Bug/ Swap fromtoken amount without zero (.1) error
  • Loading branch information
PetromirDev authored Feb 18, 2025
2 parents f1e885b + ea09241 commit 4c5df8a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/controllers/swapAndBridge/swapAndBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ export class SwapAndBridgeController extends EventEmitter {
} = props

if (fromAmount !== undefined) {
const fromAmountFormatted = fromAmount.indexOf('.') === 0 ? `0${fromAmount}` : fromAmount
this.fromAmount = fromAmount
;(() => {
if (fromAmount === '') {
Expand All @@ -512,7 +513,7 @@ export class SwapAndBridgeController extends EventEmitter {
const { tokenPriceBigInt, tokenPriceDecimals } = convertTokenPriceToBigInt(tokenPrice)

// Convert the numbers to big int
const amountInFiatBigInt = parseUnits(fromAmount, amountInFiatDecimals)
const amountInFiatBigInt = parseUnits(fromAmountFormatted, amountInFiatDecimals)

this.fromAmount = formatUnits(
(amountInFiatBigInt * CONVERSION_PRECISION_POW) / tokenPriceBigInt,
Expand All @@ -528,7 +529,7 @@ export class SwapAndBridgeController extends EventEmitter {
if (!this.fromSelectedToken) return

const sanitizedFieldValue = getSanitizedAmount(
fromAmount,
fromAmountFormatted,
this.fromSelectedToken.decimals
)
// Convert the field value to big int
Expand Down

0 comments on commit 4c5df8a

Please sign in to comment.