Skip to content

Commit 2d3e933

Browse files
committed
feat: enhance transaction detail page to refresh on txid change with tests
1 parent a7798fd commit 2d3e933

2 files changed

Lines changed: 72 additions & 4 deletions

File tree

bdk_demo/lib/features/wallet_setup/transaction_detail_page.dart

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,29 @@ class TransactionDetailPage extends ConsumerStatefulWidget {
1919
}
2020

2121
class _TransactionDetailPageState extends ConsumerState<TransactionDetailPage> {
22-
late final Future<TxDetails?> _transactionFuture;
22+
late Future<TxDetails?> _transactionFuture;
2323

24-
@override
25-
void initState() {
26-
super.initState();
24+
void _loadTransactionFuture() {
2725
_transactionFuture = ref
2826
.read(walletServiceProvider)
2927
.loadTransactionByTxid(widget.txid);
3028
}
3129

30+
@override
31+
void initState() {
32+
super.initState();
33+
_loadTransactionFuture();
34+
}
35+
36+
@override
37+
void didUpdateWidget(covariant TransactionDetailPage oldWidget) {
38+
super.didUpdateWidget(oldWidget);
39+
40+
if (oldWidget.txid != widget.txid) {
41+
_loadTransactionFuture();
42+
}
43+
}
44+
3245
String _formatAmount(TxDetails transaction) {
3346
final amount = transaction.netAmount;
3447
final prefix = amount >= 0 ? '+' : '-';

bdk_demo/test/widget_test.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,61 @@ void main() {
190190
},
191191
);
192192

193+
testWidgets('Transaction detail page refreshes when txid changes', (
194+
tester,
195+
) async {
196+
final fakeWalletService = FakeWalletService(
197+
walletInfo: _testWalletInfo,
198+
transactions: _placeholderTransactions,
199+
);
200+
201+
Future<void> pumpDetail(String txid) async {
202+
await tester.pumpWidget(
203+
ProviderScope(
204+
overrides: [
205+
walletServiceProvider.overrideWithValue(fakeWalletService),
206+
],
207+
child: MaterialApp(
208+
home: TransactionDetailPage(
209+
key: const ValueKey('detail-page'),
210+
txid: txid,
211+
),
212+
),
213+
),
214+
);
215+
}
216+
217+
await pumpDetail(_placeholderTransactions.first.txid);
218+
await tester.pumpAndSettle();
219+
220+
expect(
221+
find.text(
222+
'1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcd',
223+
),
224+
findsOneWidget,
225+
);
226+
expect(find.text('January 2 2024 03:04'), findsOneWidget);
227+
228+
await pumpDetail(_placeholderTransactions.last.txid);
229+
await tester.pumpAndSettle();
230+
231+
expect(
232+
find.text(
233+
'abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
234+
),
235+
findsOneWidget,
236+
);
237+
expect(find.text('-1600 sat'), findsNWidgets(2));
238+
expect(find.text('pending'), findsNWidgets(2));
239+
expect(
240+
find.text(
241+
'1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcd',
242+
),
243+
findsNothing,
244+
);
245+
expect(find.text('January 2 2024 03:04'), findsNothing);
246+
});
247+
193248
testWidgets('Transaction detail page handles a missing tx gracefully', (
194249
tester,
195250
) async {

0 commit comments

Comments
 (0)