-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add active swaps page and live updates
- Loading branch information
Showing
24 changed files
with
355 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
packages/widget/src/components/ActiveSwaps/ActiveSwapItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { | ||
ArrowForward as ArrowForwardIcon, | ||
Info as InfoIcon, | ||
Warning as WarningIcon | ||
} from '@mui/icons-material'; | ||
import { Box, ListItemAvatar, ListItemText, Typography } from '@mui/material'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useProcessMessage, useRouteExecution } from '../../hooks'; | ||
import { navigationRoutes } from '../../utils'; | ||
import { StepTimer } from '../Step/StepTimer'; | ||
import { TokenAvatar, TokenAvatarGroup } from '../TokenAvatar'; | ||
import { ListItem, ListItemButton } from './ActiveSwaps.style'; | ||
|
||
export const ActiveSwapItem: React.FC<{ | ||
routeId: string; | ||
dense?: boolean; | ||
}> = ({ routeId, dense }) => { | ||
const { t } = useTranslation(); | ||
const navigate = useNavigate(); | ||
const { route, status } = useRouteExecution(routeId); | ||
|
||
// TODO: replace with ES2023 findLast | ||
const lastActiveStep = route?.steps | ||
.slice() | ||
.reverse() | ||
.find((step) => step.execution); | ||
const lastActiveProcess = lastActiveStep?.execution?.process.at(-1); | ||
|
||
const { title } = useProcessMessage(lastActiveStep, lastActiveProcess); | ||
|
||
if (!route || !lastActiveStep) { | ||
return null; | ||
} | ||
|
||
const handleClick = () => { | ||
navigate(navigationRoutes.swapExecution, { state: { routeId } }); | ||
}; | ||
|
||
const getStatusComponent = () => { | ||
switch (lastActiveProcess?.status) { | ||
case 'ACTION_REQUIRED': | ||
return <InfoIcon color="info" fontSize="small" />; | ||
case 'FAILED': | ||
return <WarningIcon color="error" fontSize="small" />; | ||
default: | ||
return ( | ||
<Typography fontSize={14} fontWeight={500}> | ||
<StepTimer step={lastActiveStep} hideInProgress /> | ||
</Typography> | ||
); | ||
} | ||
}; | ||
|
||
const ListItemWrapper = dense ? ListItem : ListItemButton; | ||
|
||
return ( | ||
<ListItemWrapper | ||
onClick={handleClick} | ||
dense | ||
disableRipple | ||
> | ||
<ListItemAvatar> | ||
<TokenAvatarGroup total={2}> | ||
<TokenAvatar token={route.fromToken} /> | ||
<TokenAvatar token={route.toToken} /> | ||
</TokenAvatarGroup> | ||
</ListItemAvatar> | ||
<ListItemText | ||
sx={{ margin: 0 }} | ||
disableTypography | ||
primary={ | ||
<Typography fontWeight={500} lineHeight={1}> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
marginLeft: 2, | ||
height: 16, | ||
}} | ||
> | ||
{route.fromToken.symbol} | ||
<ArrowForwardIcon sx={{ paddingX: 0.5 }} /> | ||
{route.toToken.symbol} | ||
</Box> | ||
</Typography> | ||
} | ||
secondary={ | ||
status !== 'success' ? ( | ||
<Typography | ||
fontWeight={400} | ||
fontSize={12} | ||
color="text.secondary" | ||
lineHeight={1} | ||
mt={0.75} | ||
ml={2} | ||
> | ||
{title} | ||
</Typography> | ||
) : null | ||
} | ||
/> | ||
{getStatusComponent()} | ||
</ListItemWrapper> | ||
); | ||
}; |
43 changes: 43 additions & 0 deletions
43
packages/widget/src/components/ActiveSwaps/ActiveSwaps.style.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { | ||
Button, | ||
ListItem as MuiListItem, | ||
ListItemButton as MuiListItemButton | ||
} from '@mui/material'; | ||
import { listItemSecondaryActionClasses } from '@mui/material/ListItemSecondaryAction'; | ||
import { alpha, styled } from '@mui/material/styles'; | ||
import { getContrastAlphaColor } from '../../utils'; | ||
import { Card } from '../Card'; | ||
|
||
export const ProgressCard = styled(Card)(({ theme }) => ({ | ||
borderColor: alpha(theme.palette.secondary.main, 0.48), | ||
background: alpha(theme.palette.secondary.main, 0.08), | ||
'&:hover': { | ||
background: alpha(theme.palette.secondary.main, 0.08), | ||
}, | ||
})); | ||
|
||
export const ListItemButton = styled(MuiListItemButton)(({ theme }) => ({ | ||
borderRadius: theme.shape.borderRadiusSecondary, | ||
paddingLeft: theme.spacing(1), | ||
paddingRight: theme.spacing(1), | ||
height: 64, | ||
'&:hover': { | ||
backgroundColor: getContrastAlphaColor(theme, '4%'), | ||
}, | ||
})); | ||
|
||
export const ListItem = styled(MuiListItem)(({ theme }) => ({ | ||
padding: theme.spacing(0, 1.5), | ||
[`.${listItemSecondaryActionClasses.root}`]: { | ||
right: theme.spacing(3), | ||
}, | ||
'&:hover': { | ||
cursor: 'pointer', | ||
}, | ||
})); | ||
|
||
export const ShowAllButton = styled(Button)(({ theme }) => ({ | ||
'&:hover': { | ||
background: 'none', | ||
}, | ||
})); |
50 changes: 50 additions & 0 deletions
50
packages/widget/src/components/ActiveSwaps/ActiveSwaps.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { BoxProps } from '@mui/material'; | ||
import { Stack } from '@mui/material'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useWallet } from '../../providers'; | ||
import { useExecutingRoutesIds } from '../../stores'; | ||
import { navigationRoutes } from '../../utils'; | ||
import { CardTitle } from '../Card'; | ||
import { ActiveSwapItem } from './ActiveSwapItem'; | ||
import { ProgressCard, ShowAllButton } from './ActiveSwaps.style'; | ||
|
||
export const ActiveSwaps: React.FC<BoxProps> = (props) => { | ||
const { t } = useTranslation(); | ||
const navigate = useNavigate(); | ||
const { account } = useWallet(); | ||
const executingRoutes = useExecutingRoutesIds(account.address); | ||
|
||
if (!executingRoutes?.length) { | ||
return null; | ||
} | ||
|
||
const handleShowAll = () => { | ||
navigate(navigationRoutes.activeSwaps); | ||
}; | ||
|
||
const hasShowAll = executingRoutes?.length > 2; | ||
|
||
return ( | ||
<ProgressCard {...props}> | ||
<CardTitle>{t('header.activeSwaps')}</CardTitle> | ||
<Stack spacing={1.5} pt={1.5} pb={hasShowAll ? 0 : 2}> | ||
{executingRoutes.slice(0, 2).map((routeId) => ( | ||
<ActiveSwapItem key={routeId} routeId={routeId} dense /> | ||
))} | ||
</Stack> | ||
{hasShowAll ? ( | ||
<ShowAllButton | ||
disableRipple | ||
fullWidth | ||
onClick={handleShowAll} | ||
sx={(theme) => ({ | ||
padding: theme.spacing(0.75, 2), | ||
})} | ||
> | ||
{t('button.showAll')} | ||
</ShowAllButton> | ||
) : null} | ||
</ProgressCard> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './ActiveSwapItem'; | ||
export * from './ActiveSwaps'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
packages/widget/src/components/SwapsInProgress/SwapsInProgress.style.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.