Skip to content

Commit

Permalink
fix: balance check
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomariscal committed Aug 3, 2023
1 parent 880f1ed commit b6b8260
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/components/cactiComponents/ActionResponse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ export const ActionResponse = ({
*
* */
const [hasEnoughBalance, setHasEnoughBalance] = useState(false);

useEffect(() => {
if (approvalParams?.skipBalanceCheck) return setHasEnoughBalance(true);
if (approvalParams?.skipBalanceCheck || approvalParams?.skipApproval)
return setHasEnoughBalance(true);

// check value balance if skipping approval cuz we assume user is using eth
if (approvalParams?.skipApproval && sendParams?.value! <= ethBal!)
return setHasEnoughBalance(true);
if (sendParams?.value! <= ethBal!) return setHasEnoughBalance(true);

// check approval token balance
balance &&
approvalParams?.approvalAmount &&
if (balance && approvalParams?.approvalAmount)
setHasEnoughBalance(balance.gte(approvalParams?.approvalAmount!));
}, [
approvalParams?.approvalAmount,
Expand All @@ -153,6 +153,7 @@ export const ActionResponse = ({
if (!hasAllowance && hasEnoughBalance) {
// case: enough balance, but allowance not sufficient */
if (approveTx) {
console.log('🦄 ~ file: ActionResponse.tsx:156 ~ useEffect ~ approveTx:', approveTx);
setAction({ name: 'approve', fn: approveTx });
console.log('READY FOR APPROVAL: Has balance.');
setLabel(`A token approval is required`);
Expand Down

0 comments on commit b6b8260

Please sign in to comment.