import React, { useCallback } from 'react'; import { View, StyleSheet, ViewStyle, TouchableOpacity } 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'; 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; state: { wallets: TWallet[]; searchQuery: string }; navigateToWallet: (wallet: TWallet) => void; renderHighlightedText: (text: string, query: string) => JSX.Element; handleDeleteWallet: (wallet: TWallet) => void; handleToggleHideBalance: (wallet: TWallet) => void; } 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, }) => { const { colors } = useTheme(); const onPress = useCallback(() => { if (item.type === ItemType.WalletSection) { navigateToWallet(item.data); } }, [item, navigateToWallet]); const leftContent = useCallback( (reset: () => void) => ( { handleToggleHideBalance(item.data as TWallet); reset(); }} hideBalance={(item.data as TWallet).hideBalance} colors={colors} /> ), [colors, handleToggleHideBalance, item.data], ); const rightContent = useCallback( (reset: () => void) => ( { handleDeleteWallet(item.data as TWallet); reset(); }} /> ), [handleDeleteWallet, item.data], ); 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 ( ); } console.error('Unrecognized item type:', item); 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', }, }); export { ManageWalletsListItem, LeftSwipeContent, RightSwipeContent };