Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bdk_demo/lib/features/send/send_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:math' as math;
import 'package:bdk_demo/core/router/app_router.dart';
import 'package:bdk_demo/features/shared/widgets/secondary_app_bar.dart';
import 'package:bdk_demo/features/shared/widgets/wallet_ui_helpers.dart';
import 'package:bdk_demo/features/transactions/transactions_controller.dart';
import 'package:bdk_demo/providers/blockchain_providers.dart';
import 'package:bdk_demo/providers/connectivity_provider.dart';
import 'package:bdk_demo/providers/send_providers.dart';
Expand Down Expand Up @@ -351,6 +352,7 @@ class _SendPageState extends ConsumerState<SendPage> {
ref
.read(balanceSnapshotProvider.notifier)
.applyFromWallet(wallet, record.id);
ref.invalidate(transactionsControllerProvider(record.id));
_showSnackBar('Transaction broadcast successfully.');
context.go(AppRoutes.home);
} catch (_) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:bdk_demo/core/utils/formatters.dart';

class DemoTxDetails {
class TransactionHistoryItem {
final String txid;
final int sent;
final int received;
final bool pending;
final int? blockHeight;
final DateTime? confirmationTime;

const DemoTxDetails({
const TransactionHistoryItem({
required this.txid,
required this.sent,
required this.received,
Expand Down
33 changes: 26 additions & 7 deletions bdk_demo/lib/features/transactions/transaction_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import 'package:bdk_demo/core/theme/app_theme.dart';
import 'package:bdk_demo/core/utils/formatters.dart';
import 'package:bdk_demo/features/shared/widgets/secondary_app_bar.dart';
import 'package:bdk_demo/features/shared/widgets/wallet_ui_helpers.dart';
import 'package:bdk_demo/features/transactions/models/demo_tx_details.dart';
import 'package:bdk_demo/features/transactions/models/transaction_history_item.dart';
import 'package:bdk_demo/features/transactions/transactions_controller.dart';
import 'package:bdk_demo/models/currency_unit.dart';
import 'package:bdk_demo/providers/wallet_providers.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

Expand All @@ -13,7 +14,7 @@ class TransactionDetailPage extends ConsumerWidget {

const TransactionDetailPage({super.key, required this.txid});

String _formatAmount(DemoTxDetails transaction) {
String _formatAmount(TransactionHistoryItem transaction) {
final amount = transaction.netAmount;
final prefix = amount >= 0 ? '+' : '-';
final value = Formatters.formatBalance(amount.abs(), CurrencyUnit.satoshi);
Expand All @@ -28,7 +29,25 @@ class TransactionDetailPage extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context);
final transactionAsync = ref.watch(transactionDetailsProvider(txid));
final activeWalletId = ref.watch(activeWalletIdProvider);
final hasActiveWallet = ref.watch(hasActiveTransactionWalletProvider);
if (!hasActiveWallet) {
return const Scaffold(
appBar: SecondaryAppBar(title: 'Transaction Detail'),
body: SafeArea(
child: WalletStateCard(
icon: Icons.account_balance_wallet_outlined,
title: 'No active wallet',
message:
'Create or load a wallet before viewing transaction details.',
centered: true,
),
),
);
}
final transactionAsync = ref.watch(
transactionDetailsProvider((walletId: activeWalletId, txid: txid)),
);

return Scaffold(
appBar: const SecondaryAppBar(title: 'Transaction Detail'),
Expand All @@ -37,14 +56,14 @@ class TransactionDetailPage extends ConsumerWidget {
loading: () => const WalletStateCard(
icon: Icons.hourglass_bottom,
title: 'Loading transaction',
message: 'Preparing placeholder transaction details...',
message: 'Reading wallet transaction details...',
showSpinner: true,
centered: true,
),
error: (_, __) => WalletStateCard(
icon: Icons.error_outline,
title: 'Transaction unavailable',
message: 'The demo could not load placeholder transaction details.',
message: 'The wallet transaction details could not be loaded.',
accentColor: theme.colorScheme.error,
centered: true,
),
Expand All @@ -54,7 +73,7 @@ class TransactionDetailPage extends ConsumerWidget {
icon: Icons.search_off,
title: 'Transaction not found',
message:
'No placeholder transaction was found for this txid.\n\n$txid',
'No wallet transaction was found for this txid.\n\n$txid',
Comment on lines 74 to +76

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on detail, if there’s no active wallet the lookup comes back null, and we show the same “Transaction not found” card as for a missing txid... that makes it look like the tx is gone, when the issue is there’s no wallet loaded.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0986214. The detail page now shows a dedicated no-active-wallet state before starting the transaction lookup, with widget coverage that keeps it distinct from a missing txid.

centered: true,
);
}
Expand Down Expand Up @@ -83,7 +102,7 @@ class TransactionDetailPage extends ConsumerWidget {
),
const SizedBox(height: 8),
Text(
'Standalone transaction detail view for the selected placeholder transaction.',
'Transaction detail for the selected wallet transaction.',
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withAlpha(170),
),
Expand Down
50 changes: 50 additions & 0 deletions bdk_demo/lib/features/transactions/transaction_history_mapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:bdk_demo/features/transactions/models/transaction_history_item.dart';

sealed class TransactionHistoryPosition {
const TransactionHistoryPosition();
}

class ConfirmedTransactionPosition extends TransactionHistoryPosition {
final int blockHeight;
final int confirmationTime;

const ConfirmedTransactionPosition({
required this.blockHeight,
required this.confirmationTime,
});
}

class UnconfirmedTransactionPosition extends TransactionHistoryPosition {
const UnconfirmedTransactionPosition();
}

class TransactionHistoryMapper {
const TransactionHistoryMapper._();

static TransactionHistoryItem fromWalletData({
required String txid,
required int sent,
required int received,
required TransactionHistoryPosition position,
}) {
return switch (position) {
ConfirmedTransactionPosition() => TransactionHistoryItem(
txid: txid,
sent: sent,
received: received,
pending: false,
blockHeight: position.blockHeight,
confirmationTime: DateTime.fromMillisecondsSinceEpoch(
position.confirmationTime * 1000,
isUtc: true,
),
),
UnconfirmedTransactionPosition() => TransactionHistoryItem(
txid: txid,
sent: sent,
received: received,
pending: true,
),
};
}
}
Loading
Loading