Skip to content

Commit

Permalink
fix: decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
namgold committed Nov 2, 2023
1 parent 493a466 commit 17379cb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/state/burn/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export function useDerivedZapOutInfo(
const independentTokenAmount: CurrencyAmount<Currency> | undefined = tryParseAmount(
zapOutAmount.amount.toString(),
currencies[independentTokenField],
false,
)

const dependentTokenAmount: CurrencyAmount<Currency> | undefined = useMemo(() => {
Expand All @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions src/state/mint/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ export function useDerivedZapInInfo(
const independentAmount: CurrencyAmount<Currency> | undefined = tryParseAmount(
zapInAmounts.amounts.tokenInAmount.toString(),
currencies[independentField]?.wrapped,
false,
)

const dependentAmount: CurrencyAmount<Currency> | undefined = useMemo(() => {
Expand All @@ -332,6 +333,7 @@ export function useDerivedZapInInfo(
const dependentTokenAmount = tryParseAmount(
zapInAmounts.amounts.tokenOutAmount.toString(),
currencies[dependentField]?.wrapped,
false,
)

return dependentTokenAmount
Expand Down
8 changes: 6 additions & 2 deletions src/state/swap/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,17 @@ export function useSwapActionHandlers(): {
}

// try to parse a user entered amount for a given token
export function tryParseAmount<T extends Currency>(value?: string, currency?: T): CurrencyAmount<T> | undefined {
export function tryParseAmount<T extends Currency>(
value?: string,
currency?: T,
scaleDecimals = true,
): CurrencyAmount<T> | 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
Expand Down

0 comments on commit 17379cb

Please sign in to comment.