-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathbuy_accelerate_screen.dart
More file actions
140 lines (135 loc) · 5.29 KB
/
Copy pathbuy_accelerate_screen.dart
File metadata and controls
140 lines (135 loc) · 5.29 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import 'package:bb_mobile/core/settings/domain/settings_entity.dart';
import 'package:bb_mobile/core/themes/app_theme.dart';
import 'package:bb_mobile/core/utils/amount_conversions.dart';
import 'package:bb_mobile/core/utils/amount_formatting.dart';
import 'package:bb_mobile/core/utils/build_context_x.dart';
import 'package:bb_mobile/core/widgets/buttons/button.dart';
import 'package:bb_mobile/features/buy/presentation/buy_bloc.dart';
import 'package:bb_mobile/features/buy/ui/widgets/buy_confirm_detail_row.dart';
import 'package:bb_mobile/features/settings/presentation/bloc/settings_cubit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.dart';
class BuyAccelerateScreen extends StatelessWidget {
const BuyAccelerateScreen({super.key});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final isAcceleratingOrder = context.select(
(BuyBloc bloc) => bloc.state.isAcceleratingOrder,
);
final fees = context.select(
(BuyBloc bloc) => bloc.state.accelerationNetworkFees,
);
final relativeFee = fees?.fastest.value as double?;
final formattedRelativeFee =
relativeFee != null ? '${relativeFee.toStringAsFixed(2)} sat/vB' : null;
final absoluteFee = fees?.toAbsolute(140).fastest.value as int?;
final bitcoinUnit = context.select(
(SettingsCubit cubit) => cubit.state.bitcoinUnit,
);
final formattedAbsoluteFee =
absoluteFee != null && bitcoinUnit != null
? bitcoinUnit == BitcoinUnit.sats
? FormatAmount.sats(absoluteFee)
: FormatAmount.btc(ConvertAmount.satsToBtc(absoluteFee))
: null;
final currencyCode = context.select(
(BuyBloc bloc) => bloc.state.buyOrder?.payinCurrency,
);
final exchangeRate = context.select(
(BuyBloc bloc) => bloc.state.exchangeRate,
);
final absoluteFeeFiatEstimate =
absoluteFee != null && exchangeRate > 0
? ConvertAmount.satsToFiat(absoluteFee, exchangeRate)
: null;
final formattedFeeFiatEstimate =
absoluteFeeFiatEstimate != null && currencyCode != null
? FormatAmount.fiat(absoluteFeeFiatEstimate, currencyCode)
: null;
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, _) {
if (didPop) return; // Don't allow back navigation
Navigator.of(context, rootNavigator: true).pop();
},
child: Scaffold(
appBar: AppBar(title: Text(context.loc.buyConfirmExpressWithdrawal)),
body: SafeArea(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: .start,
children: [
const SizedBox(height: 16),
Text(
context.loc.buyNetworkFeeExplanation,
textAlign: .center,
style: theme.textTheme.bodyMedium?.copyWith(
color: context.appColors.text,
),
),
const SizedBox(height: 32),
BuyConfirmDetailRow(
label: context.loc.buyNetworkFees,
value: formattedAbsoluteFee,
),
BuyConfirmDetailRow(
label: context.loc.buyEstimatedFeeValue,
value: formattedFeeFiatEstimate,
),
BuyConfirmDetailRow(
label: context.loc.buyNetworkFeeRate,
value: formattedRelativeFee,
),
BuyConfirmDetailRow(
label: context.loc.buyConfirmationTime,
value: context.loc.buyConfirmationTimeValue,
),
const SizedBox(height: 32),
],
),
),
),
),
bottomNavigationBar: SafeArea(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: .min,
children: [
if (isAcceleratingOrder)
const Center(child: CircularProgressIndicator())
else
BBButton.big(
label: context.loc.buyWaitForFreeWithdrawal,
onPressed: () {
Navigator.of(context, rootNavigator: true).pop();
},
bgColor: context.appColors.surface,
textColor: context.appColors.secondary,
outlined: true,
borderColor: context.appColors.border,
),
const Gap(16),
BBButton.big(
label: context.loc.buyConfirmExpress,
disabled: isAcceleratingOrder,
onPressed: () {
context.read<BuyBloc>().add(
const BuyEvent.accelerateTransactionConfirmed(),
);
},
bgColor: context.appColors.secondary,
textColor: context.appColors.onSecondary,
),
],
),
),
),
),
);
}
}