Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3895517
feat: use updated permit function
defispartan Nov 18, 2022
7ab4c8c
chore: bump package for proper export
defispartan Nov 18, 2022
b1c0012
chore: standardize permitConfig casing
defispartan Nov 18, 2022
3830a05
chore: small styling changes to approval flow
defispartan Nov 18, 2022
e9346c6
chore: remove approval component which was replaced with tooltip
defispartan Nov 18, 2022
83b731f
chore: remove retry with approval text placements
defispartan Nov 18, 2022
7647937
chore: modify approval function for explicit parmeters and allow forc…
defispartan Nov 18, 2022
a5b60f6
fix: build errors on handleApproval
defispartan Nov 18, 2022
a504d1e
chore: run i18n
defispartan Nov 18, 2022
978a5b8
chore: revert permit utility modification
defispartan Nov 22, 2022
cbe1951
chore rework approval fallback params
defispartan Nov 22, 2022
9776302
chore: update actions components approval params
defispartan Nov 22, 2022
8fd5cc9
chore: update text and link
defispartan Nov 23, 2022
c4b62b5
Merge branch 'main' into chore/permit-modifications
defispartan Nov 28, 2022
45f70af
chore: cleanup unused state
defispartan Nov 28, 2022
dc0c453
feat: move tryPermit logic to zustand store
defispartan Nov 28, 2022
7a3db44
feat: add approval tx to gas estimation
defispartan Nov 28, 2022
f822489
chore: remove unused import
defispartan Nov 28, 2022
be19f8a
Merge branch 'main' into chore/permit-modifications
bojanaave Nov 30, 2022
040f90e
feat: design updates for new approve/permit flow
defispartan Dec 8, 2022
c9fc883
feat: add wallet approval preferences to walletSlice
defispartan Dec 13, 2022
1d76a69
feat: add approval preference button
defispartan Dec 13, 2022
b1a83aa
feat: apply approval method toggle in TxActionsWrapper
defispartan Dec 14, 2022
3b37cd6
chore: rework params for approval toggle
defispartan Dec 14, 2022
27b8501
Merge branch 'main' into chore/permit-modifications
defispartan Dec 14, 2022
48672d5
chore: bump utils package to include permit gas estimations
defispartan Dec 14, 2022
a2756f7
feat: use wallet approval preference in tx handler
defispartan Dec 14, 2022
a1897aa
chor: bump icon size
defispartan Dec 14, 2022
a3016c7
chore: handle edge case with already approved action
defispartan Dec 14, 2022
570805b
chore: rename variable for consistency
defispartan Dec 14, 2022
6ec34df
test(fix): fix e-mode for polygon
MareskoY Dec 14, 2022
9fd8b38
chore: review
defispartan Dec 14, 2022
2312958
chore: review
defispartan Dec 14, 2022
47297be
fix: localStorage override with multiple wallets
defispartan Dec 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions src/components/infoModalContents/ApprovalInfoContent.tsx

This file was deleted.

14 changes: 0 additions & 14 deletions src/components/infoModalContents/RetryWithApprovalInfoContent.tsx

This file was deleted.

19 changes: 19 additions & 0 deletions src/components/infoTooltips/ApprovalTooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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://eips.ethereum.org/EIPS/eip-2612" underline="always">
Learn more
</Link>
</Trans>
</TextWithTooltip>
);
};
2 changes: 1 addition & 1 deletion src/components/transactions/Borrow/BorrowActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const BorrowActions = ({
handleAction={action}
actionText={<Trans>Borrow {symbol}</Trans>}
actionInProgressText={<Trans>Borrowing {symbol}</Trans>}
handleApproval={() => approval(amountToBorrow, poolAddress)}
handleApproval={() => approval({ amount: amountToBorrow, underlyingAsset: poolAddress })}
requiresApproval={requiresApproval}
preparingTransactions={loadingTxns}
sx={sx}
Expand Down
28 changes: 4 additions & 24 deletions src/components/transactions/FlowCommons/LeftHelperText.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { CheckIcon } from '@heroicons/react/outline';
import { Trans } from '@lingui/macro';
import { Box, Typography, useTheme } from '@mui/material';

import { ApprovalInfoContent } from '../../infoModalContents/ApprovalInfoContent';
import { RetryWithApprovalInfoContent } from '../../infoModalContents/RetryWithApprovalInfoContent';
import { TextWithModal } from '../../TextWithModal';
import { ApprovalTooltip } from 'src/components/infoTooltips/ApprovalTooltip';

export type LeftHelperTextProps = {
error?: string;
Expand Down Expand Up @@ -39,30 +36,13 @@ export const LeftHelperText = ({ error, approvalHash, amount }: LeftHelperTextPr
</>
)}

{error && (
<TextWithModal
text={<Trans>Retry What?</Trans>}
iconSize={13}
iconColor={theme.palette.text.secondary}
withContentButton
variant="helperText"
color="text.secondary"
>
<RetryWithApprovalInfoContent />
</TextWithModal>
)}

{!approvalHash && !error && amount && (
<TextWithModal
<ApprovalTooltip
text={<Trans>Why do I need to approve?</Trans>}
iconSize={13}
iconColor={theme.palette.text.secondary}
withContentButton
variant="helperText"
variant="caption"
color="text.secondary"
>
<ApprovalInfoContent />
</TextWithModal>
/>
)}
</Box>
);
Expand Down
4 changes: 3 additions & 1 deletion src/components/transactions/Repay/CollateralRepayActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export const CollateralRepayActions = ({
sx={sx}
{...props}
handleAction={action}
handleApproval={() => approval()}
handleApproval={() =>
approval({ amount: repayWithAmount, underlyingAsset: poolReserve.aTokenAddress })
}
actionText={<Trans>Repay {symbol}</Trans>}
actionInProgressText={<Trans>Repaying {symbol}</Trans>}
/>
Expand Down
16 changes: 12 additions & 4 deletions src/components/transactions/Repay/RepayActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this doesn't work on forks because of a different chainId. We could move this to a helper in the store and handle the fork logic in there as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, this belongs in the store anyways

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,
Expand Down Expand Up @@ -85,9 +86,16 @@ export const RepayActions = ({
sx={sx}
{...props}
handleAction={action}
handleApproval={() => approval(amountToRepay, poolAddress)}
handleApproval={(forceApproval) =>
approval({
amount: amountToRepay,
underlyingAsset: poolAddress,
forceApprovalTx: forceApproval,
})
}
actionText={<Trans>Repay {symbol}</Trans>}
actionInProgressText={<Trans>Repaying {symbol}</Trans>}
tryPermit={tryPermit}
/>
);
};
2 changes: 1 addition & 1 deletion src/components/transactions/Stake/StakeActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const StakeActions = ({
isWrongNetwork={isWrongNetwork}
amount={amountToStake}
handleAction={action}
handleApproval={approval}
handleApproval={() => approval({ amount: amountToStake, underlyingAsset: selectedToken })}
symbol={symbol}
requiresAmount
actionText={<Trans>Stake</Trans>}
Expand Down
18 changes: 13 additions & 5 deletions src/components/transactions/Supply/SupplyActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export const SupplyActions = ({
const { currentChainId: chainId, currentMarketData } = useProtocolDataContext();
const supply = useRootStore((state) => state.supply);
const supplyWithPermit = useRootStore((state) => state.supplyWithPermit);

const tryPermit =
currentMarketData.v3 &&
permitByChainAndToken[chainId]?.[utils.getAddress(poolAddress).toLowerCase()];
const { approval, action, requiresApproval, loadingTxns, approvalTxState, mainTxState } =
useTransactionHandler({
// TODO: move tryPermit
tryPermit:
currentMarketData.v3 && permitByChainAndToken[chainId]?.[utils.getAddress(poolAddress)],
tryPermit,
handleGetTxns: async () => {
return supply({
amountToSupply,
Expand Down Expand Up @@ -66,12 +66,20 @@ export const SupplyActions = ({
isWrongNetwork={isWrongNetwork}
requiresAmount
amount={amountToSupply}
symbol={symbol}
preparingTransactions={loadingTxns}
actionText={<Trans>Supply {symbol}</Trans>}
actionInProgressText={<Trans>Supplying {symbol}</Trans>}
handleApproval={() => approval(amountToSupply, poolAddress)}
handleApproval={(forceApproval) =>
approval({
amount: amountToSupply,
underlyingAsset: poolAddress,
forceApprovalTx: forceApproval,
})
}
handleAction={action}
requiresApproval={requiresApproval}
tryPermit={tryPermit}
sx={sx}
{...props}
/>
Expand Down
4 changes: 3 additions & 1 deletion src/components/transactions/Swap/SwapActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export const SwapActions = ({
handleAction={action}
requiresAmount
amount={amountToSwap}
handleApproval={() => approval(amountToSwap, poolReserve.aTokenAddress)}
handleApproval={() =>
approval({ amount: amountToSwap, underlyingAsset: poolReserve.aTokenAddress })
}
requiresApproval={requiresApproval}
actionText={<Trans>Swap</Trans>}
actionInProgressText={<Trans>Swapping</Trans>}
Expand Down
38 changes: 29 additions & 9 deletions src/components/transactions/TxActionsWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Trans } from '@lingui/macro';
import { Box, BoxProps, Button, CircularProgress, Typography } from '@mui/material';
import { Box, BoxProps, Button, CircularProgress, Typography, useTheme } from '@mui/material';
import isEmpty from 'lodash/isEmpty';
import { ReactNode } from 'react';
import { TxStateType, useModalContext } from 'src/hooks/useModal';
Expand All @@ -14,7 +14,7 @@ interface TxActionsWrapperProps extends BoxProps {
actionText: ReactNode;
amount?: string;
approvalTxState?: TxStateType;
handleApproval?: () => Promise<void>;
handleApproval?: (forceApproval?: boolean) => Promise<void>;
handleAction: () => Promise<void>;
isWrongNetwork: boolean;
mainTxState: TxStateType;
Expand All @@ -23,6 +23,7 @@ interface TxActionsWrapperProps extends BoxProps {
requiresApproval: boolean;
symbol?: string;
blocked?: boolean;
tryPermit?: boolean;
}

export const TxActionsWrapper = ({
Expand All @@ -40,9 +41,10 @@ export const TxActionsWrapper = ({
sx,
symbol,
blocked,
tryPermit,
...rest
}: TxActionsWrapperProps) => {
const { txError, retryWithApproval } = useModalContext();
const { txError } = useModalContext();
const { watchModeOnlyAddress } = useWeb3Context();

const hasApprovalError =
Expand Down Expand Up @@ -78,15 +80,14 @@ export const TxActionsWrapper = ({
return null;
if (approvalTxState?.loading)
return { loading: true, disabled: true, content: <Trans>Approving {symbol}...</Trans> };
if (approvalTxState?.success) return { disabled: true, content: <Trans>Approved</Trans> };
if (retryWithApproval)
return { content: <Trans>Retry with approval</Trans>, handleClick: handleApproval };
return { content: <Trans>Approve to continue</Trans>, handleClick: handleApproval };
if (approvalTxState?.success)
return { disabled: true, content: <Trans>Approve Confirmed</Trans> };
return { content: <Trans>Approve {symbol} to continue</Trans>, handleClick: handleApproval };
}

const { content, disabled, loading, handleClick } = getMainParams();
const approvalParams = getApprovalParams();

const theme = useTheme();
return (
<Box sx={{ display: 'flex', flexDirection: 'column', mt: 12, ...sx }} {...rest}>
{requiresApproval && !watchModeOnlyAddress && (
Expand All @@ -100,7 +101,7 @@ export const TxActionsWrapper = ({
<Button
variant="contained"
disabled={approvalParams.disabled || blocked}
onClick={approvalParams.handleClick}
onClick={() => approvalParams.handleClick && approvalParams.handleClick()}
size="large"
sx={{ minHeight: '44px' }}
data-cy="approvalButton"
Expand Down Expand Up @@ -128,6 +129,25 @@ export const TxActionsWrapper = ({
<Trans>Watch-only mode. Connect to a wallet to perform transactions.</Trans>
</Typography>
)}
{tryPermit && approvalParams && (
<Box sx={{ display: 'flex', pt: 4 }}>
<Trans>
<Typography variant="caption" color="text.secondary">
Approval doesn&apos;t work?{' '}
</Typography>
<Typography
variant="subheader2"
sx={{ color: theme.palette.info.main, cursor: 'pointer', px: 1 }}
onClick={() => approvalParams.handleClick && approvalParams.handleClick(true)}
>
Submit a tx
</Typography>
<Typography variant="caption" color="text.secondary">
to approve instead.
</Typography>
</Trans>
</Box>
)}
</Box>
);
};
2 changes: 1 addition & 1 deletion src/components/transactions/Withdraw/WithdrawActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const WithdrawActions = ({
actionInProgressText={<Trans>Withdrawing {symbol}</Trans>}
actionText={<Trans>Withdraw {symbol}</Trans>}
handleAction={action}
handleApproval={() => approval(amountToWithdraw, poolAddress)}
handleApproval={() => approval({ amount: amountToWithdraw, underlyingAsset: poolAddress })}
requiresApproval={requiresApproval}
sx={sx}
/>
Expand Down
19 changes: 8 additions & 11 deletions src/helpers/useTransactionHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ interface UseTransactionHandlerProps {
deps?: DependencyList;
}

interface ApprovalProps {
amount?: string;
underlyingAsset?: string;
forceApprovalTx?: boolean;
}

export const useTransactionHandler = ({
handleGetTxns,
handleGetPermitTxns,
Expand All @@ -37,7 +43,6 @@ export const useTransactionHandler = ({
loadingTxns,
setLoadingTxns,
setTxError,
setRetryWithApproval,
} = useModalContext();
const { signTxData, sendTx, getTxError } = useWeb3Context();
const { refetchWalletBalances, refetchPoolData, refetchIncentiveData } =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -134,18 +139,10 @@ export const useTransactionHandler = ({
txHash: undefined,
loading: false,
});

// set use permit to false to retry with normal approval
setUsePermit(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 usePermit as state and we can just use the param passed in. It's also being returned from this hook, but doesn't look like it's used anywhere.

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({
Expand Down
Loading