import React, { useCallback, useMemo } from "react"; import { Center, HStack, Pressable, ScrollView, Text, VStack, Box, Spinner } from "native-base"; import { Platform } from "react-native"; import moment from "moment"; import { withTheme } from "../../../theme/hoc"; import { Image, SvgXml } from "../../../core/images"; import { getBridgeNetworkIcon } from "../../../utils/icons"; import type { BridgeTransaction } from "./types"; export type BridgeTransactionCardProps = { transaction: BridgeTransaction; onTxDetailsPress?: (transaction: BridgeTransaction) => void; }; export const BridgeTransactionCard = withTheme({ name: "BridgeTransactionCard" })( ({ transaction, onTxDetailsPress }: BridgeTransactionCardProps) => { const { amount, bridgeProvider, status, date, sourceChain, targetChain } = transaction; const openTransactionDetails = useCallback(() => { onTxDetailsPress?.(transaction); }, [transaction, onTxDetailsPress]); const txDate = date ? moment(date).local().format?.("MM.DD.YYYY HH:mm") : "Unknown"; const colorAmount = status === "failed" ? "goodRed.500" : "txGreen"; const amountPrefix = status === "failed" ? "" : "+"; const sourceChainIcon = useMemo(() => getBridgeNetworkIcon(sourceChain), [sourceChain]); const targetChainIcon = useMemo(() => getBridgeNetworkIcon(targetChain), [targetChain]); const getChainInitial = useCallback((chain: string) => { return chain.charAt(0).toUpperCase(); }, []); const providerLabel = bridgeProvider === "axelar" ? "Axelar" : "LayerZero"; const providerColor = bridgeProvider === "axelar" ? "goodBlue.600" : "goodBlue.500"; const getStatusIcon = useCallback(() => { switch (status) { case "bridging": return ( ); case "completed": return ( ); case "failed": return ( ); case "pending": return ( ); default: return null; } }, [status]); const getStatusText = useCallback(() => { switch (status) { case "bridging": return "Bridging in progress..."; case "completed": return "Bridge completed"; case "failed": return "Bridge failed"; case "pending": return "Pending confirmation"; default: return ""; } }, [status]); return ( Bridged via {providerLabel} {txDate} {amount && ( {amountPrefix} {amount} G$ )} {sourceChainIcon ? ( {sourceChain === "celo" ? ( ) : ( )} ) : ( {getChainInitial(sourceChain)} )} {targetChainIcon ? ( {targetChain === "celo" ? ( ) : ( )} ) : ( {getChainInitial(targetChain)} )} {sourceChain.charAt(0).toUpperCase() + sourceChain.slice(1)} →{" "} {targetChain.charAt(0).toUpperCase() + targetChain.slice(1)} {status !== "completed" && ( {getStatusText()} )}
{getStatusIcon()}
); } ); type BridgeTransactionListProps = { transactions: BridgeTransaction[] | undefined; onTxDetailsPress?: (transaction: BridgeTransaction) => void; limit?: number; }; export const BridgeTransactionList = ({ transactions, onTxDetailsPress, limit = 3 }: BridgeTransactionListProps) => ( {transactions?.map((tx: BridgeTransaction) => ( ))} );