import React, { useCallback, useState } from 'react'; import { View, StyleSheet, ViewStyle, TouchableOpacity, ActivityIndicator, Platform } from 'react-native'; import { Icon, ListItem } from '@rneui/base'; import { ExtendedTransaction, LightningTransaction, TWallet } from '../class/wallets/types'; import { WalletCarouselItem } from './WalletsCarousel'; import { TransactionListItem } from './TransactionListItem'; import { useTheme } from './themes'; import { BitcoinUnit } from '../models/bitcoinUnits'; import { TouchableOpacityWrapper } from './ListItem'; import loc from '../loc'; enum ItemType { WalletSection = 'wallet', TransactionSection = 'transaction', } interface WalletItem { type: ItemType.WalletSection; data: TWallet; } interface TransactionItem { type: ItemType.TransactionSection; data: ExtendedTransaction & LightningTransaction; } type Item = WalletItem | TransactionItem; interface ManageWalletsListItemProps { item: Item; isDraggingDisabled: boolean; drag?: () => void; isPlaceHolder?: boolean; onPressIn?: () => void; onPressOut?: () => void; state: { wallets: TWallet[]; searchQuery: string }; navigateToWallet: (wallet: TWallet) => void; renderHighlightedText: (text: string, query: string) => JSX.Element; handleDeleteWallet: (wallet: TWallet) => void; handleToggleHideBalance: (wallet: TWallet) => void; isActive?: boolean; style?: ViewStyle; } interface SwipeContentProps { onPress: () => void; hideBalance?: boolean; colors: any; } const LeftSwipeContent: React.FC = ({ onPress, hideBalance, colors }) => ( ); const RightSwipeContent: React.FC> = ({ onPress }) => ( ); const ManageWalletsListItem: React.FC = ({ item, isDraggingDisabled, drag, state, isPlaceHolder = false, navigateToWallet, renderHighlightedText, handleDeleteWallet, handleToggleHideBalance, onPressIn, onPressOut, isActive, style, }) => { const { colors } = useTheme(); const [isLoading, setIsLoading] = useState(false); const onPress = useCallback(() => { if (item.type === ItemType.WalletSection) { setIsLoading(true); navigateToWallet(item.data); setIsLoading(false); } }, [item, navigateToWallet]); const handleLeftPress = (reset: () => void) => { handleToggleHideBalance(item.data as TWallet); reset(); }; const leftContent = (reset: () => void) => ( handleLeftPress(reset)} hideBalance={(item.data as TWallet).hideBalance} colors={colors} /> ); const handleRightPress = (reset: () => void) => { handleDeleteWallet(item.data as TWallet); reset(); }; const rightContent = (reset: () => void) => handleRightPress(reset)} />; if (isLoading) { return ; } if (item.type === ItemType.WalletSection) { return ( ); } else if (item.type === ItemType.TransactionSection && item.data) { const w = state.wallets.find(wallet => wallet.getTransactions().some((tx: ExtendedTransaction) => tx.hash === item.data.hash)); const walletID = w ? w.getID() : ''; return ( ); } return null; }; const styles = StyleSheet.create({ walletCarouselItemContainer: { width: '100%', }, leftButtonContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', }, rightButtonContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'red', }, activeItem: { backgroundColor: 'rgba(0, 0, 0, 0.1)', }, }); export { LeftSwipeContent, RightSwipeContent }; export default ManageWalletsListItem;