-
Notifications
You must be signed in to change notification settings - Fork 456
chore: permit modifications #1325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
3895517
7ab4c8c
b1c0012
3830a05
e9346c6
83b731f
7647937
a5b60f6
a504d1e
978a5b8
cbe1951
9776302
8fd5cc9
c4b62b5
45f70af
dc0c453
7a3db44
f822489
be19f8a
040f90e
c9fc883
1d76a69
b1a83aa
3b37cd6
27b8501
48672d5
a2756f7
a1897aa
a3016c7
570805b
6ec34df
9fd8b38
2312958
47297be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { Trans } from '@lingui/macro'; | ||
|
|
||
| import { Link } from '../primitives/Link'; | ||
| import { TextWithTooltip, TextWithTooltipProps } from '../TextWithTooltip'; | ||
|
|
||
| export const ApprovalTooltip = ({ ...rest }: TextWithTooltipProps) => { | ||
| return ( | ||
| <TextWithTooltip {...rest}> | ||
| <Trans> | ||
| To continue you need to grant Aave smart contracts permission to move your funds from your | ||
| wallet. Depending on the asset, it is done by signing the permission message (gas free), or | ||
| by submitting an approval transaction (requires gas).{' '} | ||
| <Link | ||
| href="https://ethereum.org/en/developers/tutorials/transfers-and-approval-of-erc-20-tokens-from-a-solidity-smart-contract/" | ||
| underline="always" | ||
| > | ||
| Learn more | ||
| </Link> | ||
| </Trans> | ||
| </TextWithTooltip> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,7 +85,9 @@ export const CollateralRepayActions = ({ | |
| sx={sx} | ||
| {...props} | ||
| handleAction={action} | ||
| handleApproval={() => approval()} | ||
| handleApproval={() => | ||
| approval({ amount: repayAmount, underlyingAsset: poolReserve.aTokenAddress }) | ||
|
||
| } | ||
| actionText={<Trans>Repay {symbol}</Trans>} | ||
| actionInProgressText={<Trans>Repaying {symbol}</Trans>} | ||
| /> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,12 +37,13 @@ export const RepayActions = ({ | |
| const { currentChainId: chainId, currentMarketData } = useProtocolDataContext(); | ||
| const repay = useRootStore((state) => state.repay); | ||
| const repayWithPermit = useRootStore((state) => state.repayWithPermit); | ||
|
|
||
| const tryPermit = | ||
| currentMarketData.v3 && | ||
| permitByChainAndToken[chainId]?.[utils.getAddress(poolAddress).toLowerCase()]; | ||
|
||
| const { approval, action, requiresApproval, loadingTxns, approvalTxState, mainTxState } = | ||
| useTransactionHandler({ | ||
| // move tryPermit to store | ||
| tryPermit: | ||
| currentMarketData.v3 && permitByChainAndToken[chainId]?.[utils.getAddress(poolAddress)], | ||
| tryPermit, | ||
| handleGetTxns: async () => { | ||
| return repay({ | ||
| amountToRepay, | ||
|
|
@@ -85,9 +86,19 @@ export const RepayActions = ({ | |
| sx={sx} | ||
| {...props} | ||
| handleAction={action} | ||
| handleApproval={() => approval(amountToRepay, poolAddress)} | ||
| handleApproval={() => approval({ amount: amountToRepay, underlyingAsset: poolAddress })} | ||
| actionText={<Trans>Repay {symbol}</Trans>} | ||
| actionInProgressText={<Trans>Repaying {symbol}</Trans>} | ||
| approvalFallback={ | ||
|
||
| tryPermit | ||
| ? () => | ||
| approval({ | ||
| amount: amountToRepay, | ||
| underlyingAsset: poolAddress, | ||
| forceApprovalTx: true, | ||
| }) | ||
| : undefined | ||
| } | ||
| /> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,12 @@ interface UseTransactionHandlerProps { | |
| deps?: DependencyList; | ||
| } | ||
|
|
||
| interface ApprovalProps { | ||
| amount?: string; | ||
| underlyingAsset?: string; | ||
| forceApprovalTx?: boolean; | ||
| } | ||
|
|
||
| export const useTransactionHandler = ({ | ||
| handleGetTxns, | ||
| handleGetPermitTxns, | ||
|
|
@@ -37,7 +43,6 @@ export const useTransactionHandler = ({ | |
| loadingTxns, | ||
| setLoadingTxns, | ||
| setTxError, | ||
| setRetryWithApproval, | ||
| } = useModalContext(); | ||
| const { signTxData, sendTx, getTxError } = useWeb3Context(); | ||
| const { refetchWalletBalances, refetchPoolData, refetchIncentiveData } = | ||
|
|
@@ -102,9 +107,9 @@ export const useTransactionHandler = ({ | |
| } | ||
| }; | ||
|
|
||
| const approval = async (amount?: string, underlyingAsset?: string) => { | ||
| const approval = async ({ amount, underlyingAsset, forceApprovalTx }: ApprovalProps) => { | ||
| if (approvalTx) { | ||
| if (usePermit && amount && underlyingAsset) { | ||
| if (usePermit && amount && underlyingAsset && !forceApprovalTx) { | ||
| setApprovalTxState({ ...approvalTxState, loading: true }); | ||
| try { | ||
| // deadline is an hour after signature | ||
|
|
@@ -134,18 +139,10 @@ export const useTransactionHandler = ({ | |
| txHash: undefined, | ||
| loading: false, | ||
| }); | ||
|
|
||
| // set use permit to false to retry with normal approval | ||
| setUsePermit(false); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's some cleanup we could do in here now. I don't think we need |
||
| setRetryWithApproval(true); | ||
| } | ||
| } catch (error) { | ||
| if (!mounted.current) return; | ||
|
|
||
| // set use permit to false to retry with normal approval | ||
| setUsePermit(false); | ||
| setRetryWithApproval(true); | ||
|
|
||
| const parsedError = getErrorTextFromError(error, TxAction.GAS_ESTIMATION, false); | ||
| setTxError(parsedError); | ||
| setApprovalTxState({ | ||
|
|
||
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.