Skip to content
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

Feat: Withdraw and Swap #1740

Merged
merged 29 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d206b91
feat: added simple withdraw and switch selector
JoaquinBattilana Aug 9, 2023
d76be2e
feat: tabs ui for changing withdraw type in withdraw modal
JoaquinBattilana Aug 9, 2023
6054530
feat: new withdraw and swap actions
JoaquinBattilana Aug 15, 2023
595af70
feat: small ux fixes to withdraw and swap
JoaquinBattilana Aug 16, 2023
e1a0dc4
feat: merged with main
JoaquinBattilana Aug 16, 2023
5205672
chore: deleted some not used console log
JoaquinBattilana Aug 16, 2023
ad140bc
feat: deleted async from withdraw and swap
JoaquinBattilana Aug 16, 2023
e6ee3c6
feat: ux reviews
JoaquinBattilana Aug 16, 2023
825a284
feat: change receive label
JoaquinBattilana Aug 16, 2023
a096d58
fix: only set max selected if the underlying balance equals max amount
grothem Aug 16, 2023
d37c037
fix: show gho at top of list
grothem Aug 16, 2023
f3ec02d
Merge branch 'main' into feat/withdraw-swap-ui
MareskoY Aug 17, 2023
af5ad90
refactor: pulled out shared logic in withdraw modals (#1745)
grothem Aug 21, 2023
b8c4ff8
feat: added refetch to success withdraw and swap
JoaquinBattilana Aug 21, 2023
8e288a7
feat: added custom success screen and actions
JoaquinBattilana Aug 21, 2023
c9397cd
feat: fork config
grothem Aug 21, 2023
c9dfc91
fix: set max when fetching paraswap route data
grothem Aug 21, 2023
352ad59
fix: clear type selection on modal close
grothem Aug 21, 2023
36b65e5
feat: changed swap to switch
JoaquinBattilana Aug 22, 2023
f08c96e
feat: utils bump
grothem Aug 22, 2023
14d6821
Merge branch 'main' into feat/withdraw-swap-ui
grothem Aug 24, 2023
2040ab7
feat: updated addresses
grothem Aug 24, 2023
4bc70cd
fix: updated adapter config name
grothem Aug 25, 2023
d2fbf76
chore: merged with main
JoaquinBattilana Aug 30, 2023
e9d6258
feat: ui fixes
JoaquinBattilana Aug 30, 2023
34b4b9b
fix: added dependencies to useMemo on withdraw and swap modal
JoaquinBattilana Aug 30, 2023
95d0847
feat: track tx errors
grothem Aug 30, 2023
402b3d5
Merge branch 'main' into feat/withdraw-swap-ui
grothem Aug 30, 2023
b1c19c1
fix: use variable debt for dai switch test
grothem Aug 30, 2023
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"test:coverage": "jest --coverage"
},
"dependencies": {
"@aave/contract-helpers": "1.18.3",
"@aave/math-utils": "1.18.3",
"@aave/contract-helpers": "1.20.0",
"@aave/math-utils": "1.20.0",
"@bgd-labs/aave-address-book": "^1.33.0",
"@emotion/cache": "11.10.3",
"@emotion/react": "11.10.4",
Expand Down
3 changes: 3 additions & 0 deletions src/components/TransactionEventHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export const TransactionEventHandler = () => {
support: tx.support,
previousState: tx.previousState,
newState: tx.newState,
outAsset: tx.outAsset,
outAmount: tx.outAmount,
outAssetName: tx.outAssetName,
});

// update local state
Expand Down
91 changes: 91 additions & 0 deletions src/components/transactions/FlowCommons/BaseSuccess.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { ExternalLinkIcon } from '@heroicons/react/outline';
import { CheckIcon } from '@heroicons/react/solid';
import { Trans } from '@lingui/macro';
import { Box, Button, Link, SvgIcon, Typography } from '@mui/material';
import { ReactNode } from 'react';
import { useModalContext } from 'src/hooks/useModal';
import { useProtocolDataContext } from 'src/hooks/useProtocolDataContext';

export type BaseSuccessTxViewProps = {
txHash?: string;
children: ReactNode;
};

const ExtLinkIcon = () => (
<SvgIcon sx={{ ml: '2px', fontSize: '11px' }}>
<ExternalLinkIcon />
</SvgIcon>
);

export const BaseSuccessView = ({ txHash, children }: BaseSuccessTxViewProps) => {
const { close, mainTxState } = useModalContext();
const { currentNetworkConfig } = useProtocolDataContext();

return (
<>
<Box
sx={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Box
sx={{
width: '48px',
height: '48px',
bgcolor: 'success.200',
borderRadius: '50%',
mt: 14,
mx: 'auto',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<SvgIcon sx={{ color: 'success.main', fontSize: '32px' }}>
<CheckIcon />
</SvgIcon>
</Box>

<Typography sx={{ mt: 4 }} variant="h2">
<Trans>All done!</Trans>
</Typography>

{children}
</Box>

<Box sx={{ display: 'flex', flexDirection: 'column' }}>
<Link
variant="helperText"
href={currentNetworkConfig.explorerLinkBuilder({
tx: txHash ? txHash : mainTxState.txHash,
})}
sx={{
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'right',
mt: 6,
mb: 3,
}}
underline="hover"
target="_blank"
rel="noreferrer noopener"
>
<Trans>Review tx details</Trans>
<ExtLinkIcon />
</Link>
<Button
onClick={close}
variant="contained"
size="large"
sx={{ minHeight: '44px' }}
data-cy="closeButton"
>
<Trans>Ok, Close</Trans>
</Button>
</Box>
</>
);
};
233 changes: 80 additions & 153 deletions src/components/transactions/FlowCommons/Success.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { InterestRate } from '@aave/contract-helpers';
import { ExternalLinkIcon } from '@heroicons/react/outline';
import { CheckIcon } from '@heroicons/react/solid';
import { Trans } from '@lingui/macro';
import { Box, Button, Link, SvgIcon, Typography, useTheme } from '@mui/material';
import { Box, Button, Typography, useTheme } from '@mui/material';
import { ReactNode, useState } from 'react';
import { WalletIcon } from 'src/components/icons/WalletIcon';
import { FormattedNumber } from 'src/components/primitives/FormattedNumber';
import { Base64Token, TokenIcon } from 'src/components/primitives/TokenIcon';
import { useModalContext } from 'src/hooks/useModal';
import { useProtocolDataContext } from 'src/hooks/useProtocolDataContext';
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
import { ERC20TokenType } from 'src/libs/web3-data-provider/Web3Provider';

import { BaseSuccessView } from './BaseSuccess';

export type SuccessTxViewProps = {
txHash?: string;
action?: ReactNode;
Expand All @@ -24,12 +22,6 @@ export type SuccessTxViewProps = {
customText?: ReactNode;
};

const ExtLinkIcon = () => (
<SvgIcon sx={{ ml: '2px', fontSize: '11px' }}>
<ExternalLinkIcon />
</SvgIcon>
);

export const TxSuccessView = ({
txHash,
action,
Expand All @@ -41,169 +33,104 @@ export const TxSuccessView = ({
customAction,
customText,
}: SuccessTxViewProps) => {
const { close, mainTxState } = useModalContext();
const { addERC20Token } = useWeb3Context();
const { currentNetworkConfig } = useProtocolDataContext();
const [base64, setBase64] = useState('');
const theme = useTheme();

return (
<>
<BaseSuccessView txHash={txHash}>
<Box
sx={{
mt: 2,
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
justifyContent: 'center',
textAlign: 'center',
}}
>
<Box
sx={{
width: '48px',
height: '48px',
bgcolor: 'success.200',
borderRadius: '50%',
mt: 14,
mx: 'auto',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<SvgIcon sx={{ color: 'success.main', fontSize: '32px' }}>
<CheckIcon />
</SvgIcon>
</Box>
{action && amount && symbol && (
<Typography>
<Trans>
You {action} <FormattedNumber value={Number(amount)} compact variant="secondary14" />{' '}
{symbol}
</Trans>
</Typography>
)}

<Typography sx={{ mt: 4 }} variant="h2">
<Trans>All done!</Trans>
</Typography>
{customAction && (
<Typography>
{customText}
{customAction}
</Typography>
)}

<Box
sx={{
mt: 2,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
textAlign: 'center',
}}
>
{action && amount && symbol && (
<Typography>
<Trans>
You {action}{' '}
<FormattedNumber value={Number(amount)} compact variant="secondary14" /> {symbol}
</Trans>
</Typography>
)}
{!action && !amount && symbol && (
<Typography>
Your {symbol} {collateral ? 'now' : 'is not'} used as collateral
</Typography>
)}

{customAction && (
<Typography>
{customText}
{customAction}
</Typography>
)}

{!action && !amount && symbol && (
<Typography>
Your {symbol} {collateral ? 'now' : 'is not'} used as collateral
</Typography>
)}
{rate && (
<Typography>
<Trans>
You switched to {rate === InterestRate.Variable ? 'variable' : 'stable'} rate
</Trans>
</Typography>
)}

{rate && (
<Typography>
{addToken && symbol && (
<Box
sx={(theme) => ({
border: theme.palette.mode === 'dark' ? `1px solid ${theme.palette.divider}` : 'none',
background: theme.palette.mode === 'dark' ? 'none' : '#F7F7F9',
borderRadius: '12px',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
mt: '24px',
})}
>
<TokenIcon
symbol={addToken.symbol}
aToken={addToken && addToken.aToken ? true : false}
sx={{ fontSize: '32px', mt: '12px', mb: '8px' }}
/>
<Typography variant="description" color="text.primary" sx={{ mx: '24px' }}>
<Trans>
You switched to {rate === InterestRate.Variable ? 'variable' : 'stable'} rate
Add {addToken && addToken.aToken ? 'aToken ' : 'token '} to wallet to track your
balance.
</Trans>
</Typography>
)}

{addToken && symbol && (
<Box
sx={(theme) => ({
border:
theme.palette.mode === 'dark' ? `1px solid ${theme.palette.divider}` : 'none',
background: theme.palette.mode === 'dark' ? 'none' : '#F7F7F9',
borderRadius: '12px',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
mt: '24px',
})}
<Button
onClick={() => {
addERC20Token({
address: addToken.address,
decimals: addToken.decimals,
symbol: addToken.aToken ? `a${addToken.symbol}` : addToken.symbol,
image: !/_/.test(addToken.symbol) ? base64 : undefined,
});
}}
variant={theme.palette.mode === 'dark' ? 'outlined' : 'contained'}
size="medium"
sx={{ mt: '8px', mb: '12px' }}
>
<TokenIcon
symbol={addToken.symbol}
aToken={addToken && addToken.aToken ? true : false}
sx={{ fontSize: '32px', mt: '12px', mb: '8px' }}
/>
<Typography variant="description" color="text.primary" sx={{ mx: '24px' }}>
<Trans>
Add {addToken && addToken.aToken ? 'aToken ' : 'token '} to wallet to track your
balance.
</Trans>
{addToken.symbol && !/_/.test(addToken.symbol) && (
<Base64Token
symbol={addToken.symbol}
onImageGenerated={setBase64}
aToken={addToken.aToken}
/>
)}
<WalletIcon sx={{ width: '20px', height: '20px' }} />
<Typography variant="buttonM" color="white" ml="4px">
<Trans>Add to wallet</Trans>
</Typography>
<Button
onClick={() => {
addERC20Token({
address: addToken.address,
decimals: addToken.decimals,
symbol: addToken.aToken ? `a${addToken.symbol}` : addToken.symbol,
image: !/_/.test(addToken.symbol) ? base64 : undefined,
});
}}
variant={theme.palette.mode === 'dark' ? 'outlined' : 'contained'}
size="medium"
sx={{ mt: '8px', mb: '12px' }}
>
{addToken.symbol && !/_/.test(addToken.symbol) && (
<Base64Token
symbol={addToken.symbol}
onImageGenerated={setBase64}
aToken={addToken.aToken}
/>
)}
<WalletIcon sx={{ width: '20px', height: '20px' }} />
<Typography variant="buttonM" color="white" ml="4px">
<Trans>Add to wallet</Trans>
</Typography>
</Button>
</Box>
)}
</Box>
</Box>

<Box sx={{ display: 'flex', flexDirection: 'column' }}>
<Link
variant="helperText"
href={currentNetworkConfig.explorerLinkBuilder({
tx: txHash ? txHash : mainTxState.txHash,
})}
sx={{
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'right',
mt: 6,
mb: 3,
}}
underline="hover"
target="_blank"
rel="noreferrer noopener"
>
<Trans>Review tx details</Trans>
<ExtLinkIcon />
</Link>
<Button
onClick={close}
variant="contained"
size="large"
sx={{ minHeight: '44px' }}
data-cy="closeButton"
>
<Trans>Ok, Close</Trans>
</Button>
</Button>
</Box>
)}
</Box>
</>
</BaseSuccessView>
);
};
Loading
Loading