Skip to content

Commit 7d2f699

Browse files
committed
fix(suite): Fix buy/sell/dca buttons
1 parent aff5a1c commit 7d2f699

File tree

3 files changed

+67
-37
lines changed

3 files changed

+67
-37
lines changed

packages/components/src/components/form/SelectBar/SelectBar.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const options = [
77
{ label: 'low', value: 'low' },
88
{ label: 'medium', value: 'medium' },
99
{ label: 'high', value: 'high' },
10-
{ label: 'custom', value: 'custom' },
10+
{ label: 'custom', value: 'custom', icon: 'clock' },
1111
];
1212

1313
const meta: Meta = {

packages/components/src/components/form/SelectBar/SelectBar.tsx

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import {
2222
withFrameProps,
2323
} from '../../../utils/frameProps';
2424
import { TransientProps } from '../../../utils/transientProps';
25+
import { Icon, IconName } from '../../Icon/Icon';
26+
import { Row } from '../../Flex/Flex';
2527

2628
export const allowedSelectBarFrameProps = ['margin', 'width'] as const satisfies FramePropsKeys[];
2729
type AllowedFrameProps = Pick<FrameProps, (typeof allowedSelectBarFrameProps)[number]>;
@@ -156,6 +158,7 @@ type ValueTypes = number | string | boolean;
156158
type Option<V extends ValueTypes> = {
157159
label: ReactNode;
158160
value: V;
161+
icon?: IconName;
159162
};
160163

161164
export type SelectBarProps<V extends ValueTypes> = {
@@ -256,22 +259,38 @@ export const SelectBar = <V extends ValueTypes>({
256259
onKeyDown={handleKeyboardNav}
257260
/>
258261

259-
{options.map(option => (
260-
<Option
261-
key={String(option.value)}
262-
onClick={handleOptionClick(option)}
263-
$isDisabled={!!isDisabled}
264-
$isSelected={
265-
selectedOptionIn !== undefined
266-
? selectedOptionIn === option.value
267-
: false
268-
}
269-
data-testid={`select-bar/${String(option.value)}`}
270-
>
262+
{options.map(option => {
263+
const content = option.icon ? (
264+
<Row gap={spacings.xs}>
265+
<Icon
266+
name={option.icon}
267+
size="medium"
268+
variant={selectedOptionIn === option.value ? 'primary' : undefined}
269+
/>
270+
<span>{option.label}</span>
271+
</Row>
272+
) : (
271273
<span>{option.label}</span>
272-
<WidthMock>{option.label}</WidthMock>
273-
</Option>
274-
))}
274+
);
275+
276+
return (
277+
<Option
278+
key={String(option.value)}
279+
onClick={handleOptionClick(option)}
280+
$isDisabled={!!isDisabled}
281+
$isSelected={
282+
selectedOptionIn !== undefined
283+
? selectedOptionIn === option.value
284+
: false
285+
}
286+
data-testid={`select-bar/${String(option.value)}`}
287+
>
288+
{content}
289+
290+
<WidthMock>{content}</WidthMock>
291+
</Option>
292+
);
293+
})}
275294
</Options>
276295
</Wrapper>
277296
);
Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
1-
import { Row } from '@trezor/components';
1+
import { IconName, SelectBar } from '@trezor/components';
2+
import { Route } from '@suite-common/suite-types';
23

3-
import { CoinmarketLayoutNavigationItem } from 'src/views/wallet/coinmarket/common/CoinmarketLayout/CoinmarketLayoutNavigation/CoinmarketLayoutNavigationItem';
4+
import { Translation } from '../../../../../../components/suite';
5+
import { goto } from '../../../../../../actions/suite/routerActions';
6+
import { useDispatch, useSelector } from '../../../../../../hooks/suite';
47

5-
export const CoinmarketLayoutNavigation = () => (
6-
<Row>
7-
<CoinmarketLayoutNavigationItem
8-
route="wallet-coinmarket-buy"
9-
title="TR_NAV_BUY"
10-
icon="plus"
11-
/>
12-
<CoinmarketLayoutNavigationItem
13-
route="wallet-coinmarket-sell"
14-
title="TR_NAV_SELL"
15-
icon="minus"
16-
/>
17-
<CoinmarketLayoutNavigationItem
18-
route="wallet-coinmarket-dca"
19-
title="TR_NAV_DCA"
20-
icon="clock"
21-
/>
22-
</Row>
23-
);
8+
const options = [
9+
{
10+
label: <Translation id="TR_NAV_BUY" />,
11+
value: 'wallet-coinmarket-buy' as Route['name'],
12+
icon: 'plus' as IconName,
13+
},
14+
{
15+
label: <Translation id="TR_NAV_SELL" />,
16+
value: 'wallet-coinmarket-sell' as Route['name'],
17+
icon: 'minus' as IconName,
18+
},
19+
{
20+
label: <Translation id="TR_NAV_DCA" />,
21+
value: 'wallet-coinmarket-dca' as Route['name'],
22+
icon: 'clock' as IconName,
23+
},
24+
];
25+
26+
export const CoinmarketLayoutNavigation = () => {
27+
const dispatch = useDispatch();
28+
const routeName = useSelector(state => state.router.route?.name);
29+
const onChange = (newRoute: Route['name']) => {
30+
dispatch(goto(newRoute));
31+
};
32+
33+
return <SelectBar selectedOption={routeName} options={options} onChange={onChange} />;
34+
};

0 commit comments

Comments
 (0)