-
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.
- Loading branch information
Showing
13 changed files
with
268 additions
and
134 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
43 changes: 43 additions & 0 deletions
43
packages/widget/src/components/StepActions/StepActions.style.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,43 @@ | ||
import { | ||
StepConnector as MuiStepConnector, | ||
StepContent as MuiStepContent, | ||
StepLabel as MuiStepLabel, | ||
} from '@mui/material'; | ||
import { stepConnectorClasses } from '@mui/material/StepConnector'; | ||
import { stepContentClasses } from '@mui/material/StepContent'; | ||
import { stepLabelClasses } from '@mui/material/StepLabel'; | ||
import { styled } from '@mui/material/styles'; | ||
|
||
export const StepIcon = styled('span')(({ theme }) => ({ | ||
width: 12, | ||
height: 12, | ||
borderRadius: '50%', | ||
border: `2px solid ${theme.palette.grey[300]}`, | ||
})); | ||
|
||
export const StepConnector = styled(MuiStepConnector)(({ theme }) => ({ | ||
marginLeft: theme.spacing(1.875), | ||
[`.${stepConnectorClasses.line}`]: { | ||
minHeight: 8, | ||
borderLeftWidth: 2, | ||
borderColor: theme.palette.grey[300], | ||
}, | ||
})); | ||
|
||
export const StepLabel = styled(MuiStepLabel)(({ theme }) => ({ | ||
padding: 0, | ||
[`.${stepLabelClasses.iconContainer}`]: { | ||
paddingLeft: theme.spacing(1), | ||
paddingRight: theme.spacing(3), | ||
}, | ||
})); | ||
|
||
export const StepContent = styled(MuiStepContent)(({ theme }) => ({ | ||
borderLeft: `2px solid ${theme.palette.grey[300]}`, | ||
marginLeft: theme.spacing(1.875), | ||
paddingLeft: theme.spacing(3.9375), | ||
[`&.${stepContentClasses.last}`]: { | ||
borderLeft: 'none', | ||
paddingLeft: theme.spacing(4.1875), | ||
}, | ||
})); |
150 changes: 150 additions & 0 deletions
150
packages/widget/src/components/StepActions/StepActions.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,150 @@ | ||
import { LifiStep, Step } from '@lifinance/sdk'; | ||
import { ArrowForward as ArrowForwardIcon } from '@mui/icons-material'; | ||
import { | ||
Avatar, | ||
Box, | ||
Step as MuiStep, | ||
Stepper, | ||
Typography, | ||
TypographyProps, | ||
} from '@mui/material'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useChains } from '../../hooks'; | ||
import LiFiLogo from '../../icons/LiFiLogo.svg'; | ||
import { formatTokenAmount } from '../../utils/format'; | ||
import { | ||
StepConnector, | ||
StepContent, | ||
StepIcon, | ||
StepLabel, | ||
} from './StepActions.style'; | ||
import { StepActionsProps } from './types'; | ||
|
||
export const StepActions: React.FC<StepActionsProps> = ({ | ||
step, | ||
dense, | ||
...other | ||
}) => { | ||
const StepDetailsLabel = | ||
step.type === 'cross' || step.type === 'lifi' | ||
? CrossStepDetailsLabel | ||
: SwapStepDetailsLabel; | ||
const isFullView = !dense && (step as LifiStep).includedSteps?.length; | ||
return ( | ||
<Box {...other}> | ||
<Box | ||
sx={{ display: 'flex', alignItems: 'center' }} | ||
mb={isFullView ? 1 : 0} | ||
> | ||
<Avatar | ||
variant={step.type === 'lifi' ? 'square' : 'circular'} | ||
src={step.type === 'lifi' ? LiFiLogo : step.toolDetails.logoURI} | ||
alt={step.toolDetails.name} | ||
> | ||
{step.toolDetails.name[0]} | ||
</Avatar> | ||
<Typography | ||
ml={2} | ||
fontSize={18} | ||
fontWeight="500" | ||
textTransform="capitalize" | ||
> | ||
{step.type === 'lifi' | ||
? 'LI.FI Smart Contract' | ||
: step.toolDetails.name} | ||
</Typography> | ||
</Box> | ||
{isFullView ? ( | ||
<Stepper | ||
orientation="vertical" | ||
connector={<StepConnector />} | ||
activeStep={-1} | ||
> | ||
{(step as LifiStep).includedSteps.map((step) => ( | ||
<MuiStep key={step.id} expanded> | ||
<StepLabel StepIconComponent={StepIcon}> | ||
<StepDetailsLabel step={step} /> | ||
</StepLabel> | ||
<StepContent> | ||
<StepDetailsContent step={step} /> | ||
</StepContent> | ||
</MuiStep> | ||
))} | ||
</Stepper> | ||
) : ( | ||
<> | ||
<StepDetailsLabel ml={6} step={step} /> | ||
<StepDetailsContent ml={6} step={step} /> | ||
</> | ||
)} | ||
</Box> | ||
); | ||
}; | ||
|
||
export const StepDetailsContent: React.FC<{ step: Step } & TypographyProps> = ({ | ||
step, | ||
...other | ||
}) => { | ||
return ( | ||
<Typography | ||
fontSize={12} | ||
fontWeight="500" | ||
color="text.secondary" | ||
alignItems="center" | ||
display="flex" | ||
{...other} | ||
> | ||
{formatTokenAmount( | ||
step.estimate.fromAmount, | ||
step.action.fromToken.decimals, | ||
)}{' '} | ||
{step.action.fromToken.symbol} | ||
<ArrowForwardIcon sx={{ fontSize: '.75rem', paddingX: 0.5 }} /> | ||
{formatTokenAmount( | ||
step.estimate.toAmount, | ||
step.action.toToken.decimals, | ||
)}{' '} | ||
{step.action.toToken.symbol} | ||
</Typography> | ||
); | ||
}; | ||
|
||
export const CrossStepDetailsLabel: React.FC< | ||
{ step: Step } & TypographyProps | ||
> = ({ step, ...other }) => { | ||
const { t } = useTranslation(); | ||
const { getChainById } = useChains(); | ||
|
||
return ( | ||
<Typography | ||
fontSize={12} | ||
fontWeight="500" | ||
color="text.secondary" | ||
{...other} | ||
> | ||
{t('swapping.crossStepDetails', { | ||
from: getChainById(step.action.fromChainId)?.name, | ||
to: getChainById(step.action.toChainId)?.name, | ||
tool: step.toolDetails.name, | ||
})} | ||
</Typography> | ||
); | ||
}; | ||
|
||
export const SwapStepDetailsLabel: React.FC< | ||
{ step: Step } & TypographyProps | ||
> = ({ step, ...other }) => { | ||
const { t } = useTranslation(); | ||
return ( | ||
<Typography | ||
fontSize={12} | ||
fontWeight="500" | ||
color="text.secondary" | ||
{...other} | ||
> | ||
{t('swapping.swapStepDetails', { | ||
value: step.toolDetails.name, | ||
})} | ||
</Typography> | ||
); | ||
}; |
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 @@ | ||
export { StepActions } from './StepActions'; |
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,7 @@ | ||
import { Step } from '@lifinance/sdk'; | ||
import { BoxProps } from '@mui/material'; | ||
|
||
export interface StepActionsProps extends BoxProps { | ||
step: Step; | ||
dense?: boolean; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { Route } from '@lifinance/sdk'; | ||
|
||
export interface SwapRouteCardProps { | ||
amount: string | number; | ||
token: string; | ||
time: string; | ||
gas: string; | ||
type: 'recommended' | 'fastest' | 'cheapest'; | ||
route: Route; | ||
index: number; | ||
dense?: boolean; | ||
active?: boolean; | ||
blur?: boolean; | ||
} |
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
Oops, something went wrong.