import React from 'react'; import { format } from 'date-fns'; import Typography from '../../ui/Typography'; import { FiClock, FiCheckCircle, FiAlertTriangle, FiInfo, } from 'react-icons/fi'; import { cn } from '../../../lib/utils'; import { type ParsedTransaction } from '../../../types/transaction'; import { TransactionDetails } from '../TransactionDetails'; interface TransactionContentProps { isLoadingDetails: boolean; transactionDetails: ParsedTransaction | null; expirationTime: string | null; description: string; scheduleId: string; network: string; isAlreadyExecuted?: boolean; executedTimestamp?: string | null; notes?: string[]; isScheduleExpired?: boolean; scheduleAge?: number | null; } const getValidAmount = (amount: string | number | unknown): number => { if (typeof amount === 'string') { return parseFloat(amount.replace(/[^\d.-]/g, '')); } if (typeof amount === 'number') { return amount; } return 0; }; /** * Displays the main content of a transaction approval, including header, details, and transaction information */ export const TransactionContent: React.FC = ({ isLoadingDetails, transactionDetails, expirationTime, description, scheduleId, network, isAlreadyExecuted, executedTimestamp, notes, isScheduleExpired, scheduleAge, }) => { const formatExecutedAt = (timestamp: string): string => { if (!timestamp) return ''; try { const asSeconds = Number(timestamp); const date = isNaN(asSeconds) ? new Date(timestamp) : new Date(asSeconds * 1000); return format(date, 'PPpp'); } catch { return timestamp; } }; return (
{/* Header Section */}
{(() => { if (isAlreadyExecuted) { return ; } if (isScheduleExpired) { return ; } return ; })()} {!isAlreadyExecuted && !isScheduleExpired && !isLoadingDetails ? (
) : null}

{(() => { if (isAlreadyExecuted) return 'Transaction Executed'; if (isScheduleExpired) return 'Transaction Expired'; return 'Transaction Approval Required'; })()}

{(() => { if (isAlreadyExecuted) { return `Executed ${ executedTimestamp ? formatExecutedAt(executedTimestamp) : 'successfully' }`; } if (isScheduleExpired) { return `This scheduled transaction expired after ${scheduleAge}`; } return ( description || transactionDetails?.humanReadableType || 'Review and approve the transaction details below' ); })()}

{isScheduleExpired && scheduleId && (

Schedule ID {scheduleId} exists on the network but can no longer be executed

)} {/* Notes Section */} {notes && notes.length > 0 && (
{notes.map((note: string, index: number) => (

{note}

))}
)}
{/* Transaction Details Section */} {isLoadingDetails ? (

Loading transaction details...

) : transactionDetails ? ( (() => { const transfers = Array.isArray(transactionDetails.transfers) ? transactionDetails.transfers : []; const hbarTransfersForDisplay = transfers.map((t) => ({ ...t, amount: getValidAmount(t.amount), })); const tokenTransfers = Array.isArray( transactionDetails.tokenTransfers ) ? transactionDetails.tokenTransfers : []; const tokenTransfersForDisplay = tokenTransfers.map( (tokenTransfer) => ({ tokenId: tokenTransfer.tokenId, accountId: tokenTransfer.accountId, amount: getValidAmount(tokenTransfer.amount), }) ); return ( ); })() ) : null}
); };