import React, { useCallback } from 'react'; import { View, Text, FlatList, StyleSheet, TouchableOpacity, } from 'react-native'; import Icon from 'react-native-vector-icons/FontAwesome'; import CheckBox from '@react-native-community/checkbox'; import { useSelector } from 'react-redux'; import { useNavigation } from '@react-navigation/native'; import { fontStyles } from '../../../../styles/common'; import { strings } from '../../../../../locales/i18n'; import { IAccount } from '../types'; import { RPC, NO_RPC_BLOCK_EXPLORER } from '../../../../constants/network'; import { getEtherscanAddressUrl } from '../../../../util/etherscan'; import { findBlockExplorerForRpc } from '../../../../util/networks'; import Device from '../../../../util/device'; import { mockTheme, useAppThemeFromContext } from '../../../../util/theme'; import AccountDetails from '../AccountDetails'; import StyledButton from '../../../UI/StyledButton'; interface ISelectQRAccountsProps { canUnlock: boolean; accounts: IAccount[]; nextPage: () => void; prevPage: () => void; toggleAccount: (index: number) => void; onUnlock: () => void; onForget: () => void; } const createStyle = (colors: any) => StyleSheet.create({ container: { flex: 1, width: '100%', paddingHorizontal: 32, }, title: { marginTop: 40, fontSize: 24, marginBottom: 24, ...fontStyles.normal, color: colors.text.default, }, account: { flexDirection: 'row', paddingHorizontal: 10, paddingVertical: 5, }, checkBox: { backgroundColor: colors.background.default, }, number: { ...fontStyles.normal, color: colors.text.default, }, pagination: { alignSelf: 'flex-end', flexDirection: 'row', alignItems: 'center', }, paginationText: { ...fontStyles.normal, fontSize: 18, color: colors.primary.default, paddingHorizontal: 10, }, paginationItem: { flexDirection: 'row', alignItems: 'center', marginRight: 8, }, bottom: { alignItems: 'center', justifyContent: 'space-between', paddingTop: 70, paddingBottom: Device.isIphoneX() ? 20 : 10, }, button: { width: '100%', justifyContent: 'flex-end', paddingTop: 15, }, }); const SelectQRAccounts = (props: ISelectQRAccountsProps) => { const { accounts, prevPage, nextPage, toggleAccount, onForget, onUnlock, canUnlock, } = props; const { colors } = useAppThemeFromContext() || mockTheme; const styles = createStyle(colors); const navigation = useNavigation(); const provider = useSelector( (state: any) => state.engine.backgroundState.NetworkController.provider, ); const frequentRpcList = useSelector( (state: any) => state.engine.backgroundState.PreferencesController.frequentRpcList, ); const toBlockExplorer = useCallback( (address: string) => { const { type, rpcTarget } = provider; let accountLink: string; if (type === RPC) { const blockExplorer = findBlockExplorerForRpc(rpcTarget, frequentRpcList) || NO_RPC_BLOCK_EXPLORER; accountLink = `${blockExplorer}/address/${address}`; } else { accountLink = getEtherscanAddressUrl(type, address); } navigation.navigate('Webview', { screen: 'SimpleWebview', params: { url: accountLink, }, }); }, [frequentRpcList, navigation, provider], ); return ( {strings('connect_qr_hardware.select_accounts')} `address-${item.index}`} renderItem={({ item }) => ( toggleAccount(item.index)} boxType={'square'} tintColors={{ true: colors.primary.default, false: colors.border.default, }} onCheckColor={colors.background.default} onFillColor={colors.primary.default} onTintColor={colors.primary.default} testID={'skip-backup-check'} /> )} /> {strings('connect_qr_hardware.prev')} {strings('connect_qr_hardware.next')} {strings('connect_qr_hardware.unlock')} {strings('connect_qr_hardware.forget')} ); }; export default SelectQRAccounts;