-
-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suite-native): Mobile Trade - Country picker visual stub
- Loading branch information
Showing
18 changed files
with
423 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
suite-native/module-trading/src/components/buy/CountryOfResidencePicker.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { HStack, Text } from '@suite-native/atoms'; | ||
import { Icon } from '@suite-native/icons'; | ||
import { useTranslate } from '@suite-native/intl'; | ||
|
||
import { useTradeSheetControls } from '../../hooks/useTradeSheetControls'; | ||
import { Country } from '../../types'; | ||
import { CountrySheet } from '../general/CountrySheet/CountrySheet'; | ||
import { TradingOverviewRow } from '../general/TradingOverviewRow'; | ||
|
||
export const CountryOfResidencePicker = () => { | ||
const { translate } = useTranslate(); | ||
|
||
const { isSheetVisible, hideSheet, showSheet, setSelectedValue, selectedValue } = | ||
useTradeSheetControls<Country>(); | ||
|
||
return ( | ||
<> | ||
<TradingOverviewRow | ||
title={translate('moduleTrading.tradingScreen.countryOfResidence')} | ||
onPress={showSheet} | ||
> | ||
{selectedValue ? ( | ||
<HStack> | ||
<Icon name={selectedValue.flag} size="medium" /> | ||
<Text color="textSubdued" variant="body"> | ||
{selectedValue.name} | ||
</Text> | ||
</HStack> | ||
) : ( | ||
<Text color="textDisabled" variant="body"> | ||
{translate('moduleTrading.notSelected')} | ||
</Text> | ||
)} | ||
</TradingOverviewRow> | ||
<CountrySheet | ||
isVisible={isSheetVisible} | ||
onClose={hideSheet} | ||
onCountrySelect={setSelectedValue} | ||
selectedCountryId={selectedValue?.id} | ||
/> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
suite-native/module-trading/src/components/buy/TradeableAssetPicker.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useTradeSheetControls } from '../../hooks/useTradeSheetControls'; | ||
import { TradeableAsset } from '../../types'; | ||
import { SelectTradeableAssetButton } from '../general/SelectTradeableAssetButton'; | ||
import { TradeableAssetsSheet } from '../general/TradeableAssetsSheet/TradeableAssetsSheet'; | ||
|
||
type TradeableAssetPickerProps = ReturnType<typeof useTradeSheetControls<TradeableAsset>>; | ||
|
||
export const TradeableAssetPicker = ({ | ||
isSheetVisible, | ||
showSheet, | ||
hideSheet, | ||
selectedValue, | ||
setSelectedValue, | ||
}: TradeableAssetPickerProps) => ( | ||
<> | ||
<SelectTradeableAssetButton onPress={showSheet} selectedAsset={selectedValue} /> | ||
<TradeableAssetsSheet | ||
isVisible={isSheetVisible} | ||
onClose={hideSheet} | ||
onAssetSelect={setSelectedValue} | ||
/> | ||
</> | ||
); |
10 changes: 10 additions & 0 deletions
10
...e-native/module-trading/src/components/general/CountrySheet/CountryListEmptyComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Translation } from '@suite-native/intl'; | ||
|
||
import { TradingEmptyComponent } from '../TradingEmptyComponent'; | ||
|
||
export const CountryListEmptyComponent = () => ( | ||
<TradingEmptyComponent | ||
title={<Translation id="moduleTrading.countrySheet.emptyTitle" />} | ||
description={<Translation id="moduleTrading.countrySheet.emptyDescription" />} | ||
/> | ||
); |
40 changes: 40 additions & 0 deletions
40
suite-native/module-trading/src/components/general/CountrySheet/CountryListItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ReactNode } from 'react'; | ||
import { Pressable } from 'react-native'; | ||
|
||
import { Card, HStack, Radio, Text } from '@suite-native/atoms'; | ||
import { Icon, IconName } from '@suite-native/icons'; | ||
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles'; | ||
|
||
export type CountryListItemProps = { | ||
flag: IconName; | ||
id: string; | ||
name: ReactNode; | ||
isSelected: boolean; | ||
onPress: () => void; | ||
}; | ||
|
||
export const COUNTRY_LIST_ITEM_HEIGHT = 64 as const; | ||
|
||
const wrapperStyle = prepareNativeStyle(({ spacings }) => ({ | ||
marginVertical: spacings.sp4, | ||
})); | ||
|
||
export const CountryListItem = ({ flag, name, onPress, id, isSelected }: CountryListItemProps) => { | ||
const { applyStyle } = useNativeStyles(); | ||
|
||
return ( | ||
<Pressable onPress={onPress} style={applyStyle(wrapperStyle)}> | ||
<Card> | ||
<HStack alignItems="center" justifyContent="space-between"> | ||
<HStack> | ||
<Icon name={flag} size="medium" /> | ||
<Text variant="body" color="textDefault"> | ||
{name} | ||
</Text> | ||
</HStack> | ||
<Radio value={id} onPress={onPress} isChecked={isSelected} /> | ||
</HStack> | ||
</Card> | ||
</Pressable> | ||
); | ||
}; |
70 changes: 70 additions & 0 deletions
70
suite-native/module-trading/src/components/general/CountrySheet/CountrySheet.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { BottomSheetFlashList } from '@suite-native/atoms'; | ||
import { Translation } from '@suite-native/intl'; | ||
|
||
import { SearchableSheetHeader } from '../SearchableSheetHeader'; | ||
import { CountryListEmptyComponent } from './CountryListEmptyComponent'; | ||
import { COUNTRY_LIST_ITEM_HEIGHT, CountryListItem } from './CountryListItem'; | ||
import { Country } from '../../../types'; | ||
|
||
export type CountrySheetProps = { | ||
isVisible: boolean; | ||
onClose: () => void; | ||
onCountrySelect: (symbol: Country) => void; | ||
selectedCountryId?: string; | ||
}; | ||
|
||
const mockCountries: Country[] = [ | ||
{ id: 'us', name: 'United States', flag: 'flag' }, | ||
{ id: 'cz', name: 'Czech Republic', flag: 'flagCheckered' }, | ||
{ id: 'sk', name: 'Slovakia', flag: 'flag' }, | ||
{ id: 'de', name: 'Germany', flag: 'flagCheckered' }, | ||
{ id: 'fr', name: 'France', flag: 'flag' }, | ||
{ id: 'es', name: 'Spain', flag: 'flagCheckered' }, | ||
{ id: 'it', name: 'Italy', flag: 'flag' }, | ||
{ id: 'pl', name: 'Poland', flag: 'flagCheckered' }, | ||
{ id: 'hu', name: 'Hungary', flag: 'flag' }, | ||
{ id: 'at', name: 'Austria', flag: 'flagCheckered' }, | ||
{ id: 'ch', name: 'Switzerland', flag: 'flag' }, | ||
]; | ||
|
||
const keyExtractor = (item: Country) => item.id; | ||
const getEstimatedListHeight = (itemsCount: number) => itemsCount * COUNTRY_LIST_ITEM_HEIGHT; | ||
|
||
export const CountrySheet = ({ | ||
isVisible, | ||
onClose, | ||
onCountrySelect, | ||
selectedCountryId, | ||
}: CountrySheetProps) => { | ||
const onCountrySelectCallback = (country: Country) => { | ||
onCountrySelect(country); | ||
onClose(); | ||
}; | ||
|
||
const data: Country[] = mockCountries; | ||
|
||
return ( | ||
<BottomSheetFlashList<Country> | ||
isVisible={isVisible} | ||
onClose={onClose} | ||
ListEmptyComponent={<CountryListEmptyComponent />} | ||
handleComponent={() => ( | ||
<SearchableSheetHeader | ||
onClose={onClose} | ||
title={<Translation id="moduleTrading.countrySheet.title" />} | ||
/> | ||
)} | ||
renderItem={({ item }) => ( | ||
<CountryListItem | ||
{...item} | ||
onPress={() => onCountrySelectCallback(item)} | ||
isSelected={item.id === selectedCountryId} | ||
/> | ||
)} | ||
data={data} | ||
estimatedListHeight={getEstimatedListHeight(data.length)} | ||
estimatedItemSize={COUNTRY_LIST_ITEM_HEIGHT} | ||
keyExtractor={keyExtractor} | ||
/> | ||
); | ||
}; |
79 changes: 79 additions & 0 deletions
79
suite-native/module-trading/src/components/general/SearchableSheetHeader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { ReactNode, useCallback, useState } from 'react'; | ||
import Animated, { FadeIn, FadeOut, LinearTransition } from 'react-native-reanimated'; | ||
|
||
import { BottomSheetGrabber, VStack } from '@suite-native/atoms'; | ||
import { useTranslate } from '@suite-native/intl'; | ||
import { NativeStyleObject, prepareNativeStyle, useNativeStyles } from '@trezor/styles'; | ||
|
||
import { SearchInputWithCancel } from './SearchInputWithCancel'; | ||
import { SheetHeaderTitle } from './SheetHeaderTitle'; | ||
|
||
export type SearchableSheetHeaderProps = { | ||
onClose: () => void; | ||
title: ReactNode; | ||
onFilterFocusChange?: (isFilterActive: boolean) => void; | ||
children?: ReactNode; | ||
style?: NativeStyleObject; | ||
}; | ||
|
||
export const FOCUS_ANIMATION_DURATION = 300 as const; | ||
|
||
const noOp = () => {}; | ||
|
||
const wrapperStyle = prepareNativeStyle<{}>(({ spacings }) => ({ | ||
padding: spacings.sp16, | ||
gap: spacings.sp16, | ||
})); | ||
|
||
export const SearchableSheetHeader = ({ | ||
onClose, | ||
title, | ||
children, | ||
onFilterFocusChange = noOp, | ||
style, | ||
}: SearchableSheetHeaderProps) => { | ||
const { applyStyle } = useNativeStyles(); | ||
const { translate } = useTranslate(); | ||
|
||
const [isFilterActive, setIsFilterActive] = useState(false); | ||
const [filterValue, setFilterValue] = useState(''); | ||
|
||
const changeFilterFocus = useCallback( | ||
(newValue: boolean) => { | ||
setIsFilterActive(newValue); | ||
onFilterFocusChange(newValue); | ||
}, | ||
[onFilterFocusChange], | ||
); | ||
|
||
return ( | ||
<VStack style={[applyStyle(wrapperStyle), style]}> | ||
<BottomSheetGrabber /> | ||
<Animated.View layout={LinearTransition.duration(FOCUS_ANIMATION_DURATION)}> | ||
{!isFilterActive && ( | ||
<Animated.View | ||
entering={FadeIn.duration(FOCUS_ANIMATION_DURATION)} | ||
exiting={FadeOut.duration(FOCUS_ANIMATION_DURATION)} | ||
> | ||
<SheetHeaderTitle | ||
leftButtonIcon="x" | ||
onLeftButtonPress={onClose} | ||
leftButtonA11yLabel={translate('generic.buttons.close')} | ||
> | ||
{title} | ||
</SheetHeaderTitle> | ||
</Animated.View> | ||
)} | ||
</Animated.View> | ||
<Animated.View layout={LinearTransition.duration(FOCUS_ANIMATION_DURATION)}> | ||
<SearchInputWithCancel | ||
onChange={setFilterValue} | ||
onFocus={() => changeFilterFocus(true)} | ||
onBlur={() => changeFilterFocus(false)} | ||
value={filterValue} | ||
/> | ||
</Animated.View> | ||
{children} | ||
</VStack> | ||
); | ||
}; |
Oops, something went wrong.