-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathwithdraw_confirmation_screen.dart
More file actions
268 lines (251 loc) · 8.97 KB
/
Copy pathwithdraw_confirmation_screen.dart
File metadata and controls
268 lines (251 loc) · 8.97 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
import 'package:bb_mobile/core/themes/app_theme.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/core/widgets/loading/fading_linear_progress.dart';
import 'package:bb_mobile/core/widgets/loading/loading_line_content.dart';
import 'package:bb_mobile/core/widgets/scrollable_column.dart';
import 'package:bb_mobile/features/recipients/domain/value_objects/recipient_type.dart';
import 'package:bb_mobile/features/recipients/interface_adapters/presenters/models/recipient_view_model.dart';
import 'package:bb_mobile/features/withdraw/presentation/withdraw_bloc.dart';
import 'package:bb_mobile/generated/flutter_gen/assets.gen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.dart';
class WithdrawConfirmationScreen extends StatelessWidget {
const WithdrawConfirmationScreen({super.key});
@override
Widget build(BuildContext context) {
final order = context.select(
(WithdrawBloc bloc) =>
bloc.state is WithdrawConfirmationState
? (bloc.state as WithdrawConfirmationState).order
: null,
);
final recipient = context.select(
(WithdrawBloc bloc) =>
bloc.state is WithdrawConfirmationState
? (bloc.state as WithdrawConfirmationState).recipient
: null,
);
return Scaffold(
appBar: AppBar(
title: Image.asset(
Assets.logos.bbLogoSmall.path,
height: 32,
width: 32,
),
),
body: SafeArea(
child: Column(
children: [
FadingLinearProgress(
height: 3,
trigger: context.select<WithdrawBloc, bool>(
(bloc) =>
bloc.state is WithdrawConfirmationState &&
(bloc.state as WithdrawConfirmationState)
.isConfirmingWithdrawal,
),
backgroundColor: context.appColors.surface,
foregroundColor: context.appColors.primary,
),
Expanded(
child: ScrollableColumn(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
children: [
const Gap(24.0),
Text(
context.loc.withdrawConfirmTitle,
style: context.font.headlineMedium?.copyWith(
color: context.appColors.secondary,
),
),
const Gap(4.0),
const Gap(8.0),
_DetailRow(
title: context.loc.withdrawConfirmRecipientName,
value: recipient?.displayName,
),
const _Divider(),
_DetailRow(
title: _getRecipientInfoLabel(context, recipient),
value: _getRecipientInfoValue(recipient),
),
const _Divider(),
_DetailRow(
title: context.loc.withdrawConfirmAmount,
value:
order == null
? null
: FormatAmount.fiat(
order.payoutAmount,
order.payoutCurrency,
),
),
const Spacer(),
_ConfirmButton(
onConfirmPressed: () {
context.read<WithdrawBloc>().add(
const WithdrawEvent.confirmed(),
);
},
),
const Gap(24.0),
],
),
),
],
),
),
);
}
String _getRecipientInfoLabel(
BuildContext context,
RecipientViewModel? recipient,
) {
if (recipient == null) return context.loc.withdrawConfirmBankAccount;
switch (recipient.type) {
case RecipientType.interacEmailCad:
return context.loc.withdrawConfirmEmail;
case RecipientType.billPaymentCad:
return context.loc.withdrawConfirmPayee;
case RecipientType.bankTransferCad:
return context.loc.withdrawConfirmAccount;
case RecipientType.sepaEur:
return context.loc.withdrawConfirmIban;
case RecipientType.speiClabeMxn:
return context.loc.withdrawConfirmClabe;
case RecipientType.speiSmsMxn:
return context.loc.withdrawConfirmPhone;
case RecipientType.speiCardMxn:
return context.loc.withdrawConfirmCard;
case RecipientType.sinpeIbanUsd:
return context.loc.withdrawConfirmIban;
case RecipientType.sinpeIbanCrc:
return context.loc.withdrawConfirmIban;
case RecipientType.sinpeMovilCrc:
return context.loc.withdrawConfirmPhone;
case RecipientType.bankAccountArgentina:
return context.loc.withdrawConfirmAccount;
case RecipientType.pseColombia:
return context.loc.withdrawConfirmBankAccount;
case RecipientType.nequiColombia:
return context.loc.withdrawConfirmPhone;
}
}
String? _getRecipientInfoValue(RecipientViewModel? recipient) {
if (recipient == null) return null;
switch (recipient.type) {
case RecipientType.interacEmailCad:
return recipient.email;
case RecipientType.billPaymentCad:
return recipient.payeeName ??
recipient.payeeCode ??
recipient.payeeAccountNumber;
case RecipientType.bankTransferCad:
return '${recipient.institutionNumber}-${recipient.transitNumber}-${recipient.accountNumber}';
case RecipientType.sepaEur:
return recipient.iban;
case RecipientType.speiClabeMxn:
return recipient.clabe;
case RecipientType.speiSmsMxn:
return recipient.phoneNumber;
case RecipientType.speiCardMxn:
return recipient.debitcard;
case RecipientType.sinpeIbanUsd:
return recipient.iban;
case RecipientType.sinpeIbanCrc:
return recipient.iban;
case RecipientType.sinpeMovilCrc:
return recipient.phoneNumber;
case RecipientType.bankAccountArgentina:
return null; // TODO: Implement
case RecipientType.pseColombia:
return recipient.bankAccount;
case RecipientType.nequiColombia:
return recipient.phoneNumber;
}
}
}
class _DetailRow extends StatelessWidget {
final String title;
final String? value;
const _DetailRow({required this.title, required this.value}) : super();
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 12.0),
child:
value == null
? const LoadingLineContent()
: Row(
mainAxisAlignment: .spaceBetween,
children: [
Text(
title,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.onSurfaceVariant,
),
),
Expanded(
child: Text(
value!,
textAlign: .end,
maxLines: 2,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.secondary,
),
),
),
],
),
);
}
}
class _Divider extends StatelessWidget {
const _Divider();
@override
Widget build(BuildContext context) {
return Divider(color: context.appColors.secondaryFixedDim, height: 1);
}
}
class _ConfirmButton extends StatelessWidget {
final VoidCallback onConfirmPressed;
const _ConfirmButton({required this.onConfirmPressed}) : super();
@override
Widget build(BuildContext context) {
final isConfirmingWithdrawal = context.select(
(WithdrawBloc bloc) =>
bloc.state is WithdrawConfirmationState &&
(bloc.state as WithdrawConfirmationState).isConfirmingWithdrawal,
);
final withdrawError = context.select(
(WithdrawBloc bloc) =>
bloc.state is WithdrawConfirmationState
? (bloc.state as WithdrawConfirmationState).error
: null,
);
return Column(
children: [
if (withdrawError != null) ...[
Text(
context.loc.withdrawConfirmError(withdrawError.toString()),
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
),
const Gap(16),
],
const Gap(16),
BBButton.big(
label: context.loc.withdrawConfirmButton,
disabled: isConfirmingWithdrawal,
onPressed: onConfirmPressed,
bgColor: context.appColors.onSurface,
textColor: context.appColors.surface,
),
],
);
}
}