Skip to content

Commit 46a8e66

Browse files
committed
feat(suite-native): add real countries data to trading
1 parent dce9c9e commit 46a8e66

File tree

5 files changed

+18
-44
lines changed

5 files changed

+18
-44
lines changed

suite-native/module-trading/src/components/buy/CountryOfResidencePicker.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { HStack, Text } from '@suite-native/atoms';
2-
import { Icon } from '@suite-native/icons';
32
import { useTranslate } from '@suite-native/intl';
43

54
import { useTradeSheetControls } from '../../hooks/useTradeSheetControls';
@@ -21,9 +20,8 @@ export const CountryOfResidencePicker = () => {
2120
>
2221
{selectedValue ? (
2322
<HStack>
24-
<Icon name={selectedValue.flag} size="medium" />
2523
<Text color="textSubdued" variant="body">
26-
{selectedValue.name}
24+
{selectedValue.value}
2725
</Text>
2826
</HStack>
2927
) : (
@@ -36,7 +34,7 @@ export const CountryOfResidencePicker = () => {
3634
isVisible={isSheetVisible}
3735
onClose={hideSheet}
3836
onCountrySelect={setSelectedValue}
39-
selectedCountryId={selectedValue?.id}
37+
selectedCountryId={selectedValue?.value}
4038
/>
4139
</>
4240
);

suite-native/module-trading/src/components/general/CountrySheet/CountryListItem.tsx

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import { ReactNode } from 'react';
22
import { Pressable } from 'react-native';
33

44
import { Card, HStack, Radio, Text } from '@suite-native/atoms';
5-
import { Icon, IconName } from '@suite-native/icons';
65
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles';
76

87
export type CountryListItemProps = {
9-
flag: IconName;
10-
id: string;
11-
name: ReactNode;
8+
value: string;
9+
label: ReactNode;
1210
isSelected: boolean;
1311
onPress: () => void;
1412
};
@@ -19,20 +17,19 @@ const wrapperStyle = prepareNativeStyle(({ spacings }) => ({
1917
marginVertical: spacings.sp4,
2018
}));
2119

22-
export const CountryListItem = ({ flag, name, onPress, id, isSelected }: CountryListItemProps) => {
20+
export const CountryListItem = ({ label, onPress, value, isSelected }: CountryListItemProps) => {
2321
const { applyStyle } = useNativeStyles();
2422

2523
return (
2624
<Pressable onPress={onPress} style={applyStyle(wrapperStyle)}>
2725
<Card>
2826
<HStack alignItems="center" justifyContent="space-between">
2927
<HStack>
30-
<Icon name={flag} size="medium" />
3128
<Text variant="body" color="textDefault">
32-
{name}
29+
{label}
3330
</Text>
3431
</HStack>
35-
<Radio value={id} onPress={onPress} isChecked={isSelected} />
32+
<Radio value={value} onPress={onPress} isChecked={isSelected} />
3633
</HStack>
3734
</Card>
3835
</Pressable>

suite-native/module-trading/src/components/general/CountrySheet/CountrySheet.tsx

+5-20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { regional } from '@suite-common/trading';
12
import { BottomSheetFlashList } from '@suite-native/atoms';
23
import { Translation } from '@suite-native/intl';
34

@@ -13,21 +14,7 @@ export type CountrySheetProps = {
1314
selectedCountryId?: string;
1415
};
1516

16-
const mockCountries: Country[] = [
17-
{ id: 'us', name: 'United States', flag: 'flag' },
18-
{ id: 'cz', name: 'Czech Republic', flag: 'flagCheckered' },
19-
{ id: 'sk', name: 'Slovakia', flag: 'flag' },
20-
{ id: 'de', name: 'Germany', flag: 'flagCheckered' },
21-
{ id: 'fr', name: 'France', flag: 'flag' },
22-
{ id: 'es', name: 'Spain', flag: 'flagCheckered' },
23-
{ id: 'it', name: 'Italy', flag: 'flag' },
24-
{ id: 'pl', name: 'Poland', flag: 'flagCheckered' },
25-
{ id: 'hu', name: 'Hungary', flag: 'flag' },
26-
{ id: 'at', name: 'Austria', flag: 'flagCheckered' },
27-
{ id: 'ch', name: 'Switzerland', flag: 'flag' },
28-
];
29-
30-
const keyExtractor = (item: Country) => item.id;
17+
const keyExtractor = (item: Country) => item.value;
3118
const getEstimatedListHeight = (itemsCount: number) => itemsCount * COUNTRY_LIST_ITEM_HEIGHT;
3219

3320
export const CountrySheet = ({
@@ -41,8 +28,6 @@ export const CountrySheet = ({
4128
onClose();
4229
};
4330

44-
const data: Country[] = mockCountries;
45-
4631
return (
4732
<BottomSheetFlashList<Country>
4833
isVisible={isVisible}
@@ -58,11 +43,11 @@ export const CountrySheet = ({
5843
<CountryListItem
5944
{...item}
6045
onPress={() => onCountrySelectCallback(item)}
61-
isSelected={item.id === selectedCountryId}
46+
isSelected={item.value === selectedCountryId}
6247
/>
6348
)}
64-
data={data}
65-
estimatedListHeight={getEstimatedListHeight(data.length)}
49+
data={regional.countriesOptions}
50+
estimatedListHeight={getEstimatedListHeight(regional.countriesOptions.length)}
6651
estimatedItemSize={COUNTRY_LIST_ITEM_HEIGHT}
6752
keyExtractor={keyExtractor}
6853
/>

suite-native/module-trading/src/components/general/CountrySheet/__tests__/CountryListItem.comp.test.tsx

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,26 @@ describe('CountryListItem', () => {
66
const renderCountryListItem = (props: Partial<CountryListItemProps>) =>
77
render(
88
<CountryListItem
9-
flag="flag"
10-
id="US"
9+
value="US"
1110
isSelected={false}
12-
name="United States"
11+
label="🇺🇸 United States of America"
1312
onPress={jest.fn()}
1413
{...props}
1514
/>,
1615
);
1716

1817
it('should render given name', () => {
19-
const { getByText } = renderCountryListItem({ name: 'United States' });
18+
const { getByText } = renderCountryListItem({ label: '🇺🇸 United States of America' });
2019

21-
expect(getByText('United States')).toBeDefined();
20+
expect(getByText('🇺🇸 United States of America')).toBeDefined();
2221
});
2322

2423
it('should call onPress callback on item press', () => {
2524
const onPress = jest.fn();
2625
const { getByText } = renderCountryListItem({ onPress });
2726

2827
act(() => {
29-
fireEvent.press(getByText('United States'));
28+
fireEvent.press(getByText('🇺🇸 United States of America'));
3029
});
3130

3231
expect(onPress).toHaveBeenCalledTimes(1);

suite-native/module-trading/src/types.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { NetworkSymbol } from '@suite-common/wallet-config';
22
import { Account, TokenAddress } from '@suite-common/wallet-types';
3-
import { IconName } from '@suite-native/icons';
43
import { Address } from '@trezor/blockchain-link-types';
54

65
// NOTE: in production code we probably want to use `TokenInfoBranded` or something similar instead
@@ -10,11 +9,7 @@ export type TradeableAsset = {
109
name?: string;
1110
};
1211

13-
export type Country = {
14-
id: string;
15-
name: string;
16-
flag: IconName;
17-
};
12+
export type Country = { label: string; value: string };
1813

1914
export type ReceiveAccount = {
2015
account: Account;

0 commit comments

Comments
 (0)