dev
dart 136 lines 5.05 KB
Raw
1 import 'package:cake_wallet/generated/i18n.dart';
2 import 'package:cake_wallet/utils/show_bar.dart';
3 import 'package:cake_wallet/view_model/wallet_seed_view_model.dart';
4 import 'package:flutter/material.dart';
5 import 'package:flutter_mobx/flutter_mobx.dart';
6
7 class SeedVerificationStepView extends StatelessWidget {
8 const SeedVerificationStepView({
9 required this.walletSeedViewModel,
10 required this.questionTextColor,
11 super.key,
12 });
13
14 final WalletSeedViewModel walletSeedViewModel;
15 final Color questionTextColor;
16
17 @override
18 Widget build(BuildContext context) {
19 return Observer(
20 builder: (context) {
21 return Padding(
22 padding: EdgeInsets.symmetric(horizontal: 8),
23 child: Column(
24 crossAxisAlignment: CrossAxisAlignment.start,
25 children: [
26 SizedBox(height: 48),
27 Align(
28 alignment: Alignment.center,
29 child: RichText(
30 text: TextSpan(
31 children: [
32 TextSpan(
33 text: '${S.current.seed_position_question_one} ',
34 style: Theme.of(context).textTheme.bodyLarge?.copyWith(
35 fontWeight: FontWeight.w600,
36 color: questionTextColor,
37 ),
38 ),
39 TextSpan(
40 text: '${getOrdinal(walletSeedViewModel.currentWordIndex + 1)} ',
41 style: Theme.of(context).textTheme.bodyLarge?.copyWith(
42 fontWeight: FontWeight.w800,
43 color: questionTextColor,
44 ),
45 ),
46 TextSpan(
47 text: S.current.seed_position_question_two,
48 style: Theme.of(context).textTheme.bodyLarge?.copyWith(
49 fontWeight: FontWeight.w600,
50 color: questionTextColor,
51 ),
52 ),
53 ],
54 ),
55 textAlign: TextAlign.center,
56 ),
57 ),
58 const SizedBox(height: 24),
59 Align(
60 alignment: Alignment.center,
61 child: Wrap(
62 spacing: 8,
63 runSpacing: 8,
64 alignment: WrapAlignment.center,
65 children: walletSeedViewModel.currentOptions.map(
66 (option) {
67 return GestureDetector(
68 key: ValueKey('seed_verification_option_${option}_button_key'),
69 onTap: () async {
70 if (walletSeedViewModel.wrongEntries > 2) return;
71
72 final isCorrectWord = walletSeedViewModel.isChosenWordCorrect(option);
73 final isSecondWrongEntry = walletSeedViewModel.wrongEntries >= 2;
74 if (!isCorrectWord) {
75 await showBar<void>(
76 context,
77 isSecondWrongEntry
78 ? S.current.incorrect_seed_option_back
79 : S.current.incorrect_seed_option,
80 );
81
82 if (isSecondWrongEntry) {
83 if (context.mounted) {
84 Navigator.pop(context);
85 }
86 }
87 }
88 },
89 child: Container(
90 padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
91 decoration: BoxDecoration(
92 borderRadius: BorderRadius.circular(16),
93 color: Theme.of(context).colorScheme.surfaceContainerHighest,
94 ),
95 child: Text(
96 option,
97 style: Theme.of(context).textTheme.bodyLarge?.copyWith(
98 height: 1.2,
99 fontWeight: FontWeight.w800,
100 color: Theme.of(context).colorScheme.onSurfaceVariant,
101 ),
102 ),
103 ),
104 );
105 },
106 ).toList(),
107 ),
108 ),
109 ],
110 ),
111 );
112 },
113 );
114 }
115
116 String getOrdinal(int number) {
117 // Handle special cases for 11th, 12th, 13th
118 final lastTwoDigits = number % 100;
119 if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
120 return '${number}th';
121 }
122
123 // Check the last digit for st, nd, rd, or default th
124 final lastDigit = number % 10;
125 switch (lastDigit) {
126 case 1:
127 return '${number}st';
128 case 2:
129 return '${number}nd';
130 case 3:
131 return '${number}rd';
132 default:
133 return '${number}th';
134 }
135 }
136 }