Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
change logic
Browse files Browse the repository at this point in the history
  • Loading branch information
W3stside committed Jan 19, 2022
1 parent 9945e7b commit e272016
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/custom/hooks/useApproveCallback/useApproveCallbackMod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ export function useApproveCallback({
// we might not have enough data to know whether or not we need to approve
if (!currentAllowance) return ApprovalState.UNKNOWN

// is the optionally set check amount less than current set allowance?
const isOptionalAmountLessThanAllowance = !!amountToCheckAgainstAllowance?.lessThan(currentAllowance)
// is current set allowance less than actual approving amount?
const isApprovingAmountLessThanAllowance = currentAllowance.lessThan(amountToApprove)
// is amountToCheckAgainstAllowance < allowance
// if TRUE = need to approve
const optionalAmountNeedsApproval = !!amountToCheckAgainstAllowance?.greaterThan(currentAllowance)
// is amountToApprove > allowance
// if TRUE = need to approve
const amountToApproveNeedsApproval = amountToApprove.greaterThan(currentAllowance)

// Return approval state
if (isOptionalAmountLessThanAllowance || isApprovingAmountLessThanAllowance) {
if (optionalAmountNeedsApproval || amountToApproveNeedsApproval) {
return pendingApproval ? ApprovalState.PENDING : ApprovalState.NOT_APPROVED
} else {
// Enough allowance
Expand Down

0 comments on commit e272016

Please sign in to comment.