From 0f42a0b3ab427e9e7df1afb70dc7801e01b77d60 Mon Sep 17 00:00:00 2001 From: uncoolzero <107518216+uncoolzero@users.noreply.github.com> Date: Sun, 25 Jun 2023 19:52:01 -0300 Subject: [PATCH 1/2] Improved approval checks --- projects/ui/src/components/Field/Actions/Sow.tsx | 7 ++++++- projects/ui/src/components/Swap/Actions/Transfer.tsx | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/projects/ui/src/components/Field/Actions/Sow.tsx b/projects/ui/src/components/Field/Actions/Sow.tsx index 38e39ac534..f2132b62c9 100644 --- a/projects/ui/src/components/Field/Actions/Sow.tsx +++ b/projects/ui/src/components/Field/Actions/Sow.tsx @@ -149,6 +149,11 @@ const SowForm: FC< claimBeansState: values.claimableBeans, }); + /// Checks + const shouldApprove = + values.balanceFrom === BalanceFrom.EXTERNAL || + values.balanceFrom === BalanceFrom.TOTAL && values.tokens[0].amount?.gt(balances[tokenIn.address].internal); + const handleSetBalanceFrom = useCallback( (_balanceFrom: BalanceFrom) => { setFieldValue('balanceFrom', _balanceFrom); @@ -354,7 +359,7 @@ const SowForm: FC< size="large" disabled={!isSubmittable || isSubmitting} contract={sdk.contracts.beanstalk} - tokens={values.tokens} + tokens={shouldApprove ? values.tokens : []} mode="auto" > Sow diff --git a/projects/ui/src/components/Swap/Actions/Transfer.tsx b/projects/ui/src/components/Swap/Actions/Transfer.tsx index 824d666b67..0053fa06e6 100644 --- a/projects/ui/src/components/Swap/Actions/Transfer.tsx +++ b/projects/ui/src/components/Swap/Actions/Transfer.tsx @@ -239,7 +239,7 @@ const TransferForm: FC< /// Checks const shouldApprove = fromMode === FarmFromMode.EXTERNAL || - fromMode === FarmFromMode.INTERNAL_EXTERNAL; + fromMode === FarmFromMode.INTERNAL_EXTERNAL && amount?.gt(balances[tokenIn.address]?.internal); const amountsCheck = amount?.gt(0); const enoughBalanceCheck = amount 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 2/2] 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);