mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-02 12:14:09 +01:00
CW-774: Enforce Seed Verification (#1874)
* feat: Switch UI for seeds display * feat: Add localization for disclaimer text * fix: Modify color for warning on seeds screen * Fix: Adjust UI styling for seed page * chore: Revert podfile.lock * Fix column colors * Fix more colors * Fix more colors and update strings * feat: Enforce Seed Verification Implementation * fix: Error extracting seed words in Japanese because of spacing type used * fix: Modify styling for copy image button * fix: Add back button to the seed page and adjust styling to seed verification question text * Update seed verification image [skip ci] * Update description text weight [skip ci] * Make seed page wider * Seed page changes --------- Co-authored-by: tuxpizza <tuxsudo@tux.pizza> Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
co-authored by
tuxpizza
Omar Hatem
parent
d55e635f61
commit
ae80fb3b55
@@ -25,5 +25,5 @@ class PreSeedPage extends InfoPage {
|
||||
|
||||
@override
|
||||
void Function(BuildContext) get onPressed =>
|
||||
(BuildContext context) => Navigator.of(context).popAndPushNamed(Routes.seed, arguments: true);
|
||||
(BuildContext context) => Navigator.of(context).pushNamed(Routes.seed, arguments: true);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
import 'package:cake_wallet/src/screens/seed/seed_verification/seed_verification_step_view.dart';
|
||||
import 'package:cake_wallet/src/screens/seed/seed_verification/seed_verification_success_view.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_seed_view_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
|
||||
class SeedVerificationPage extends BasePage {
|
||||
final WalletSeedViewModel walletSeedViewModel;
|
||||
|
||||
SeedVerificationPage(this.walletSeedViewModel);
|
||||
|
||||
@override
|
||||
String? get title => S.current.verify_seed;
|
||||
|
||||
@override
|
||||
Widget body(BuildContext context) {
|
||||
return Observer(
|
||||
builder: (context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: walletSeedViewModel.isVerificationComplete
|
||||
? SeedVerificationSuccessView(
|
||||
imageColor: titleColor(context),
|
||||
)
|
||||
: SeedVerificationStepView(
|
||||
walletSeedViewModel: walletSeedViewModel,
|
||||
questionTextColor: titleColor(context),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/themes/extensions/cake_text_theme.dart';
|
||||
import 'package:cake_wallet/utils/show_bar.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_seed_view_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
|
||||
class SeedVerificationStepView extends StatelessWidget {
|
||||
const SeedVerificationStepView({
|
||||
required this.walletSeedViewModel,
|
||||
required this.questionTextColor,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final WalletSeedViewModel walletSeedViewModel;
|
||||
final Color questionTextColor;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Observer(
|
||||
builder: (context) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(height: 48),
|
||||
Align(
|
||||
alignment: Alignment.center,
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: '${S.current.seed_position_question_one} ',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: questionTextColor,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: '${getOrdinal(walletSeedViewModel.currentWordIndex + 1)} ',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: questionTextColor,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: S.current.seed_position_question_two,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: questionTextColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Align(
|
||||
alignment: Alignment.center,
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
alignment: WrapAlignment.center,
|
||||
children: walletSeedViewModel.currentOptions.map(
|
||||
(option) {
|
||||
return GestureDetector(
|
||||
onTap: () async {
|
||||
final isCorrectWord = walletSeedViewModel.isChosenWordCorrect(option);
|
||||
final isSecondWrongEntry = walletSeedViewModel.wrongEntries == 2;
|
||||
if (!isCorrectWord) {
|
||||
await showBar<void>(
|
||||
context,
|
||||
isSecondWrongEntry
|
||||
? S.current.incorrect_seed_option_back
|
||||
: S.current.incorrect_seed_option,
|
||||
);
|
||||
|
||||
if (isSecondWrongEntry) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
color: Theme.of(context).cardColor,
|
||||
),
|
||||
child: Text(
|
||||
option,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: Theme.of(context).extension<CakeTextTheme>()!.buttonTextColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
).toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
String getOrdinal(int number) {
|
||||
// Handle special cases for 11th, 12th, 13th
|
||||
final lastTwoDigits = number % 100;
|
||||
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
|
||||
return '${number}th';
|
||||
}
|
||||
|
||||
// Check the last digit for st, nd, rd, or default th
|
||||
final lastDigit = number % 10;
|
||||
switch (lastDigit) {
|
||||
case 1:
|
||||
return '${number}st';
|
||||
case 2:
|
||||
return '${number}nd';
|
||||
case 3:
|
||||
return '${number}rd';
|
||||
default:
|
||||
return '${number}th';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
||||
import 'package:cake_wallet/themes/extensions/cake_text_theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SeedVerificationSuccessView extends StatelessWidget {
|
||||
const SeedVerificationSuccessView({required this.imageColor, super.key});
|
||||
|
||||
final Color imageColor;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final image = Image.asset('assets/images/seed_verified.png', color: imageColor);
|
||||
|
||||
return Center(
|
||||
child: Column(
|
||||
children: [
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.3),
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1.8,
|
||||
child: image,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
S.current.seed_verified,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Theme.of(context).extension<CakeTextTheme>()!.titleColor,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 48),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: '${S.current.seed_verified_subtext} ',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Theme.of(context).extension<CakeTextTheme>()!.secondaryTextColor,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: S.current.seed_display_path,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: Theme.of(context).extension<CakeTextTheme>()!.secondaryTextColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Spacer(),
|
||||
PrimaryButton(
|
||||
key: ValueKey('wallet_seed_page_open_wallet_button_key'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||
},
|
||||
text: S.current.open_wallet,
|
||||
color: Theme.of(context).primaryColor,
|
||||
textColor: Colors.white,
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:cake_wallet/routes.dart';
|
||||
import 'package:cake_wallet/themes/extensions/cake_text_theme.dart';
|
||||
import 'package:cake_wallet/themes/extensions/dashboard_page_theme.dart';
|
||||
import 'package:cake_wallet/themes/theme_base.dart';
|
||||
@@ -15,7 +16,7 @@ import 'package:cake_wallet/src/widgets/primary_button.dart';
|
||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_seed_view_model.dart';
|
||||
|
||||
import '../../../themes/extensions/menu_theme.dart';
|
||||
import '../../../themes/extensions/send_page_theme.dart';
|
||||
|
||||
class WalletSeedPage extends BasePage {
|
||||
WalletSeedPage(this.walletSeedViewModel, {required this.isNewWalletCreated});
|
||||
@@ -29,62 +30,34 @@ class WalletSeedPage extends BasePage {
|
||||
final bool isNewWalletCreated;
|
||||
final WalletSeedViewModel walletSeedViewModel;
|
||||
|
||||
@override
|
||||
void onClose(BuildContext context) async {
|
||||
if (isNewWalletCreated) {
|
||||
final confirmed = await showPopUp<bool>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithTwoActions(
|
||||
alertDialogKey: ValueKey('wallet_seed_page_seed_alert_dialog_key'),
|
||||
alertRightActionButtonKey:
|
||||
ValueKey('wallet_seed_page_seed_alert_confirm_button_key'),
|
||||
alertLeftActionButtonKey: ValueKey('wallet_seed_page_seed_alert_back_button_key'),
|
||||
alertTitle: S.of(context).seed_alert_title,
|
||||
alertContent: S.of(context).seed_alert_content,
|
||||
leftButtonText: S.of(context).seed_alert_back,
|
||||
rightButtonText: S.of(context).seed_alert_yes,
|
||||
actionLeftButton: () => Navigator.of(context).pop(false),
|
||||
actionRightButton: () => Navigator.of(context).pop(true),
|
||||
);
|
||||
},
|
||||
) ??
|
||||
false;
|
||||
|
||||
if (confirmed) {
|
||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget? leading(BuildContext context) => isNewWalletCreated ? null : super.leading(context);
|
||||
|
||||
@override
|
||||
Widget trailing(BuildContext context) {
|
||||
final copyImage = Image.asset(
|
||||
'assets/images/copy_address.png',
|
||||
color: Theme.of(context)
|
||||
.extension<CakeTextTheme>()!
|
||||
.buttonTextColor
|
||||
);
|
||||
|
||||
return isNewWalletCreated
|
||||
? GestureDetector(
|
||||
key: ValueKey('wallet_seed_page_next_button_key'),
|
||||
onTap: () => onClose(context),
|
||||
key: ValueKey('wallet_seed_page_copy_seeds_button_key'),
|
||||
onTap: () {
|
||||
ClipboardUtil.setSensitiveDataToClipboard(
|
||||
ClipboardData(text: walletSeedViewModel.seed),
|
||||
);
|
||||
showBar<void>(context, S.of(context).copied_to_clipboard);
|
||||
},
|
||||
child: Container(
|
||||
width: 100,
|
||||
height: 32,
|
||||
padding: EdgeInsets.all(8),
|
||||
width: 40,
|
||||
alignment: Alignment.center,
|
||||
margin: EdgeInsets.only(left: 10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.all(Radius.circular(16)),
|
||||
color: Theme.of(context).cardColor),
|
||||
child: Text(
|
||||
S.of(context).seed_language_next,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Theme.of(context).extension<CakeTextTheme>()!.buttonTextColor),
|
||||
borderRadius: BorderRadius.all(Radius.circular(8)),
|
||||
color: Theme.of(context).cardColor,
|
||||
),
|
||||
child: copyImage,
|
||||
),
|
||||
)
|
||||
: Offstage();
|
||||
@@ -95,7 +68,7 @@ class WalletSeedPage extends BasePage {
|
||||
return WillPopScope(
|
||||
onWillPop: () async => false,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 8),
|
||||
padding: EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
||||
alignment: Alignment.center,
|
||||
child: ConstrainedBox(
|
||||
constraints:
|
||||
@@ -129,7 +102,7 @@ class WalletSeedPage extends BasePage {
|
||||
size: 64,
|
||||
color: Colors.white.withOpacity(0.75),
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
S.current.cake_seeds_save_disclaimer,
|
||||
@@ -146,24 +119,23 @@ class WalletSeedPage extends BasePage {
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 32),
|
||||
SizedBox(height: 20),
|
||||
Text(
|
||||
key: ValueKey('wallet_seed_page_wallet_name_text_key'),
|
||||
walletSeedViewModel.name,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Theme.of(context).extension<CakeTextTheme>()!.titleColor,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
SizedBox(height: 20),
|
||||
Expanded(
|
||||
child: GridView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
itemCount: walletSeedViewModel.seedSplit.length,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: walletSeedViewModel.columnCount,
|
||||
childAspectRatio: 3.6,
|
||||
crossAxisCount: 3,
|
||||
childAspectRatio: 2.8,
|
||||
mainAxisSpacing: 8.0,
|
||||
crossAxisSpacing: 8.0,
|
||||
),
|
||||
@@ -172,7 +144,7 @@ class WalletSeedPage extends BasePage {
|
||||
final numberCount = index + 1;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
@@ -182,25 +154,27 @@ class WalletSeedPage extends BasePage {
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 20,
|
||||
child: Text(
|
||||
//maxLines: 1,
|
||||
numberCount.toString(),
|
||||
textAlign: TextAlign.right,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 12,
|
||||
height: 1,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: Theme.of(context)
|
||||
.extension<CakeTextTheme>()!
|
||||
.buttonTextColor
|
||||
.withOpacity(0.5)),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${item[0].toUpperCase()}${item.substring(1)}',
|
||||
'${item[0].toLowerCase()}${item.substring(1)}',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
height: 0.8,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Theme.of(context)
|
||||
.extension<CakeTextTheme>()!
|
||||
@@ -225,7 +199,7 @@ class WalletSeedPage extends BasePage {
|
||||
children: <Widget>[
|
||||
Flexible(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(right: 8.0),
|
||||
padding: EdgeInsets.only(right: 8.0, top: 8.0),
|
||||
child: PrimaryButton(
|
||||
key: ValueKey('wallet_seed_page_save_seeds_button_key'),
|
||||
onPressed: () {
|
||||
@@ -244,17 +218,13 @@ class WalletSeedPage extends BasePage {
|
||||
),
|
||||
Flexible(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(left: 8.0),
|
||||
padding: EdgeInsets.only(left: 8.0, top: 8.0),
|
||||
child: Builder(
|
||||
builder: (context) => PrimaryButton(
|
||||
key: ValueKey('wallet_seed_page_copy_seeds_button_key'),
|
||||
onPressed: () {
|
||||
ClipboardUtil.setSensitiveDataToClipboard(
|
||||
ClipboardData(text: walletSeedViewModel.seed),
|
||||
);
|
||||
showBar<void>(context, S.of(context).copied_to_clipboard);
|
||||
},
|
||||
text: S.of(context).copy,
|
||||
key: ValueKey('wallet_seed_page_verify_seed_button_key'),
|
||||
onPressed: () =>
|
||||
Navigator.pushNamed(context, Routes.walletSeedVerificationPage),
|
||||
text: S.current.verify_seed,
|
||||
color: Theme.of(context).primaryColor,
|
||||
textColor: Colors.white,
|
||||
),
|
||||
@@ -263,7 +233,7 @@ class WalletSeedPage extends BasePage {
|
||||
)
|
||||
],
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
SizedBox(height: 12),
|
||||
],
|
||||
)
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user