Skip to content

Commit 15883d0

Browse files
authored
feat: add token switch on Trade page (#5583)
* feat: simplify CellGroup component * feat: add token switch to Trade page
1 parent 17beed2 commit 15883d0

12 files changed

Lines changed: 78 additions & 27 deletions

File tree

.changeset/slimy-windows-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@venusprotocol/evm": minor
3+
---
4+
5+
add token switch to Trade page

apps/evm/src/components/CellGroup/index.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Cell, type CellProps } from '../Cell';
55

66
export type { CellProps } from '../Cell';
77

8-
export type CellGroupVariant = 'primary' | 'secondary' | 'tertiary';
8+
export type CellGroupVariant = 'primary' | 'secondary';
99

1010
export interface CellGroupProps {
1111
cells: CellProps[];
@@ -21,13 +21,10 @@ export const CellGroup: React.FC<CellGroupProps> = ({
2121
}) => (
2222
<Card
2323
className={cn(
24-
'min-w-0 border-0',
24+
'min-w-0 border-0 p-0 gap-4 md:gap-x-6',
2525
variant === 'primary' &&
26-
'p-4 grid grid-cols-2 rounded-xl gap-4 sm:flex sm:flex-wrap sm:gap-0 sm:px-6 sm:py-4',
27-
variant === 'secondary' &&
28-
'p-0 flex overflow-x-auto overflow-y-hidden scrollbar-hidden bg-transparent sm:p-0 md:p-0 xl:p-0',
29-
variant === 'tertiary' &&
30-
'gap-2 bg-transparent p-0 grid grid-cols-2 sm:p-0 xl:bg-cards xl:flex xl:p-6 xl:flex-wrap xl:rounded-xl xl:gap-x-0',
26+
'flex overflow-x-auto overflow-y-hidden scrollbar-hidden bg-transparent',
27+
variant === 'secondary' && 'grid grid-cols-2 xl:flex xl:flex-wrap xl:rounded-xl',
3128
className,
3229
)}
3330
{...containerProps}
@@ -36,14 +33,7 @@ export const CellGroup: React.FC<CellGroupProps> = ({
3633
<Cell
3734
key={`cell-group-item-${cell.label}`}
3835
{...cell}
39-
className={cn(
40-
'shrink-0 xl:bg-transparent',
41-
variant === 'primary' && 'sm:px-6 sm:first-of-type:pl-0 sm:last-of-type:pr-0',
42-
variant === 'secondary' && 'px-4 md:px-6 first-of-type:pl-0 last-of-type:pr-0',
43-
variant === 'tertiary' &&
44-
'bg-cards rounded-xl p-4 xl:py-0 xl:px-6 xl:rounded-none xl:first-of-type:pl-0 xl:last-of-type:pr-0',
45-
cell.className,
46-
)}
36+
className={cn('shrink-0 xl:bg-transparent', cell.className)}
4737
/>
4838
))}
4939
</Card>

apps/evm/src/components/Icon/icons/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,4 @@ export { default as protectionShield } from './protectionShield';
9696
export { default as resilientOracle } from './resilientOracle';
9797
export { default as sunset } from './sunset';
9898
export { default as fullScreen } from './fullScreen';
99+
export { default as switch } from './switch';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { SVGProps } from 'react';
2+
3+
const SvgSwitch = (props: SVGProps<SVGSVGElement>) => (
4+
<svg
5+
width="16"
6+
height="16"
7+
viewBox="0 0 16 16"
8+
fill="none"
9+
xmlns="http://www.w3.org/2000/svg"
10+
{...props}
11+
>
12+
<path
13+
d="M12 6.83331H1L4.14286 3.83331"
14+
stroke="currentColor"
15+
strokeWidth="1.5"
16+
strokeLinecap="round"
17+
strokeLinejoin="round"
18+
/>
19+
<path
20+
d="M4 9.83331H15L11.8571 12.8333"
21+
stroke="currentColor"
22+
strokeWidth="1.5"
23+
strokeLinecap="round"
24+
strokeLinejoin="round"
25+
/>
26+
</svg>
27+
);
28+
29+
export default SvgSwitch;

apps/evm/src/containers/Layout/Header/MarketInfo/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export const MarketInfo = () => {
212212
...cell,
213213
className: 'p-0 bg-transparent',
214214
}))}
215-
variant="tertiary"
215+
variant="secondary"
216216
className="xl:p-0 xl:bg-transparent"
217217
/>
218218
</Wrapper>

apps/evm/src/pages/Dashboard/Markets/Positions/Summary/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ export const Summary: React.FC<SummaryProps> = ({
140140
<div className="space-y-4 md:space-y-6 xl:hidden">
141141
<CellGroup
142142
cells={displayAccountHealth ? cells.slice(0, cells.length - 1) : cells}
143-
variant="tertiary"
144-
className={cn('gap-3', displayAccountHealth ? 'sm:grid-cols-3' : 'sm:grid-cols-2')}
143+
variant="secondary"
144+
className={cn(displayAccountHealth ? 'sm:grid-cols-3' : 'sm:grid-cols-2')}
145145
/>
146146

147147
{displayAccountHealth && <Cell {...cells[cells.length - 1]} className={cellClassName} />}
@@ -152,7 +152,6 @@ export const Summary: React.FC<SummaryProps> = ({
152152
<CellGroup
153153
cells={displayAccountHealth ? cells.slice(0, cells.length - 1) : cells}
154154
className="w-full xl:p-0"
155-
variant="secondary"
156155
/>
157156

158157
{/* Account health */}

apps/evm/src/pages/Dashboard/Overview/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export const Overview: React.FC<OverviewProps> = ({ ...otherProps }) => {
312312
disabled={!accountAddress}
313313
onClick={toggleAccordion}
314314
>
315-
<CellGroup variant="secondary" cells={graphCells} />
315+
<CellGroup cells={graphCells} />
316316

317317
{shouldShowAccountBreakdown && (
318318
<div className="flex items-center gap-x-3" data-testid={testIds.performanceChartPreview}>

apps/evm/src/pages/Dashboard/Vaults/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const Vaults: React.FC<VaultsProps> = ({ vaults }) => {
8282

8383
return (
8484
<>
85-
<CellGroup variant="secondary" cells={overviewCells} className="mb-6" />
85+
<CellGroup cells={overviewCells} className="mb-6" />
8686
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 2xl:grid-cols-3">
8787
{filteredVaults.map(vault => (
8888
<VaultCardSimplified vault={vault} key={vault.key} />

apps/evm/src/pages/Markets/Header/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export const Header: React.FC<HeaderProps> = ({ pool, className }) => {
2929

3030
<PoolStats
3131
pools={[pool]}
32-
variant="secondary"
3332
className="xl:w-auto"
3433
stats={['supply', 'borrow', 'liquidity', 'assetCount']}
3534
/>

apps/evm/src/pages/Trade/PairInfo/__tests__/index.spec.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ vi.mock('../../useTokenPair', () => ({
3131

3232
const longTokenSelectTestId = 'pair-info-long-token-select';
3333
const shortTokenSelectTestId = 'pair-info-short-token-select';
34+
const switchTokensButtonTestId = 'pair-info-switch-tokens-button';
3435

3536
const defaultLongAsset = poolData[0].assets[2];
3637
const defaultShortAsset = poolData[0].assets[3];
@@ -209,4 +210,15 @@ describe('PairInfo', () => {
209210
[SHORT_TOKEN_ADDRESS_PARAM_KEY]: defaultLongToken.address,
210211
});
211212
});
213+
214+
it('updates search params when switching the selected tokens', async () => {
215+
renderPairInfo();
216+
217+
fireEvent.click(screen.getByTestId(switchTokensButtonTestId));
218+
219+
await expectUpdatedSearchParams({
220+
[LONG_TOKEN_ADDRESS_PARAM_KEY]: defaultShortToken.address,
221+
[SHORT_TOKEN_ADDRESS_PARAM_KEY]: defaultLongToken.address,
222+
});
223+
});
212224
});

0 commit comments

Comments
 (0)