Skip to content

Commit

Permalink
fix(earn): display correct amounts on input amount token toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
MuckT committed Oct 16, 2024
1 parent 4af772d commit 775a925
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/earn/EarnEnterAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ function EarnEnterAmount({ route }: Props) {
}, [mode])

const [inputToken, setInputToken] = useState<TokenBalance>(() => availableInputTokens[0])
const [transactionToken, setTransactionToken] = useState<TokenBalance>(() =>
isWithdrawal ? withdrawToken : inputToken
)

const reviewBottomSheetRef = useRef<BottomSheetModalRefType>(null)
const feeDetailsBottomSheetRef = useRef<BottomSheetModalRefType>(null)
Expand Down Expand Up @@ -138,6 +141,7 @@ function EarnEnterAmount({ route }: Props) {

const onSelectToken = (token: TokenBalance) => {
setInputToken(token)

Check warning on line 143 in src/earn/EarnEnterAmount.tsx

View check run for this annotation

Codecov / codecov/patch

src/earn/EarnEnterAmount.tsx#L143

Added line #L143 was not covered by tests
if (!isWithdrawal) setTransactionToken(token)
tokenBottomSheetRef.current?.close()
// NOTE: analytics is already fired by the bottom sheet, don't need one here
}
Expand Down Expand Up @@ -224,20 +228,15 @@ function EarnEnterAmount({ route }: Props) {
localAmount: parsedLocalAmount,
}
}
}, [tokenAmountInput, localAmountInput, enteredIn, mode])
}, [tokenAmountInput, localAmountInput, enteredIn, mode, transactionToken])

// This is for withdrawals as we want the user to be able to input the amounts in the deposit token
const { transactionToken, transactionTokenAmount } = useMemo(() => {
const transactionToken = isWithdrawal ? withdrawToken : inputToken
const transactionTokenAmount = isWithdrawal
? tokenAmount && tokenAmount.dividedBy(pool.pricePerShare[0])
: tokenAmount
const transactionTokenAmount = useMemo(
() =>
isWithdrawal ? tokenAmount && tokenAmount.dividedBy(pool.pricePerShare[0]) : tokenAmount,

return {
transactionToken,
transactionTokenAmount,
}
}, [inputToken, withdrawToken, tokenAmount, isWithdrawal, pool])
[transactionToken, inputToken, withdrawToken, tokenAmount, isWithdrawal, pool]
)

const balanceInInputToken = useMemo(
() =>
Expand Down

0 comments on commit 775a925

Please sign in to comment.