From 14d8660c6499dd49b73e5a77cb6d05c4927620c0 Mon Sep 17 00:00:00 2001 From: uncoolzero <107518216+uncoolzero@users.noreply.github.com> Date: Mon, 26 Jun 2023 00:16:44 -0300 Subject: [PATCH] Improved Approval Checks - Buy Fert, Deposit --- projects/ui/src/components/Barn/Actions/Buy.tsx | 7 ++++++- projects/ui/src/components/Field/Actions/Sow.tsx | 2 +- projects/ui/src/components/Silo/Actions/Deposit.tsx | 7 ++++++- projects/ui/src/components/Swap/Actions/Transfer.tsx | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/projects/ui/src/components/Barn/Actions/Buy.tsx b/projects/ui/src/components/Barn/Actions/Buy.tsx index 6e7de4761e..25ae49f99f 100644 --- a/projects/ui/src/components/Barn/Actions/Buy.tsx +++ b/projects/ui/src/components/Barn/Actions/Buy.tsx @@ -159,6 +159,11 @@ const BuyForm: FC< return _params; }, [values.balanceFrom]); + /// Approval Checks + const shouldApprove = + values.balanceFrom === BalanceFrom.EXTERNAL || + values.balanceFrom === BalanceFrom.TOTAL && values.tokens[0].amount?.gt(balances[tokenIn.address].internal); + return ( @@ -257,7 +262,7 @@ const BuyForm: FC< disabled={!isValid} // Smart props contract={sdk.contracts.beanstalk} - tokens={values.tokens} + tokens={shouldApprove ? values.tokens : []} > Buy diff --git a/projects/ui/src/components/Field/Actions/Sow.tsx b/projects/ui/src/components/Field/Actions/Sow.tsx index f2132b62c9..7878303aff 100644 --- a/projects/ui/src/components/Field/Actions/Sow.tsx +++ b/projects/ui/src/components/Field/Actions/Sow.tsx @@ -149,7 +149,7 @@ const SowForm: FC< claimBeansState: values.claimableBeans, }); - /// Checks + /// Approval Checks const shouldApprove = values.balanceFrom === BalanceFrom.EXTERNAL || values.balanceFrom === BalanceFrom.TOTAL && values.tokens[0].amount?.gt(balances[tokenIn.address].internal); diff --git a/projects/ui/src/components/Silo/Actions/Deposit.tsx b/projects/ui/src/components/Silo/Actions/Deposit.tsx index 09663ea9b6..a997bfa68b 100644 --- a/projects/ui/src/components/Silo/Actions/Deposit.tsx +++ b/projects/ui/src/components/Silo/Actions/Deposit.tsx @@ -179,6 +179,11 @@ const DepositForm: FC< values.tokens[0].amount === undefined && values.claimableBeans.amount?.eq(0); + /// Approval Checks + const shouldApprove = + values.balanceFrom === BalanceFrom.EXTERNAL || + values.balanceFrom === BalanceFrom.TOTAL && values.tokens[0].amount?.gt(balances[tokenIn.address].internal); + return ( Deposit diff --git a/projects/ui/src/components/Swap/Actions/Transfer.tsx b/projects/ui/src/components/Swap/Actions/Transfer.tsx index 0053fa06e6..88cb7e8596 100644 --- a/projects/ui/src/components/Swap/Actions/Transfer.tsx +++ b/projects/ui/src/components/Swap/Actions/Transfer.tsx @@ -236,7 +236,7 @@ const TransferForm: FC< // eslint-disable-next-line react-hooks/exhaustive-deps }, [handleSetBalanceFrom, account, toMode]); - /// Checks + /// Approval Checks const shouldApprove = fromMode === FarmFromMode.EXTERNAL || fromMode === FarmFromMode.INTERNAL_EXTERNAL && amount?.gt(balances[tokenIn.address]?.internal);