|
| 1 | +import 'package:bdk_demo/core/theme/app_theme.dart'; |
| 2 | +import 'package:bdk_demo/core/utils/formatters.dart'; |
| 3 | +import 'package:bdk_demo/features/shared/widgets/secondary_app_bar.dart'; |
| 4 | +import 'package:bdk_demo/features/shared/widgets/wallet_ui_helpers.dart'; |
| 5 | +import 'package:bdk_demo/features/transactions/models/demo_tx_details.dart'; |
| 6 | +import 'package:bdk_demo/features/transactions/transactions_controller.dart'; |
| 7 | +import 'package:bdk_demo/models/currency_unit.dart'; |
| 8 | +import 'package:flutter/material.dart'; |
| 9 | +import 'package:flutter_riverpod/flutter_riverpod.dart'; |
| 10 | + |
| 11 | +class TransactionDetailPage extends ConsumerWidget { |
| 12 | + final String txid; |
| 13 | + |
| 14 | + const TransactionDetailPage({super.key, required this.txid}); |
| 15 | + |
| 16 | + String _formatAmount(DemoTxDetails transaction) { |
| 17 | + final amount = transaction.netAmount; |
| 18 | + final prefix = amount >= 0 ? '+' : '-'; |
| 19 | + final value = Formatters.formatBalance(amount.abs(), CurrencyUnit.satoshi); |
| 20 | + return '$prefix$value'; |
| 21 | + } |
| 22 | + |
| 23 | + String _formatTimestamp(DateTime timestamp) { |
| 24 | + final unixSeconds = timestamp.millisecondsSinceEpoch ~/ 1000; |
| 25 | + return Formatters.formatTimestamp(unixSeconds); |
| 26 | + } |
| 27 | + |
| 28 | + @override |
| 29 | + Widget build(BuildContext context, WidgetRef ref) { |
| 30 | + final theme = Theme.of(context); |
| 31 | + final transactionAsync = ref.watch(transactionDetailsProvider(txid)); |
| 32 | + |
| 33 | + return Scaffold( |
| 34 | + appBar: const SecondaryAppBar(title: 'Transaction Detail'), |
| 35 | + body: SafeArea( |
| 36 | + child: transactionAsync.when( |
| 37 | + loading: () => const WalletStateCard( |
| 38 | + icon: Icons.hourglass_bottom, |
| 39 | + title: 'Loading transaction', |
| 40 | + message: 'Preparing placeholder transaction details...', |
| 41 | + showSpinner: true, |
| 42 | + centered: true, |
| 43 | + ), |
| 44 | + error: (_, __) => WalletStateCard( |
| 45 | + icon: Icons.error_outline, |
| 46 | + title: 'Transaction unavailable', |
| 47 | + message: 'The demo could not load placeholder transaction details.', |
| 48 | + accentColor: theme.colorScheme.error, |
| 49 | + centered: true, |
| 50 | + ), |
| 51 | + data: (transaction) { |
| 52 | + if (transaction == null) { |
| 53 | + return WalletStateCard( |
| 54 | + icon: Icons.search_off, |
| 55 | + title: 'Transaction not found', |
| 56 | + message: |
| 57 | + 'No placeholder transaction was found for this txid.\n\n$txid', |
| 58 | + centered: true, |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + return ListView( |
| 63 | + padding: const EdgeInsets.all(24), |
| 64 | + children: [ |
| 65 | + Card( |
| 66 | + child: Padding( |
| 67 | + padding: const EdgeInsets.all(20), |
| 68 | + child: Column( |
| 69 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 70 | + children: [ |
| 71 | + Row( |
| 72 | + children: [ |
| 73 | + Expanded( |
| 74 | + child: Text( |
| 75 | + _formatAmount(transaction), |
| 76 | + style: theme.textTheme.headlineSmall?.copyWith( |
| 77 | + fontWeight: FontWeight.w700, |
| 78 | + ), |
| 79 | + ), |
| 80 | + ), |
| 81 | + WalletStatusChip(status: transaction.statusLabel), |
| 82 | + ], |
| 83 | + ), |
| 84 | + const SizedBox(height: 8), |
| 85 | + Text( |
| 86 | + 'Standalone transaction detail view for the selected placeholder transaction.', |
| 87 | + style: theme.textTheme.bodyMedium?.copyWith( |
| 88 | + color: theme.colorScheme.onSurface.withAlpha(170), |
| 89 | + ), |
| 90 | + ), |
| 91 | + ], |
| 92 | + ), |
| 93 | + ), |
| 94 | + ), |
| 95 | + const SizedBox(height: 24), |
| 96 | + Card( |
| 97 | + child: Padding( |
| 98 | + padding: const EdgeInsets.all(20), |
| 99 | + child: Column( |
| 100 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 101 | + children: [ |
| 102 | + Text( |
| 103 | + 'Full txid', |
| 104 | + style: theme.textTheme.labelLarge?.copyWith( |
| 105 | + color: theme.colorScheme.onSurface.withAlpha(170), |
| 106 | + ), |
| 107 | + ), |
| 108 | + const SizedBox(height: 8), |
| 109 | + SelectableText( |
| 110 | + transaction.txid, |
| 111 | + style: AppTheme.monoStyle.copyWith( |
| 112 | + fontSize: 13, |
| 113 | + color: theme.colorScheme.onSurface, |
| 114 | + ), |
| 115 | + ), |
| 116 | + ], |
| 117 | + ), |
| 118 | + ), |
| 119 | + ), |
| 120 | + const SizedBox(height: 24), |
| 121 | + Card( |
| 122 | + child: Padding( |
| 123 | + padding: const EdgeInsets.all(20), |
| 124 | + child: Column( |
| 125 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 126 | + children: [ |
| 127 | + WalletDetailRow( |
| 128 | + label: 'Amount', |
| 129 | + value: _formatAmount(transaction), |
| 130 | + ), |
| 131 | + const SizedBox(height: 12), |
| 132 | + WalletDetailRow( |
| 133 | + label: 'Status', |
| 134 | + value: transaction.statusLabel, |
| 135 | + ), |
| 136 | + if (transaction.blockHeight != null) ...[ |
| 137 | + const SizedBox(height: 12), |
| 138 | + WalletDetailRow( |
| 139 | + label: 'Block height', |
| 140 | + value: '${transaction.blockHeight}', |
| 141 | + ), |
| 142 | + ], |
| 143 | + if (transaction.confirmationTime != null) ...[ |
| 144 | + const SizedBox(height: 12), |
| 145 | + WalletDetailRow( |
| 146 | + label: 'Timestamp', |
| 147 | + value: _formatTimestamp( |
| 148 | + transaction.confirmationTime!, |
| 149 | + ), |
| 150 | + ), |
| 151 | + ], |
| 152 | + ], |
| 153 | + ), |
| 154 | + ), |
| 155 | + ), |
| 156 | + ], |
| 157 | + ); |
| 158 | + }, |
| 159 | + ), |
| 160 | + ), |
| 161 | + ); |
| 162 | + } |
| 163 | +} |
0 commit comments