forked from SatoshiPortal/bullbitcoin-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpay_wallet_selection_screen.dart
More file actions
118 lines (110 loc) · 4.12 KB
/
Copy pathpay_wallet_selection_screen.dart
File metadata and controls
118 lines (110 loc) · 4.12 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import 'package:bb_mobile/core/themes/app_theme.dart';
import 'package:bb_mobile/core/utils/build_context_x.dart';
import 'package:bb_mobile/core/widgets/loading/fading_linear_progress.dart';
import 'package:bb_mobile/core/widgets/scrollable_column.dart';
import 'package:bb_mobile/features/bitcoin_price/presentation/bloc/bitcoin_price_bloc.dart';
import 'package:bb_mobile/features/pay/presentation/pay_bloc.dart';
import 'package:bb_mobile/features/pay/ui/pay_router.dart';
import 'package:bb_mobile/features/wallet/ui/widgets/wallet_cards.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.dart';
import 'package:go_router/go_router.dart';
class PayWalletSelectionScreen extends StatelessWidget {
const PayWalletSelectionScreen({super.key});
@override
Widget build(BuildContext context) {
// Update BitcoinPriceBloc currency to match pay flow currency
WidgetsBinding.instance.addPostFrameCallback((_) {
final currency = context.read<PayBloc>().state.currency;
context.read<BitcoinPriceBloc>().add(
BitcoinPriceCurrencyChanged(currencyCode: currency.code),
);
});
final isCreatingPayOrder = context.select(
(PayBloc bloc) =>
bloc.state is PayWalletSelectionState &&
(bloc.state as PayWalletSelectionState).isCreatingPayOrder,
);
final currency = context.select((PayBloc bloc) => bloc.state.currency);
return Scaffold(
appBar: AppBar(title: Text(context.loc.paySelectWallet)),
body: SafeArea(
child: Column(
children: [
FadingLinearProgress(
height: 3,
trigger: isCreatingPayOrder,
backgroundColor: context.appColors.onPrimary,
foregroundColor: context.appColors.primary,
),
Expanded(
child: ScrollableColumn(
children: [
const Gap(24.0),
Text(
context.loc.payWhichWallet,
style: context.font.labelMedium?.copyWith(
color: context.appColors.text,
),
),
const Gap(24.0),
WalletCards(
padding: EdgeInsets.zero,
onTap:
isCreatingPayOrder
? null
: (wallet) => context.read<PayBloc>().add(
PayEvent.walletSelected(wallet: wallet),
),
localSignersOnly: true,
fiatCurrency: currency.code,
),
const Gap(24.0),
ListTile(
tileColor: context.appColors.onPrimary,
shape: const Border(),
title: Text(context.loc.payExternalWallet),
subtitle: Text(context.loc.payExternalWalletDescription),
trailing: const Icon(Icons.chevron_right),
onTap:
isCreatingPayOrder
? null
: () => context.pushNamed(
PayRoute.payExternalWalletNetworkSelection.name,
extra: context.read<PayBloc>(),
),
),
const Gap(24.0),
const _PayError(),
],
),
),
],
),
),
);
}
}
class _PayError extends StatelessWidget {
const _PayError();
@override
Widget build(BuildContext context) {
final payError = context.select(
(PayBloc bloc) =>
bloc.state is PayWalletSelectionState
? (bloc.state as PayWalletSelectionState).error
: null,
);
if (payError == null) return const SizedBox.shrink();
return Center(
child: Text(
payError.toTranslated(context),
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: TextAlign.center,
),
);
}
}