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

[TAS-234] feat: swap state #41

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion libs/oeth/swap/src/actions/swapCurve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const allowance: Allowance = async ({ tokenIn, tokenOut, curve }) => {
return 0n;
}

if (isNilOrEmpty(tokenIn.address) || isNilOrEmpty(tokenOut.address)) {
if (isNilOrEmpty(tokenIn.address)) {
return maxUint256;
}

Expand Down
38 changes: 19 additions & 19 deletions libs/oeth/swap/src/components/BestRoutes.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { Box } from '@mui/material';
import Grid2 from '@mui/material/Unstable_Grid2/Grid2';

import { useHandleSelectSwapRoute } from '../hooks';
import { useSwapState } from '../state';
import { routeEq } from '../utils';
import { SwapRouteCard } from './SwapRouteCard';

import type { BoxProps } from '@mui/material';
import type { Grid2Props } from '@mui/material';

export function BestRoutes(props: BoxProps) {
const [{ swapRoutes, selectedSwapRoute }] = useSwapState();
export type BestRoutesProps = { isLoading: boolean } & Grid2Props;

export function BestRoutes(props: Grid2Props) {
const [{ swapRoutes, selectedSwapRoute, isSwapRoutesLoading }] =
useSwapState();
const handleSelectSwapRoute = useHandleSelectSwapRoute();

return (
<Box
sx={{
gridTemplateColumns: 'repeat(2, 1fr)',
gap: 1,
display: 'grid',
}}
>
<Grid2 spacing={1} {...props} container>
{swapRoutes.slice(0, 2).map((route, index) => (
<SwapRouteCard
key={`bestRoute-${index}`}
isSelected={routeEq(selectedSwapRoute, route)}
isBest={index === 0}
onSelect={handleSelectSwapRoute}
route={route}
/>
<Grid2 key={route.action} xs={6}>
<SwapRouteCard
key={`bestRoute-${index}`}
isSelected={routeEq(selectedSwapRoute, route)}
isBest={index === 0}
onSelect={handleSelectSwapRoute}
route={route}
isLoading={isSwapRoutesLoading}
/>
</Grid2>
))}
</Box>
</Grid2>
);
}
60 changes: 16 additions & 44 deletions libs/oeth/swap/src/components/SwapRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Skeleton, Stack, Typography } from '@mui/material';
import { Collapse, Skeleton, Stack, Typography } from '@mui/material';
import { Card, cardStyles } from '@origin/shared/components';
import { useIntl } from 'react-intl';

Expand All @@ -9,31 +9,6 @@ import { SwapRouteAccordion } from './SwapRouteAccordion';

import type { CardProps } from '@mui/material';

import type { EstimatedSwapRoute } from '../types';

interface Swap {
type: 'swap';
}
export interface Redeem {
type: 'redeem';
tokenAbbreviation: string;
waitTime: string;
}

export type Route = {
name: string;
icon: string | string[];
quantity: number;
value: number;
rate: number;
transactionCost: number;
} & (Swap | Redeem);

export type SwapRouteProps = {
isLoading: boolean;
routes: EstimatedSwapRoute[];
};

export function SwapRoute(props: Omit<CardProps, 'children'>) {
const intl = useIntl();
const [{ swapRoutes, isSwapRoutesLoading }] = useSwapState();
Expand All @@ -52,27 +27,26 @@ export function SwapRoute(props: Omit<CardProps, 'children'>) {
}}
title={
isSwapRoutesLoading ? (
<Typography
color="primary.contrastText"
sx={{
fontSize: (theme) => theme.typography.pxToRem(12),
display: 'flex',
alignItems: 'center',
}}
<Stack
direction="row"
alignItems="center"
gap={1}
sx={(theme) => ({ color: theme.palette.primary.contrastText })}
>
<Skeleton
variant="circular"
width="0.5rem"
height="0.5rem"
sx={{
mr: 1.5,
backgroundColor: (theme) => theme.palette.primary.contrastText,
}}
/>
{intl.formatMessage({
defaultMessage: 'Finding the best route...',
})}
</Typography>
<Typography variant="body2">
{intl.formatMessage({
defaultMessage: 'Finding the best route...',
})}
</Typography>
</Stack>
) : (
<Stack
direction="row"
Expand All @@ -99,12 +73,10 @@ export function SwapRoute(props: Omit<CardProps, 'children'>) {
}),
}}
>
{hasContent ? (
<>
<BestRoutes />
<SwapRouteAccordion sx={{ mt: 2 }} />
</>
) : undefined}
<Collapse in={hasContent}>
<BestRoutes />
{swapRoutes.length > 2 && <SwapRouteAccordion sx={{ mt: 2 }} />}
</Collapse>
</Card>
);
}
Loading