import React, { useEffect, useRef, useContext, useState } from 'react'; import { View, Image, Text, StyleSheet, StatusBar, I18nManager, Pressable } from 'react-native'; import { BluePrivateBalance } from '../../BlueComponents'; import DraggableFlatList, { ScaleDecorator } from 'react-native-draggable-flatlist'; import LinearGradient from 'react-native-linear-gradient'; import ReactNativeHapticFeedback from 'react-native-haptic-feedback'; import { useTheme } from '@react-navigation/native'; import navigationStyle from '../../components/navigationStyle'; import { LightningCustodianWallet, LightningLdkWallet, MultisigHDWallet } from '../../class'; import WalletGradient from '../../class/wallet-gradient'; import loc, { formatBalance, transactionTimeToReadable } from '../../loc'; import { BlueStorageContext } from '../../blue_modules/storage-context'; const styles = StyleSheet.create({ loading: { flex: 1, paddingTop: 20, }, root: { flex: 1, }, itemRoot: { backgroundColor: 'transparent', padding: 10, }, gradient: { padding: 15, borderRadius: 10, minHeight: 164, elevation: 5, }, image: { width: 99, height: 94, position: 'absolute', bottom: 0, right: 0, }, transparentText: { backgroundColor: 'transparent', }, tip: { marginHorizontal: 16, borderRadius: 12, padding: 16, marginVertical: 24, }, label: { backgroundColor: 'transparent', fontSize: 19, color: '#fff', writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr', }, balance: { backgroundColor: 'transparent', fontWeight: 'bold', fontSize: 36, color: '#fff', writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr', }, latestTxLabel: { backgroundColor: 'transparent', fontSize: 13, color: '#fff', writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr', }, latestTxValue: { backgroundColor: 'transparent', fontWeight: 'bold', fontSize: 16, color: '#fff', writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr', }, }); const ReorderWallets = () => { const sortableList = useRef(); const { colors } = useTheme(); const { wallets, setWalletsWithNewOrder } = useContext(BlueStorageContext); const stylesHook = { root: { backgroundColor: colors.elevated, }, loading: { backgroundColor: colors.elevated, }, tip: { backgroundColor: colors.ballOutgoingExpired, }, }; const [walletData, setWalletData] = useState([]); useEffect(() => { setWalletData(wallets); }, [wallets]); const renderItem = ({ item, drag, isActive }) => { return ( { 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} {item.getTransactions().find(tx => tx.confirmations === 0) ? loc.transactions.pending.toLowerCase() : transactionTimeToReadable(item.getLatestTransactionTime())} ); }; const onChangeOrder = () => { ReactNativeHapticFeedback.trigger('impactMedium', { ignoreAndroidSystemSettings: false }); }; const onDragBegin = () => { ReactNativeHapticFeedback.trigger('selection', { ignoreAndroidSystemSettings: false }); }; const onRelease = () => { ReactNativeHapticFeedback.trigger('impactLight', { ignoreAndroidSystemSettings: false }); }; const onDragEnd = ({ data }) => { setWalletsWithNewOrder(data); setWalletData(data); }; const _keyExtractor = (_item, index) => index.toString(); const ListHeaderComponent = ( {loc.wallets.reorder_instructions} ); return ( ); }; ReorderWallets.navigationOptions = navigationStyle( { headerHideBackButton: true, headerLargeTitle: true, closeButton: true, }, opts => ({ ...opts, headerTitle: loc.wallets.reorder_title }), ); export default ReorderWallets;