import { useSnapshot } from 'valtio'; import { memo, useState } from 'react'; import { SvgUri } from 'react-native-svg'; import { FlexView, ListItem, Text, useTheme, Icon, Image } from '@reown/appkit-ui-react-native'; import { OnRampController } from '@reown/appkit-core-react-native'; import { type OnRampCountry, type OnRampFiatCurrency } from '@reown/appkit-common-react-native'; import { SelectorModal } from '../../partials/w3m-selector-modal'; import { Country } from './components/Country'; import { Currency } from '../w3m-onramp-view/components/Currency'; import { getModalTitle, getItemHeight, getModalItems, getModalItemKey, getModalSearchPlaceholder, getModalEmptyTitle, getModalEmptyDescription } from './utils'; import { styles } from './styles'; type ModalType = 'country' | 'paymentCurrency'; const MemoizedCountry = memo(Country); const MemoizedCurrency = memo(Currency); export function OnRampSettingsView() { const { paymentCurrency, selectedCountry } = useSnapshot(OnRampController.state); const Theme = useTheme(); const [modalType, setModalType] = useState(); const [searchValue, setSearchValue] = useState(''); const onModalClose = () => { setModalType(undefined); setSearchValue(''); }; const onCountryPress = () => { setModalType('country'); }; const onPaymentCurrencyPress = () => { setModalType('paymentCurrency'); }; const onPressModalItem = async (item: any) => { setModalType(undefined); setSearchValue(''); if (modalType === 'country') { await OnRampController.setSelectedCountry(item as OnRampCountry); } else if (modalType === 'paymentCurrency') { OnRampController.setPaymentCurrency(item as OnRampFiatCurrency); } }; const renderModalItem = ({ item }: { item: any }) => { if (modalType === 'country') { const parsedItem = item as OnRampCountry; return ( ); } const parsedItem = item as OnRampFiatCurrency; return ( ); }; return ( <> {selectedCountry?.flagImageUrl && SvgUri ? ( ) : undefined} Select Country {selectedCountry?.name ? ( {selectedCountry?.name} ) : null} {paymentCurrency?.symbolImageUrl ? ( ) : ( )} Select Currency {paymentCurrency?.name ? ( {paymentCurrency?.name} ) : null} getModalItemKey(modalType, index, item)} title={getModalTitle(modalType)} itemHeight={getItemHeight(modalType)} searchPlaceholder={getModalSearchPlaceholder(modalType)} emptyTitle={getModalEmptyTitle(modalType)} emptyDescription={getModalEmptyDescription(modalType)} /> ); }