From d9456db0836ecda78e5f53f0ee95febf93973cd1 Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Thu, 2 Nov 2023 16:23:29 +0700 Subject: [PATCH] fix: decimals (#2359) --- src/state/burn/hooks.ts | 3 ++- src/state/mint/hooks.ts | 2 ++ src/state/swap/hooks.ts | 8 ++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/state/burn/hooks.ts b/src/state/burn/hooks.ts index a247226edb..e653007e94 100644 --- a/src/state/burn/hooks.ts +++ b/src/state/burn/hooks.ts @@ -359,6 +359,7 @@ export function useDerivedZapOutInfo( const independentTokenAmount: CurrencyAmount | undefined = tryParseAmount( zapOutAmount.amount.toString(), currencies[independentTokenField], + false, ) const dependentTokenAmount: CurrencyAmount | undefined = useMemo(() => { @@ -368,7 +369,7 @@ export function useDerivedZapOutInfo( ? JSBI.divide(JSBI.multiply(liquidityValueA.quotient, percentToRemove.numerator), percentToRemove.denominator) : JSBI.divide(JSBI.multiply(liquidityValueB.quotient, percentToRemove.numerator), percentToRemove.denominator) - return tryParseAmount(amount.toString(), currencies[dependentTokenField]) + return tryParseAmount(amount.toString(), currencies[dependentTokenField], false) } else { return undefined } diff --git a/src/state/mint/hooks.ts b/src/state/mint/hooks.ts index 9b700f6f95..c5af973882 100644 --- a/src/state/mint/hooks.ts +++ b/src/state/mint/hooks.ts @@ -320,6 +320,7 @@ export function useDerivedZapInInfo( const independentAmount: CurrencyAmount | undefined = tryParseAmount( zapInAmounts.amounts.tokenInAmount.toString(), currencies[independentField]?.wrapped, + false, ) const dependentAmount: CurrencyAmount | undefined = useMemo(() => { @@ -332,6 +333,7 @@ export function useDerivedZapInInfo( const dependentTokenAmount = tryParseAmount( zapInAmounts.amounts.tokenOutAmount.toString(), currencies[dependentField]?.wrapped, + false, ) return dependentTokenAmount diff --git a/src/state/swap/hooks.ts b/src/state/swap/hooks.ts index 03677c7de2..a4f1dd3306 100644 --- a/src/state/swap/hooks.ts +++ b/src/state/swap/hooks.ts @@ -145,13 +145,17 @@ export function useSwapActionHandlers(): { } // try to parse a user entered amount for a given token -export function tryParseAmount(value?: string, currency?: T): CurrencyAmount | undefined { +export function tryParseAmount( + value?: string, + currency?: T, + scaleDecimals = true, +): CurrencyAmount | undefined { if (!value || !currency) { return undefined } try { const typedValueParsed = parseFraction(value) - .multiply(10 ** currency.decimals) + .multiply(scaleDecimals ? 10 ** currency.decimals : 1) .toFixed(0) const result = CurrencyAmount.fromRawAmount(currency, typedValueParsed) return result