Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/slimy-windows-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@venusprotocol/evm": minor
---

add token switch to Trade page
20 changes: 5 additions & 15 deletions apps/evm/src/components/CellGroup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Cell, type CellProps } from '../Cell';

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

export type CellGroupVariant = 'primary' | 'secondary' | 'tertiary';
export type CellGroupVariant = 'primary' | 'secondary';

export interface CellGroupProps {
cells: CellProps[];
Expand All @@ -21,13 +21,10 @@ export const CellGroup: React.FC<CellGroupProps> = ({
}) => (
<Card
className={cn(
'min-w-0 border-0',
'min-w-0 border-0 p-0 gap-4 md:gap-x-6',
variant === 'primary' &&
'p-4 grid grid-cols-2 rounded-xl gap-4 sm:flex sm:flex-wrap sm:gap-0 sm:px-6 sm:py-4',
variant === 'secondary' &&
'p-0 flex overflow-x-auto overflow-y-hidden scrollbar-hidden bg-transparent sm:p-0 md:p-0 xl:p-0',
variant === 'tertiary' &&
'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',
'flex overflow-x-auto overflow-y-hidden scrollbar-hidden bg-transparent',
variant === 'secondary' && 'grid grid-cols-2 xl:flex xl:flex-wrap xl:rounded-xl',
Comment thread
therealemjy marked this conversation as resolved.
className,
)}
{...containerProps}
Expand All @@ -36,14 +33,7 @@ export const CellGroup: React.FC<CellGroupProps> = ({
<Cell
key={`cell-group-item-${cell.label}`}
{...cell}
className={cn(
'shrink-0 xl:bg-transparent',
variant === 'primary' && 'sm:px-6 sm:first-of-type:pl-0 sm:last-of-type:pr-0',
variant === 'secondary' && 'px-4 md:px-6 first-of-type:pl-0 last-of-type:pr-0',
variant === 'tertiary' &&
'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',
cell.className,
)}
className={cn('shrink-0 xl:bg-transparent', cell.className)}
/>
))}
</Card>
Expand Down
1 change: 1 addition & 0 deletions apps/evm/src/components/Icon/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,4 @@ export { default as protectionShield } from './protectionShield';
export { default as resilientOracle } from './resilientOracle';
export { default as sunset } from './sunset';
export { default as fullScreen } from './fullScreen';
export { default as switch } from './switch';
29 changes: 29 additions & 0 deletions apps/evm/src/components/Icon/icons/switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { SVGProps } from 'react';

const SvgSwitch = (props: SVGProps<SVGSVGElement>) => (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<path
d="M12 6.83331H1L4.14286 3.83331"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M4 9.83331H15L11.8571 12.8333"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
Comment thread
therealemjy marked this conversation as resolved.
</svg>
);

export default SvgSwitch;
2 changes: 1 addition & 1 deletion apps/evm/src/containers/Layout/Header/MarketInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export const MarketInfo = () => {
...cell,
className: 'p-0 bg-transparent',
}))}
variant="tertiary"
variant="secondary"
className="xl:p-0 xl:bg-transparent"
/>
</Wrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ export const Summary: React.FC<SummaryProps> = ({
<div className="space-y-4 md:space-y-6 xl:hidden">
<CellGroup
cells={displayAccountHealth ? cells.slice(0, cells.length - 1) : cells}
variant="tertiary"
className={cn('gap-3', displayAccountHealth ? 'sm:grid-cols-3' : 'sm:grid-cols-2')}
variant="secondary"
className={cn(displayAccountHealth ? 'sm:grid-cols-3' : 'sm:grid-cols-2')}
/>

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

{/* Account health */}
Expand Down
2 changes: 1 addition & 1 deletion apps/evm/src/pages/Dashboard/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export const Overview: React.FC<OverviewProps> = ({ ...otherProps }) => {
disabled={!accountAddress}
onClick={toggleAccordion}
>
<CellGroup variant="secondary" cells={graphCells} />
<CellGroup cells={graphCells} />

{shouldShowAccountBreakdown && (
<div className="flex items-center gap-x-3" data-testid={testIds.performanceChartPreview}>
Expand Down
2 changes: 1 addition & 1 deletion apps/evm/src/pages/Dashboard/Vaults/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const Vaults: React.FC<VaultsProps> = ({ vaults }) => {

return (
<>
<CellGroup variant="secondary" cells={overviewCells} className="mb-6" />
<CellGroup cells={overviewCells} className="mb-6" />
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 2xl:grid-cols-3">
{filteredVaults.map(vault => (
<VaultCardSimplified vault={vault} key={vault.key} />
Expand Down
1 change: 0 additions & 1 deletion apps/evm/src/pages/Markets/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export const Header: React.FC<HeaderProps> = ({ pool, className }) => {

<PoolStats
pools={[pool]}
variant="secondary"
className="xl:w-auto"
stats={['supply', 'borrow', 'liquidity', 'assetCount']}
/>
Expand Down
12 changes: 12 additions & 0 deletions apps/evm/src/pages/Trade/PairInfo/__tests__/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ vi.mock('../../useTokenPair', () => ({

const longTokenSelectTestId = 'pair-info-long-token-select';
const shortTokenSelectTestId = 'pair-info-short-token-select';
const switchTokensButtonTestId = 'pair-info-switch-tokens-button';

const defaultLongAsset = poolData[0].assets[2];
const defaultShortAsset = poolData[0].assets[3];
Expand Down Expand Up @@ -209,4 +210,15 @@ describe('PairInfo', () => {
[SHORT_TOKEN_ADDRESS_PARAM_KEY]: defaultLongToken.address,
});
});

it('updates search params when switching the selected tokens', async () => {
renderPairInfo();

fireEvent.click(screen.getByTestId(switchTokensButtonTestId));

await expectUpdatedSearchParams({
[LONG_TOKEN_ADDRESS_PARAM_KEY]: defaultShortToken.address,
[SHORT_TOKEN_ADDRESS_PARAM_KEY]: defaultLongToken.address,
});
});
});
24 changes: 20 additions & 4 deletions apps/evm/src/pages/Trade/PairInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { cn } from '@venusprotocol/ui';
import BigNumber from 'bignumber.js';
import { useSearchParams } from 'react-router';

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

const switchSelectedTokens = () =>
setSearchParams(currentSearchParams => ({
...Object.fromEntries(currentSearchParams),
[SHORT_TOKEN_ADDRESS_PARAM_KEY]: longToken.address,
[LONG_TOKEN_ADDRESS_PARAM_KEY]: shortToken.address,
}));

const {
data: { borrowAssets, supplyAssets },
} = useGetTradeAssets();
Expand Down Expand Up @@ -139,7 +146,7 @@ export const PairInfo: React.FC<PairInfoProps> = ({ changePercentage, priceCents
];

return (
<div className="flex flex-col gap-y-6 lg:flex-col lg:p-4 lg:rounded-lg lg:border lg:border-dark-blue-hover">
<div className="flex flex-col gap-y-6 lg:p-4 lg:rounded-lg lg:border lg:border-dark-blue-hover">
<div className="flex flex-col gap-3 sm:flex-row">
<TokenSelect
type="long"
Expand All @@ -158,7 +165,7 @@ export const PairInfo: React.FC<PairInfoProps> = ({ changePercentage, priceCents
/>
</div>

<div className="flex min-w-0 flex-col gap-6 md:flex-row md:justify-between lg:flex lg:flex-col">
<div className="flex min-w-0 flex-col gap-6 md:flex-row md:justify-between lg:flex-col 2xl:flex-row">
<div className="flex items-center gap-x-2">
<TokenPair
shortToken={shortToken}
Expand All @@ -184,10 +191,19 @@ export const PairInfo: React.FC<PairInfoProps> = ({ changePercentage, priceCents
</p>
)}
</div>

<button
type="button"
className="cursor-pointer text-light-grey hover:text-blue"
onClick={switchSelectedTokens}
data-testid="pair-info-switch-tokens-button"
>
Comment thread
therealemjy marked this conversation as resolved.
<Icon name="switch" className="text-inherit transition-colors" />
</button>
</div>

<div className="overflow-hidden">
<CellGroup variant="secondary" cells={cells} />
<CellGroup cells={cells} />
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const StatusTab: React.FC<StatusTabProps> = ({ row }) => {

return (
<div className="flex flex-col gap-y-6 gap-x-12 justify-between md:flex-row lg:flex-col 2xl:flex-row">
<CellGroup variant="secondary" cells={cells} className="md:w-auto lg:w-full 2xl:w-auto" />
<CellGroup cells={cells} className="md:w-auto lg:w-full 2xl:w-auto" />

<AccountHealth pool={row.pool} />
</div>
Expand Down
Loading