Skip to content

Commit

Permalink
feat: for long routes, we should show a shorter version and hide the …
Browse files Browse the repository at this point in the history
…rest in a button.
  • Loading branch information
mikasackermn authored and Ikari-Shinji-re committed Jan 17, 2024
1 parent 9e61b84 commit 378b3e4
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"eslint.validate": [
"javascript",
Expand Down
47 changes: 43 additions & 4 deletions widget/embedded/src/components/Quote/Quote.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ export const summaryStyles = css({
cursor: 'default',
});

export const rowStyles = css({
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
'.blockchainImage': {
marginLeft: '-$8',
},
});
export const basicInfoStyles = css({
paddingTop: '$10',
display: 'flex',
Expand All @@ -127,7 +136,7 @@ export const basicInfoStyles = css({
},
});

export const Chains = styled(Collapsible.Trigger, {
export const Trigger = styled(Collapsible.Trigger, {
display: 'flex',
width: '100%',
justifyContent: 'space-between',
Expand Down Expand Up @@ -171,17 +180,27 @@ export const Chains = styled(Collapsible.Trigger, {
},
},
},
'& div:nth-child(1)': { display: 'flex' },
'.blockchains_section': {
display: 'none',
},
'@xs': {
'.blockchains_section': {
display: 'block',
},
},
});

export const ChainImageContainer = styled('div', {
export const ImageContainer = styled('div', {
width: '18px',
height: '18px',
borderRadius: '100%',
border: '1.5px transparent solid',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
border: '1.5px transparent solid',
img: {
borderRadius: '100%',
},
variants: {
state: {
error: {
Expand Down Expand Up @@ -252,3 +271,23 @@ export const ContainerInfoOutput = styled('div', {
display: 'flex',
flexWrap: 'wrap',
});

export const MoreStep = styled('div', {
width: '18px',
height: '18px',
borderRadius: '100%',
backgroundColor: '$background',
cursor: 'default',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
border: '1.5px transparent solid',
variants: {
state: {
error: {
borderColor: '$error500',
},
warning: { borderColor: '$warning500' },
},
},
});
65 changes: 7 additions & 58 deletions widget/embedded/src/components/Quote/Quote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import type { SwapResult } from 'rango-sdk';
import { i18n } from '@lingui/core';
import {
Alert,
ChevronDownIcon,
ChevronRightIcon,
Divider,
Image,
InfoIcon,
QuoteCost,
StepDetails,
Expand Down Expand Up @@ -52,20 +49,18 @@ import { getTotalFeeInUsd } from '../../utils/swap';
import {
BasicInfoOutput,
basicInfoStyles,
ChainImageContainer,
Chains,
ContainerInfoOutput,
Content,
EXPANDABLE_QUOTE_TRANSITION_DURATION,
FrameIcon,
HorizontalSeparator,
IconContainer,
QuoteContainer,
stepsDetailsStyles,
SummaryContainer,
summaryStyles,
} from './Quote.styles';
import { QuoteSummary } from './QuoteSummary';
import { QuoteTrigger } from './QuoteTrigger ';

export function Quote(props: QuoteProps) {
const {
Expand Down Expand Up @@ -374,59 +369,13 @@ export function Quote(props: QuoteProps) {
recommended={recommended}
open={expanded}
onOpenChange={setExpanded}>
<Chains
ref={(ref) => (quoteRef.current = ref)}
<QuoteTrigger
quoteRef={quoteRef}
recommended={recommended}
onClick={() => setExpanded((prevState) => !prevState)}>
<div>
{steps.map((step, index) => {
const key = `item-${index}`;
const arrow = (
<IconContainer>
<ChevronRightIcon
size={12}
color="black"
{...(step.state && {
color: step.state === 'error' ? 'error' : 'warning',
})}
/>
</IconContainer>
);
return (
<React.Fragment key={key}>
<Tooltip
container={tooltipContainer}
side="bottom"
sideOffset={4}
content={step.from.chain.displayName}>
<ChainImageContainer
state={step.state || steps[index - 1]?.state}>
<Image src={step.from.chain.image} size={16} />
</ChainImageContainer>
</Tooltip>
{index === numberOfSteps - 1 && (
<>
{arrow}
<Tooltip
container={tooltipContainer}
side="bottom"
sideOffset={4}
content={step.to.chain.displayName}>
<ChainImageContainer state={step.state}>
<Image src={step.to.chain.image} size={16} />
</ChainImageContainer>
</Tooltip>
</>
)}
{index !== numberOfSteps - 1 && <>{arrow}</>}
</React.Fragment>
);
})}
</div>
<IconContainer orientation={expanded ? 'up' : 'down'}>
<ChevronDownIcon size={12} color="black" />
</IconContainer>
</Chains>
setExpanded={setExpanded}
expanded={expanded}
steps={steps}
/>
<Content open={expanded}>
<HorizontalSeparator />
<div className={stepsDetailsStyles()}>
Expand Down
17 changes: 17 additions & 0 deletions widget/embedded/src/components/Quote/Quote.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { QuoteError, QuoteWarning } from '../../types';
import type { Step } from '@rango-dev/ui';
import type { BestRouteResponse } from 'rango-sdk';
import type { ReactNode } from 'react';

Expand All @@ -13,3 +14,19 @@ export type QuoteProps = {
output: { value: string; usdValue?: string };
expanded?: boolean;
};

export type QuoteTriggerProps = {
quoteRef: React.MutableRefObject<HTMLButtonElement | null>;
recommended: boolean;
setExpanded: React.Dispatch<React.SetStateAction<boolean | undefined>>;
steps: Step[];
expanded?: boolean;
};

export type QuoteTriggerImagesProps = {
content: ReactNode;
state?: 'error' | 'warning' | undefined;
src: string;
open?: boolean;
className?: string;
};
Loading

0 comments on commit 378b3e4

Please sign in to comment.