-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathreceive_page.dart
More file actions
88 lines (84 loc) · 3.14 KB
/
Copy pathreceive_page.dart
File metadata and controls
88 lines (84 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import 'package:bdk_demo/features/receive/receive_address_card.dart';
import 'package:bdk_demo/features/receive/receive_error_panel.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/models/wallet_record.dart';
import 'package:bdk_demo/providers/address_providers.dart';
import 'package:bdk_demo/providers/wallet_providers.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
class ReceivePage extends ConsumerWidget {
const ReceivePage({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final record = ref.watch(activeWalletRecordProvider);
final receiveState = ref.watch(currentReceiveAddressProvider);
return Scaffold(
appBar: const SecondaryAppBar(title: 'Receive'),
body: SafeArea(
child: record == null
? const WalletStateCard(
icon: Icons.account_balance_wallet_outlined,
title: 'No active wallet',
message: 'Load a wallet before generating a receive address.',
centered: true,
)
: _buildWalletContent(context, ref, record, receiveState),
),
);
}
Widget _buildWalletContent(
BuildContext context,
WidgetRef ref,
WalletRecord record,
ReceiveAddressState receiveState,
) {
return ListView(
padding: const EdgeInsets.all(24),
children: [
Text(
'Receive on ${record.network.displayName}',
style: Theme.of(
context,
).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.w700),
),
const SizedBox(height: 6),
Text(record.name, style: Theme.of(context).textTheme.bodyMedium),
const SizedBox(height: 20),
if (receiveState.address case final address?)
ReceiveAddressCard(address: address, index: receiveState.index)
else
WalletStateCard(
icon: Icons.qr_code_2,
title: receiveState.isGenerating
? 'Generating address'
: 'Ready to receive',
message: receiveState.isGenerating
? 'Revealing and saving the next external address.'
: 'Generate a fresh external address for this wallet.',
showSpinner: receiveState.isGenerating,
),
if (receiveState.errorMessage case final error?) ...[
const SizedBox(height: 12),
ReceiveErrorPanel(message: error),
],
const SizedBox(height: 20),
FilledButton.icon(
onPressed: receiveState.isGenerating
? null
: () => ref
.read(currentReceiveAddressProvider.notifier)
.generateForActiveWallet(),
icon: const Icon(Icons.add_location_alt_outlined),
label: Text(
receiveState.address != null
? 'Generate new address'
: receiveState.errorMessage != null
? 'Try again'
: 'Generate address',
),
),
],
);
}
}