Skip to content

Commit

Permalink
Fix payment flow for overflow amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
mliu committed Mar 21, 2024
1 parent 04b24c9 commit 5a09244
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
useCLPoolAllowance,
} from '@huma-finance/shared'
import React, { useCallback, useEffect, useState } from 'react'
import { BigNumber } from 'ethers'

import { useAppDispatch } from '../../../hooks/useRedux'
import { setPaymentAmount, setStep } from '../../../store/widgets.reducers'
Expand Down Expand Up @@ -43,8 +44,8 @@ export function ChooseAmount({
)

const handleAction = useCallback(() => {
const payAmount = upScale(currentAmount, decimals)
const step = toBigNumber(payAmount).gt(allowance)
const payAmount = upScale<BigNumber>(toBigNumber(currentAmount), decimals)
const step = payAmount.gt(allowance)
? WIDGET_STEP.ApproveAllowance
: WIDGET_STEP.Transfer
dispatch(setStep(step))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useWeb3React } from '@web3-react/core'
import { PoolInfoType, toBigNumber, upScale } from '@huma-finance/shared'
import React, { useCallback } from 'react'
import { BigNumber } from 'ethers'

import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
import { selectWidgetState } from '../../../store/widgets.selectors'
Expand All @@ -17,7 +18,10 @@ export function Transfer({ poolInfo }: Props): React.ReactElement {
const { account } = useWeb3React()
const { paymentAmount } = useAppSelector(selectWidgetState)
const { decimals } = poolInfo.poolUnderlyingToken
const paymentBigNumber = toBigNumber(upScale(paymentAmount!, decimals))
const paymentBigNumber = upScale<BigNumber>(
toBigNumber(paymentAmount!),
decimals,
)

const handleSuccess = useCallback(() => {
dispatch(setStep(WIDGET_STEP.Done))
Expand Down

0 comments on commit 5a09244

Please sign in to comment.