-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add no routes available message
- Loading branch information
Showing
8 changed files
with
204 additions
and
74 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
64 changes: 64 additions & 0 deletions
64
packages/widget/src/components/SwapRouteCard/SwapRouteCardSkeleton.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,64 @@ | ||
import { Box, BoxProps, Skeleton } from '@mui/material'; | ||
import { Card } from './SwapRouteCard.style'; | ||
import { SwapRouteCardSkeletonProps } from './types'; | ||
|
||
export const SwapRouteCardSkeleton: React.FC< | ||
SwapRouteCardSkeletonProps & BoxProps | ||
> = ({ active, dense, ...other }) => { | ||
return ( | ||
<Card dense={dense} {...other}> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
}} | ||
> | ||
<Skeleton | ||
variant="rectangular" | ||
width={120} | ||
height={24} | ||
sx={{ borderRadius: 0.5 }} | ||
/> | ||
{active ? <Skeleton variant="circular" width={24} height={24} /> : null} | ||
</Box> | ||
<Box my={2}> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<Box mr={2}> | ||
<Skeleton variant="circular" width={32} height={32} /> | ||
</Box> | ||
<Skeleton variant="text" width={96} height={32} /> | ||
</Box> | ||
<Box ml={6}> | ||
<Skeleton variant="text" width={56} height={22} /> | ||
</Box> | ||
</Box> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
}} | ||
> | ||
<Box> | ||
<Skeleton variant="text" width={56} height={22} /> | ||
<Skeleton variant="text" width={52} height={15} /> | ||
</Box> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
alignItems: 'flex-end', | ||
flexDirection: 'column', | ||
}} | ||
> | ||
<Skeleton variant="text" width={40} height={22} /> | ||
<Skeleton variant="text" width={48} height={15} /> | ||
</Box> | ||
</Box> | ||
</Card> | ||
); | ||
}; |
38 changes: 38 additions & 0 deletions
38
packages/widget/src/components/SwapRouteCard/SwapRouteNotFoundCard.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,38 @@ | ||
import { Route as RouteIcon } from '@mui/icons-material'; | ||
import { Box, BoxProps, Typography } from '@mui/material'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Card } from './SwapRouteCard.style'; | ||
import { SwapRouteCardSkeletonProps } from './types'; | ||
|
||
export const SwapRouteNotFoundCard: React.FC< | ||
SwapRouteCardSkeletonProps & BoxProps | ||
> = ({ active, dense, ...other }) => { | ||
const { t } = useTranslation(); | ||
return ( | ||
<Card active={active} dense={dense} {...other}> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
flexDirection: 'column', | ||
flex: 1, | ||
}} | ||
py={1.375} | ||
> | ||
<RouteIcon fontSize="large" /> | ||
<Typography fontSize={16} fontWeight="500" mt={2}> | ||
{t('swap.info.title.routeNotFound')} | ||
</Typography> | ||
<Typography | ||
fontSize={14} | ||
color="text.secondary" | ||
textAlign="center" | ||
mt={1} | ||
> | ||
{t('swap.info.message.routeNotFound')} | ||
</Typography> | ||
</Box> | ||
</Card> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from './SwapRouteCard'; | ||
export * from './SwapRouteCardSkeleton'; | ||
export * from './SwapRouteNotFoundCard'; |
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
67 changes: 38 additions & 29 deletions
67
packages/widget/src/pages/SwapRoutesPage/SwapRoutesPage.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 |
---|---|---|
@@ -1,53 +1,62 @@ | ||
/* eslint-disable react/no-array-index-key */ | ||
import { Route } from '@lifi/sdk'; | ||
import { BoxProps, Skeleton } from '@mui/material'; | ||
import { BoxProps } from '@mui/material'; | ||
import { useEffect } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { SwapRouteCard } from '../../components/SwapRouteCard'; | ||
import { | ||
SwapRouteCard, | ||
SwapRouteCardSkeleton, | ||
SwapRouteNotFoundCard, | ||
} from '../../components/SwapRouteCard'; | ||
import { useSwapRoutes } from '../../hooks'; | ||
import { useCurrentRoute, useSetExecutableRoute } from '../../stores'; | ||
import { routes } from '../../utils/routes'; | ||
import { Stack } from './SwapRoutesPage.style'; | ||
|
||
export const SwapRoutesPage: React.FC<BoxProps> = () => { | ||
const navigate = useNavigate(); | ||
const { routes: swapRoutes, isLoading, isFetching } = useSwapRoutes(); | ||
const { | ||
routes: swapRoutes, | ||
isLoading, | ||
isFetching, | ||
isFetched, | ||
} = useSwapRoutes(); | ||
const [currentRoute] = useCurrentRoute(); | ||
const setExecutableRoute = useSetExecutableRoute(); | ||
|
||
if (!swapRoutes?.length && !isLoading && !isFetching) { | ||
// TODO: make no routes message | ||
return null; | ||
} | ||
|
||
const handleRouteClick = (route: Route) => { | ||
setExecutableRoute(route); | ||
navigate(routes.swap, { state: { routeId: route.id }, replace: true }); | ||
}; | ||
|
||
// A route for this transaction does not exist yet possibly due to liquidity issues or because the amount of tokens you are sending is below the bridge minimum amount. | ||
// Please try again later or change the tokens you intend to swap. | ||
// If the problem persists, come to our Discord and leave a message in the support channel. | ||
useEffect(() => { | ||
if (!swapRoutes?.length && !isLoading && !isFetching) { | ||
navigate(routes.home); | ||
} | ||
// redirect to the home page if no routes are found on page reload | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
const routeNotFound = !swapRoutes?.length && isFetched; | ||
|
||
return ( | ||
<Stack direction="column" spacing={2}> | ||
{isLoading || isFetching | ||
? Array.from({ length: 3 }).map((_, index) => ( | ||
<Skeleton | ||
key={index} | ||
variant="rectangular" | ||
width="100%" | ||
height={196} | ||
sx={{ borderRadius: 1 }} | ||
/> | ||
)) | ||
: swapRoutes?.map((route, index) => ( | ||
<SwapRouteCard | ||
key={route.id} | ||
route={route} | ||
active={currentRoute?.id === route.id} | ||
onClick={() => handleRouteClick(route)} | ||
/> | ||
))} | ||
{routeNotFound ? ( | ||
<SwapRouteNotFoundCard minWidth="100%" dense /> | ||
) : isLoading || isFetching ? ( | ||
Array.from({ length: 3 }).map((_, index) => ( | ||
<SwapRouteCardSkeleton key={index} minWidth="100%" dense /> | ||
)) | ||
) : ( | ||
swapRoutes?.map((route, index) => ( | ||
<SwapRouteCard | ||
key={route.id} | ||
route={route} | ||
active={currentRoute?.id === route.id} | ||
onClick={() => handleRouteClick(route)} | ||
/> | ||
)) | ||
)} | ||
</Stack> | ||
); | ||
}; |