Skip to content

Commit 25732f7

Browse files
committed
feat: add token switch to Trade page
1 parent 4c975b1 commit 25732f7

5 files changed

Lines changed: 41 additions & 7 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/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';

apps/evm/src/components/Icon/icons/switch.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ const SvgSwitch = (props: SVGProps<SVGSVGElement>) => (
1212
<path
1313
d="M12 6.83331H1L4.14286 3.83331"
1414
stroke="currentColor"
15-
stroke-width="1.5"
16-
stroke-linecap="round"
17-
stroke-linejoin="round"
15+
strokeWidth="1.5"
16+
strokeLinecap="round"
17+
strokeLinejoin="round"
1818
/>
1919
<path
2020
d="M4 9.83331H15L11.8571 12.8333"
2121
stroke="currentColor"
22-
stroke-width="1.5"
23-
stroke-linecap="round"
24-
stroke-linejoin="round"
22+
strokeWidth="1.5"
23+
strokeLinecap="round"
24+
strokeLinejoin="round"
2525
/>
2626
</svg>
2727
);

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
});

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { cn } from '@venusprotocol/ui';
22
import BigNumber from 'bignumber.js';
33
import { useSearchParams } from 'react-router';
44

5-
import { Apy, CellGroup, type CellProps } from 'components';
5+
import { Apy, CellGroup, type CellProps, Icon } from 'components';
66
import { PLACEHOLDER_KEY } from 'constants/placeholders';
77
import { useTranslation } from 'libs/translations';
88
import type { Asset, Token } from 'types';
@@ -52,6 +52,13 @@ export const PairInfo: React.FC<PairInfoProps> = ({ changePercentage, priceCents
5252
: longToken.address,
5353
}));
5454

55+
const switchSelectedTokens = () =>
56+
setSearchParams(currentSearchParams => ({
57+
...Object.fromEntries(currentSearchParams),
58+
[SHORT_TOKEN_ADDRESS_PARAM_KEY]: longToken.address,
59+
[LONG_TOKEN_ADDRESS_PARAM_KEY]: shortToken.address,
60+
}));
61+
5562
const {
5663
data: { borrowAssets, supplyAssets },
5764
} = useGetTradeAssets();
@@ -184,6 +191,15 @@ export const PairInfo: React.FC<PairInfoProps> = ({ changePercentage, priceCents
184191
</p>
185192
)}
186193
</div>
194+
195+
<button
196+
type="button"
197+
className="cursor-pointer text-light-grey hover:text-blue"
198+
onClick={switchSelectedTokens}
199+
data-testid="pair-info-switch-tokens-button"
200+
>
201+
<Icon name="switch" className="text-inherit transition-colors" />
202+
</button>
187203
</div>
188204

189205
<div className="overflow-hidden">

0 commit comments

Comments
 (0)