Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const testData = {
assets.polygonV3Market.EURS,
assets.polygonV3Market.jEUR,
assets.polygonV3Market.agEUR,
assets.polygonV3Market.miMATIC,
],
},
};
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"test:ci": "jest --ci"
},
"dependencies": {
"@aave/contract-helpers": "1.9.0",
"@aave/math-utils": "1.9.0",
"@aave/contract-helpers": "1.9.1-cae134738b8899ec4f5227d4932cb8f8ab5e4acd.0+6c081d5",
"@aave/math-utils": "1.9.1-cae134738b8899ec4f5227d4932cb8f8ab5e4acd.0+6c081d5",
"@emotion/cache": "11.10.3",
"@emotion/react": "11.10.4",
"@emotion/server": "latest",
Expand Down
4 changes: 3 additions & 1 deletion src/components/TextWithTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface TextWithTooltipProps extends TypographyProps {
text?: ReactNode;
icon?: ReactNode;
iconSize?: number;
iconMargin?: number;
color?: string;
// eslint-disable-next-line
children?: ReactElement<any, string | JSXElementConstructor<any>>;
Expand All @@ -18,6 +19,7 @@ export const TextWithTooltip = ({
text,
icon,
iconSize = 14,
iconMargin,
color,
children,
...rest
Expand All @@ -39,7 +41,7 @@ export const TextWithTooltip = ({
borderRadius: '50%',
p: 0,
minWidth: 0,
ml: 0.5,
ml: iconMargin || 0.5,
}}
>
<SvgIcon
Expand Down
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 and wallet you use, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { CheckIcon } from '@heroicons/react/outline';
import { CogIcon } from '@heroicons/react/solid';
import { Trans } from '@lingui/macro';
import {
Box,
ListItemIcon,
ListItemText,
Menu,
MenuItem,
SvgIcon,
Typography,
} from '@mui/material';
import * as React from 'react';
import { ApprovalMethod } from 'src/store/walletSlice';

interface ApprovalMethodToggleButtonProps {
currentMethod: ApprovalMethod;
setMethod: (newMethod: ApprovalMethod) => void;
}

export const ApprovalMethodToggleButton = ({
currentMethod,
setMethod,
}: ApprovalMethodToggleButtonProps) => {
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const open = Boolean(anchorEl);
const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};

return (
<>
<Box onClick={handleClick} sx={{ display: 'flex', alignItems: 'center', cursor: 'pointer' }}>
<Typography variant="subheader2" color="info.main">
<Trans>{currentMethod}</Trans>
</Typography>
<SvgIcon sx={{ fontSize: 16, ml: 1, color: 'info.main' }}>
<CogIcon />
</SvgIcon>
</Box>

<Menu
anchorEl={anchorEl}
open={open}
onClose={handleClose}
MenuListProps={{
'aria-labelledby': 'basic-button',
}}
keepMounted={true}
data-cy={`approveMenu_${currentMethod}`}
>
<MenuItem
selected={currentMethod === ApprovalMethod.PERMIT}
value={ApprovalMethod.PERMIT}
onClick={() => {
if (currentMethod === ApprovalMethod.APPROVE) {
setMethod(ApprovalMethod.PERMIT);
}
handleClose();
}}
>
<ListItemText primaryTypographyProps={{ variant: 'subheader1' }}>
<Trans>{ApprovalMethod.PERMIT}</Trans>
</ListItemText>
<ListItemIcon>
<SvgIcon>{currentMethod === ApprovalMethod.PERMIT && <CheckIcon />}</SvgIcon>
</ListItemIcon>
</MenuItem>

<MenuItem
selected={currentMethod === ApprovalMethod.APPROVE}
value={ApprovalMethod.APPROVE}
onClick={() => {
if (currentMethod === ApprovalMethod.PERMIT) {
setMethod(ApprovalMethod.APPROVE);
}
handleClose();
}}
>
<ListItemText primaryTypographyProps={{ variant: 'subheader1' }}>
<Trans>{ApprovalMethod.APPROVE}</Trans>
</ListItemText>
<ListItemIcon>
<SvgIcon>{currentMethod === ApprovalMethod.APPROVE && <CheckIcon />}</SvgIcon>
</ListItemIcon>
</MenuItem>
</Menu>
Copy link
Contributor

Choose a reason for hiding this comment

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

Could these menu item components be simplified? They look identical other than the ApprovalMethod.VALUE

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would end up with more code to split to separate component and pass currentMethod, buttonMethod, setMethod, and handleClose as props so I think it's fine to leave as is

</>
);
};
69 changes: 0 additions & 69 deletions src/components/transactions/FlowCommons/LeftHelperText.tsx

This file was deleted.

74 changes: 47 additions & 27 deletions src/components/transactions/FlowCommons/RightHelperText.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { ExternalLinkIcon } from '@heroicons/react/outline';
import { Trans } from '@lingui/macro';
import { Box, Link, SvgIcon } from '@mui/material';
import { Box, Link, SvgIcon, Typography } from '@mui/material';
import { ApprovalMethodToggleButton } from 'src/components/transactions/FlowCommons/ApprovalMethodToggleButton';
import { MOCK_SIGNED_HASH } from 'src/helpers/useTransactionHandler';
import { useProtocolDataContext } from 'src/hooks/useProtocolDataContext';
import { useRootStore } from 'src/store/root';
import { ApprovalMethod } from 'src/store/walletSlice';

export type RightHelperTextProps = {
approvalHash?: string;
tryPermit?: boolean;
};

const ExtLinkIcon = () => (
Expand All @@ -14,32 +18,48 @@ const ExtLinkIcon = () => (
</SvgIcon>
);

export const RightHelperText = ({ approvalHash }: RightHelperTextProps) => {
export const RightHelperText = ({ approvalHash, tryPermit }: RightHelperTextProps) => {
const { walletApprovalMethodPreference, setWalletApprovalMethodPreference } = useRootStore();
const usingPermit = tryPermit && walletApprovalMethodPreference;
const { currentNetworkConfig } = useProtocolDataContext();
const isSigned = approvalHash === MOCK_SIGNED_HASH;
// a signature will not be reviewable on etherscan
if (!approvalHash || isSigned) return null;
return (
<Box
sx={{
display: 'flex',
justifyContent: 'flex-start',
alignItems: 'center',
}}
>
{approvalHash && (
<Link
variant="helperText"
href={currentNetworkConfig.explorerLinkBuilder({ tx: approvalHash })}
sx={{ display: 'inline-flex', alignItems: 'center' }}
underline="hover"
target="_blank"
rel="noreferrer noopener"
>
<Trans>Review approval tx details</Trans>
<ExtLinkIcon />
</Link>
)}
</Box>
);
// a signature is not submitted on-chain so there is no link to review
if (!approvalHash && !isSigned && tryPermit)
return (
<Box sx={{ display: 'inline-flex', alignItems: 'center', mb: 2 }}>
<Typography variant="subheader2" color="text.secondary">
<Trans>Approve with</Trans>&nbsp;
</Typography>
<ApprovalMethodToggleButton
currentMethod={walletApprovalMethodPreference}
setMethod={(method: ApprovalMethod) => setWalletApprovalMethodPreference(method)}
/>
</Box>
);
if (approvalHash && !usingPermit)
return (
<Box
sx={{
display: 'flex',
justifyContent: 'flex-start',
alignItems: 'center',
pb: 1,
}}
>
{approvalHash && (
<Link
variant="helperText"
href={currentNetworkConfig.explorerLinkBuilder({ tx: approvalHash })}
sx={{ display: 'inline-flex', alignItems: 'center' }}
underline="hover"
target="_blank"
rel="noreferrer noopener"
>
<Trans>Review approval tx details</Trans>
<ExtLinkIcon />
</Link>
)}
</Box>
);
return <></>;
};
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
Loading