import { useNavigation, useNavigationState, useRoute } from '@react-navigation/native'; import React, { useEffect, useState } from 'react'; import { ActivityIndicator, FlatList, I18nManager, Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; import LinearGradient from 'react-native-linear-gradient'; import triggerHapticFeedback, { HapticFeedbackTypes } from '../../blue_modules/hapticFeedback'; import { BlueSpacing20, BlueText } from '../../BlueComponents'; import { LightningCustodianWallet, LightningLdkWallet, MultisigHDWallet } from '../../class'; import WalletGradient from '../../class/wallet-gradient'; import { BlurredBalanceView } from '../../components/BlurredBalanceView'; import SafeArea from '../../components/SafeArea'; import { useTheme } from '../../components/themes'; import loc, { formatBalance, transactionTimeToReadable } from '../../loc'; import { Chain } from '../../models/bitcoinUnits'; import { useStorage } from '../../hooks/context/useStorage'; const SelectWallet = () => { const { chainType, onWalletSelect, availableWallets, noWalletExplanationText, onChainRequireSend = false } = useRoute().params; const [isLoading, setIsLoading] = useState(true); const { pop, navigate, setOptions, getParent } = useNavigation(); const { wallets } = useStorage(); const { colors, closeImage } = useTheme(); const isModal = useNavigationState(state => state.routes.length) === 1; let data = !onChainRequireSend ? wallets.filter(item => item.chain === Chain.ONCHAIN) || [] : chainType ? wallets.filter(item => item.chain === chainType && item.allowSend()) : wallets.filter(item => item.allowSend()) || []; if (availableWallets && availableWallets.length > 0) { // availableWallets if provided, overrides chainType argument and `allowSend()` check data = availableWallets; } const styles = StyleSheet.create({ loading: { flex: 1, justifyContent: 'center', alignContent: 'center', paddingTop: 20, backgroundColor: colors.background, }, itemRoot: { backgroundColor: 'transparent', padding: 10, marginVertical: 17, }, gradient: { padding: 15, borderRadius: 10, minHeight: 164, elevation: 5, }, image: { width: 99, height: 94, position: 'absolute', bottom: 0, right: 0, }, transparentText: { backgroundColor: 'transparent', }, label: { backgroundColor: 'transparent', fontSize: 19, color: '#fff', writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr', }, balance: { backgroundColor: 'transparent', fontWeight: 'bold', fontSize: 36, writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr', color: '#fff', }, latestTxLabel: { backgroundColor: 'transparent', fontSize: 13, color: '#fff', writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr', }, latestTxValue: { backgroundColor: 'transparent', fontWeight: 'bold', fontSize: 16, writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr', color: '#fff', }, noWallets: { flex: 1, justifyContent: 'center', alignItems: 'center', paddingTop: 20, }, center: { textAlign: 'center', }, }); useEffect(() => { console.log('SelectWallet - useEffect'); setIsLoading(false); }, []); useEffect(() => { if (isLoading || data.length === 0) { setOptions({ statusBarStyle: 'light' }); } else { setOptions({ statusBarStyle: 'auto' }); } }, [isLoading, data.length, setOptions]); useEffect(() => { setOptions( isModal ? { // eslint-disable-next-line react/no-unstable-nested-components headerLeft: () => ( { getParent().pop(); }} testID="NavigationCloseButton" > ), } : {}, ); // eslint-disable-next-line react-hooks/exhaustive-deps }, [closeImage, isModal, styles.button]); const renderItem = ({ item }) => { return ( { triggerHapticFeedback(HapticFeedbackTypes.Selection); onWalletSelect(item, { navigation: { pop, navigate } }); }} accessibilityRole="button" > { switch (item.type) { case LightningLdkWallet.type: case LightningCustodianWallet.type: return I18nManager.isRTL ? require('../../img/lnd-shape-rtl.png') : require('../../img/lnd-shape.png'); case MultisigHDWallet.type: return I18nManager.isRTL ? require('../../img/vault-shape-rtl.png') : require('../../img/vault-shape.png'); default: return I18nManager.isRTL ? require('../../img/btc-shape-rtl.png') : require('../../img/btc-shape.png'); } })()} style={styles.image} /> {item.getLabel()} {item.hideBalance ? ( ) : ( {formatBalance(Number(item.getBalance()), item.getPreferredBalanceUnit(), true)} )} {loc.wallets.list_latest_transaction} {transactionTimeToReadable(item.getLatestTransactionTime())} ); }; if (isLoading) { return ( ); } else if (data.length <= 0) { return ( {loc.wallets.select_no_bitcoin} {noWalletExplanationText || loc.wallets.select_no_bitcoin_exp} ); } else { return ( `${index}`} /> ); } }; export default SelectWallet;