-
Notifications
You must be signed in to change notification settings - Fork 9
feat: scaffold transaction presentation in bdk_demo active wallet flow #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
j-kon
wants to merge
8
commits into
bitcoindevkit:main
Choose a base branch
from
j-kon:feat/bdk-demo-transaction-scaffold
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,029
−15
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0e9986f
feat: scaffold transaction presentation in bdk_demo active wallet flow
j-kon c6fcca9
feat: add transaction detail flow with navigation and tests
j-kon bebb956
feat: enhance transaction detail page to refresh on txid change with …
j-kon 49ee27a
feat: refine wallet service imports and enhance active wallets page t…
j-kon 8c77d9d
fix: reformat wallet_service.dart for consistency
j-kon 380d1e0
chore: drop bdk_demo README changes from transaction scaffold PR
j-kon d46ca6e
refactor: share wallet UI helpers in bdk_demo
j-kon 5b46853
refactor: split bdk_demo transactions into standalone feature
j-kon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
bdk_demo/lib/features/shared/widgets/wallet_ui_helpers.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| import 'package:bdk_demo/core/theme/app_theme.dart'; | ||
|
|
||
| class WalletStateCard extends StatelessWidget { | ||
| final IconData icon; | ||
| final String title; | ||
| final String message; | ||
| final Color? accentColor; | ||
| final bool showSpinner; | ||
| final bool centered; | ||
|
|
||
| const WalletStateCard({ | ||
| super.key, | ||
| required this.icon, | ||
| required this.title, | ||
| required this.message, | ||
| this.accentColor, | ||
| this.showSpinner = false, | ||
| this.centered = false, | ||
| }); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| final theme = Theme.of(context); | ||
| final color = accentColor ?? theme.colorScheme.primary; | ||
|
|
||
| final card = Card( | ||
| child: Padding( | ||
| padding: const EdgeInsets.all(20), | ||
| child: Row( | ||
| crossAxisAlignment: CrossAxisAlignment.start, | ||
| children: [ | ||
| showSpinner | ||
| ? const SizedBox( | ||
| width: 20, | ||
| height: 20, | ||
| child: CircularProgressIndicator(strokeWidth: 2), | ||
| ) | ||
| : Icon(icon, color: color), | ||
| const SizedBox(width: 12), | ||
| Expanded( | ||
| child: Column( | ||
| crossAxisAlignment: CrossAxisAlignment.start, | ||
| mainAxisSize: MainAxisSize.min, | ||
| children: [ | ||
| Text( | ||
| title, | ||
| style: theme.textTheme.titleMedium?.copyWith( | ||
| fontWeight: FontWeight.w600, | ||
| ), | ||
| ), | ||
| const SizedBox(height: 6), | ||
| Text(message, style: theme.textTheme.bodyMedium), | ||
| ], | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| if (!centered) return card; | ||
|
|
||
| return Center( | ||
| child: Padding(padding: const EdgeInsets.all(24), child: card), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class WalletDetailRow extends StatelessWidget { | ||
| final String label; | ||
| final String value; | ||
| final bool monospace; | ||
|
|
||
| const WalletDetailRow({ | ||
| super.key, | ||
| required this.label, | ||
| required this.value, | ||
| this.monospace = false, | ||
| }); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| final theme = Theme.of(context); | ||
|
|
||
| return Column( | ||
| crossAxisAlignment: CrossAxisAlignment.start, | ||
| children: [ | ||
| Text( | ||
| label, | ||
| style: theme.textTheme.labelLarge?.copyWith( | ||
| color: theme.colorScheme.onSurface.withAlpha(170), | ||
| ), | ||
| ), | ||
| const SizedBox(height: 4), | ||
| Text( | ||
| value, | ||
| style: monospace | ||
| ? AppTheme.monoStyle.copyWith( | ||
| fontSize: 13, | ||
| color: theme.colorScheme.onSurface, | ||
| ) | ||
| : theme.textTheme.bodyLarge, | ||
| ), | ||
| ], | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class WalletStatusChip extends StatelessWidget { | ||
| final String status; | ||
|
|
||
| const WalletStatusChip({super.key, required this.status}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| final theme = Theme.of(context); | ||
| final isPending = status == 'pending'; | ||
|
|
||
| return Container( | ||
| padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6), | ||
| decoration: BoxDecoration( | ||
| borderRadius: BorderRadius.circular(999), | ||
| color: isPending | ||
| ? theme.colorScheme.secondaryContainer | ||
| : theme.colorScheme.primaryContainer, | ||
| ), | ||
| child: Text( | ||
| status, | ||
| style: theme.textTheme.labelMedium?.copyWith( | ||
| color: isPending | ||
| ? theme.colorScheme.onSecondaryContainer | ||
| : theme.colorScheme.onPrimaryContainer, | ||
| fontWeight: FontWeight.w600, | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } |
16 changes: 7 additions & 9 deletions
16
bdk_demo/lib/models/tx_details.dart → .../transactions/models/demo_tx_details.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,25 @@ | ||
| class TxDetails { | ||
| import 'package:bdk_demo/core/utils/formatters.dart'; | ||
|
|
||
| class DemoTxDetails { | ||
| final String txid; | ||
| final int sent; | ||
| final int received; | ||
| final int fee; | ||
| final double? feeRate; | ||
| final bool pending; | ||
| final int? blockHeight; | ||
| final DateTime? confirmationTime; | ||
|
|
||
| const TxDetails({ | ||
| const DemoTxDetails({ | ||
| required this.txid, | ||
| required this.sent, | ||
| required this.received, | ||
| this.fee = 0, | ||
| this.feeRate, | ||
| this.pending = true, | ||
| this.blockHeight, | ||
| this.confirmationTime, | ||
| }); | ||
|
|
||
| int get netAmount => received - sent; | ||
|
|
||
| String get shortTxid => txid.length > 16 | ||
| ? '${txid.substring(0, 8)}...${txid.substring(txid.length - 8)}' | ||
| : txid; | ||
| String get shortTxid => Formatters.abbreviateTxid(txid); | ||
|
|
||
| String get statusLabel => pending ? 'pending' : 'confirmed'; | ||
| } |
163 changes: 163 additions & 0 deletions
163
bdk_demo/lib/features/transactions/transaction_detail_page.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| 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/transactions_controller.dart'; | ||
| import 'package:bdk_demo/models/currency_unit.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
|
||
| class TransactionDetailPage extends ConsumerWidget { | ||
| final String txid; | ||
|
|
||
| const TransactionDetailPage({super.key, required this.txid}); | ||
|
|
||
| String _formatAmount(DemoTxDetails transaction) { | ||
| final amount = transaction.netAmount; | ||
| final prefix = amount >= 0 ? '+' : '-'; | ||
| final value = Formatters.formatBalance(amount.abs(), CurrencyUnit.satoshi); | ||
| return '$prefix$value'; | ||
| } | ||
|
|
||
| String _formatTimestamp(DateTime timestamp) { | ||
| final unixSeconds = timestamp.millisecondsSinceEpoch ~/ 1000; | ||
| return Formatters.formatTimestamp(unixSeconds); | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context, WidgetRef ref) { | ||
| final theme = Theme.of(context); | ||
| final transactionAsync = ref.watch(transactionDetailsProvider(txid)); | ||
|
|
||
| return Scaffold( | ||
| appBar: const SecondaryAppBar(title: 'Transaction Detail'), | ||
| body: SafeArea( | ||
| child: transactionAsync.when( | ||
| loading: () => const WalletStateCard( | ||
| icon: Icons.hourglass_bottom, | ||
| title: 'Loading transaction', | ||
| message: 'Preparing placeholder transaction details...', | ||
| showSpinner: true, | ||
| centered: true, | ||
| ), | ||
| error: (_, __) => WalletStateCard( | ||
| icon: Icons.error_outline, | ||
| title: 'Transaction unavailable', | ||
| message: 'The demo could not load placeholder transaction details.', | ||
| accentColor: theme.colorScheme.error, | ||
| centered: true, | ||
| ), | ||
| data: (transaction) { | ||
| if (transaction == null) { | ||
| return WalletStateCard( | ||
| icon: Icons.search_off, | ||
| title: 'Transaction not found', | ||
| message: | ||
| 'No placeholder transaction was found for this txid.\n\n$txid', | ||
| centered: true, | ||
| ); | ||
| } | ||
|
|
||
| return ListView( | ||
| padding: const EdgeInsets.all(24), | ||
| children: [ | ||
| Card( | ||
| child: Padding( | ||
| padding: const EdgeInsets.all(20), | ||
| child: Column( | ||
| crossAxisAlignment: CrossAxisAlignment.start, | ||
| children: [ | ||
| Row( | ||
| children: [ | ||
| Expanded( | ||
| child: Text( | ||
| _formatAmount(transaction), | ||
| style: theme.textTheme.headlineSmall?.copyWith( | ||
| fontWeight: FontWeight.w700, | ||
| ), | ||
| ), | ||
| ), | ||
| WalletStatusChip(status: transaction.statusLabel), | ||
| ], | ||
| ), | ||
| const SizedBox(height: 8), | ||
| Text( | ||
| 'Standalone transaction detail view for the selected placeholder transaction.', | ||
| style: theme.textTheme.bodyMedium?.copyWith( | ||
| color: theme.colorScheme.onSurface.withAlpha(170), | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ), | ||
| const SizedBox(height: 24), | ||
| Card( | ||
| child: Padding( | ||
| padding: const EdgeInsets.all(20), | ||
| child: Column( | ||
| crossAxisAlignment: CrossAxisAlignment.start, | ||
| children: [ | ||
| Text( | ||
| 'Full txid', | ||
| style: theme.textTheme.labelLarge?.copyWith( | ||
| color: theme.colorScheme.onSurface.withAlpha(170), | ||
| ), | ||
| ), | ||
| const SizedBox(height: 8), | ||
| SelectableText( | ||
| transaction.txid, | ||
| style: AppTheme.monoStyle.copyWith( | ||
| fontSize: 13, | ||
| color: theme.colorScheme.onSurface, | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ), | ||
| const SizedBox(height: 24), | ||
| Card( | ||
| child: Padding( | ||
| padding: const EdgeInsets.all(20), | ||
| child: Column( | ||
| crossAxisAlignment: CrossAxisAlignment.start, | ||
| children: [ | ||
| WalletDetailRow( | ||
| label: 'Amount', | ||
| value: _formatAmount(transaction), | ||
| ), | ||
| const SizedBox(height: 12), | ||
| WalletDetailRow( | ||
| label: 'Status', | ||
| value: transaction.statusLabel, | ||
| ), | ||
| if (transaction.blockHeight != null) ...[ | ||
| const SizedBox(height: 12), | ||
| WalletDetailRow( | ||
| label: 'Block height', | ||
| value: '${transaction.blockHeight}', | ||
| ), | ||
| ], | ||
| if (transaction.confirmationTime != null) ...[ | ||
| const SizedBox(height: 12), | ||
| WalletDetailRow( | ||
| label: 'Timestamp', | ||
| value: _formatTimestamp( | ||
| transaction.confirmationTime!, | ||
| ), | ||
| ), | ||
| ], | ||
| ], | ||
| ), | ||
| ), | ||
| ), | ||
| ], | ||
| ); | ||
| }, | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.