pre seed page refactoring

This commit is contained in:
Serhii 2023-11-22 23:37:05 +02:00
parent 306e4671b4
commit 217c19272f
6 changed files with 35 additions and 40 deletions

View file

@ -129,7 +129,7 @@ import 'package:cake_wallet/src/screens/rescan/rescan_page.dart';
import 'package:cake_wallet/src/screens/restore/restore_from_backup_page.dart'; import 'package:cake_wallet/src/screens/restore/restore_from_backup_page.dart';
import 'package:cake_wallet/src/screens/restore/restore_options_page.dart'; import 'package:cake_wallet/src/screens/restore/restore_options_page.dart';
import 'package:cake_wallet/src/screens/restore/wallet_restore_page.dart'; import 'package:cake_wallet/src/screens/restore/wallet_restore_page.dart';
import 'package:cake_wallet/src/screens/seed/pre_seed_page.dart'; import 'package:cake_wallet/src/screens/seed/warning_page.dart';
import 'package:cake_wallet/src/screens/seed/wallet_seed_page.dart'; import 'package:cake_wallet/src/screens/seed/wallet_seed_page.dart';
import 'package:cake_wallet/src/screens/send/send_template_page.dart'; import 'package:cake_wallet/src/screens/send/send_template_page.dart';
import 'package:cake_wallet/src/screens/setup_pin_code/setup_pin_code.dart'; import 'package:cake_wallet/src/screens/setup_pin_code/setup_pin_code.dart';
@ -337,6 +337,9 @@ Future<void> setup({
settingsStore: getIt.get<SettingsStore>(), settingsStore: getIt.get<SettingsStore>(),
walletInfoSource: _walletInfoSource)); walletInfoSource: _walletInfoSource));
getIt.registerFactoryParam<AdvancedPrivacySettingsViewModel, WalletType, void>(
(type, _) => AdvancedPrivacySettingsViewModel(type, getIt.get<SettingsStore>()));
getIt.registerFactory<WalletLoadingService>(() => WalletLoadingService( getIt.registerFactory<WalletLoadingService>(() => WalletLoadingService(
getIt.get<SharedPreferences>(), getIt.get<SharedPreferences>(),
getIt.get<KeyService>(), getIt.get<KeyService>(),
@ -345,7 +348,7 @@ Future<void> setup({
getIt.registerFactoryParam<WalletNewVM, WalletType, void>((type, _) => getIt.registerFactoryParam<WalletNewVM, WalletType, void>((type, _) =>
WalletNewVM(getIt.get<AppStore>(), WalletNewVM(getIt.get<AppStore>(),
getIt.get<WalletCreationService>(param1: type), _walletInfoSource, getIt.get<WalletCreationService>(param1: type), _walletInfoSource,
type: type)); getIt.get<AdvancedPrivacySettingsViewModel>(param1: type),type: type));
getIt.registerFactoryParam<WalletRestorationFromQRVM, WalletType, void>((WalletType type, _) { getIt.registerFactoryParam<WalletRestorationFromQRVM, WalletType, void>((WalletType type, _) {
return WalletRestorationFromQRVM(getIt.get<AppStore>(), return WalletRestorationFromQRVM(getIt.get<AppStore>(),
@ -900,9 +903,9 @@ Future<void> setup({
getIt.registerFactoryParam<NewWalletTypePage, void Function(BuildContext, WalletType), bool?>( getIt.registerFactoryParam<NewWalletTypePage, void Function(BuildContext, WalletType), bool?>(
(param1, isCreate) => NewWalletTypePage(onTypeSelected: param1, isCreate: isCreate ?? true)); (param1, isCreate) => NewWalletTypePage(onTypeSelected: param1, isCreate: isCreate ?? true));
getIt.registerFactoryParam<PreSeedPage, WalletType, AdvancedPrivacySettingsViewModel>( getIt.registerFactoryParam<WarningPage, int, void>(
(WalletType type, AdvancedPrivacySettingsViewModel advancedPrivacySettingsViewModel) (seedPhraseLength, _)
=> PreSeedPage(type, advancedPrivacySettingsViewModel)); => WarningPage(seedPhraseLength));
getIt.registerFactoryParam<TradeDetailsViewModel, Trade, void>((trade, _) => getIt.registerFactoryParam<TradeDetailsViewModel, Trade, void>((trade, _) =>
TradeDetailsViewModel( TradeDetailsViewModel(
@ -1149,9 +1152,6 @@ Future<void> setup({
IoniaPaymentStatusPage( IoniaPaymentStatusPage(
getIt.get<IoniaPaymentStatusViewModel>(param1: paymentInfo, param2: committedInfo))); getIt.get<IoniaPaymentStatusViewModel>(param1: paymentInfo, param2: committedInfo)));
getIt.registerFactoryParam<AdvancedPrivacySettingsViewModel, WalletType, void>(
(type, _) => AdvancedPrivacySettingsViewModel(type, getIt.get<SettingsStore>()));
getIt.registerFactoryParam<HomeSettingsPage, BalanceViewModel, void>((balanceViewModel, _) => getIt.registerFactoryParam<HomeSettingsPage, BalanceViewModel, void>((balanceViewModel, _) =>
HomeSettingsPage(getIt.get<HomeSettingsViewModel>(param1: balanceViewModel))); HomeSettingsPage(getIt.get<HomeSettingsViewModel>(param1: balanceViewModel)));

View file

@ -40,7 +40,7 @@ import 'package:cake_wallet/src/screens/order_details/order_details_page.dart';
import 'package:cake_wallet/src/screens/pin_code/pin_code_widget.dart'; import 'package:cake_wallet/src/screens/pin_code/pin_code_widget.dart';
import 'package:cake_wallet/src/screens/restore/restore_from_backup_page.dart'; import 'package:cake_wallet/src/screens/restore/restore_from_backup_page.dart';
import 'package:cake_wallet/src/screens/restore/wallet_restore_page.dart'; import 'package:cake_wallet/src/screens/restore/wallet_restore_page.dart';
import 'package:cake_wallet/src/screens/seed/pre_seed_page.dart'; import 'package:cake_wallet/src/screens/seed/warning_page.dart';
import 'package:cake_wallet/src/screens/settings/connection_sync_page.dart'; import 'package:cake_wallet/src/screens/settings/connection_sync_page.dart';
import 'package:cake_wallet/src/screens/settings/trocador_providers_page.dart'; import 'package:cake_wallet/src/screens/settings/trocador_providers_page.dart';
import 'package:cake_wallet/src/screens/settings/tor_page.dart'; import 'package:cake_wallet/src/screens/settings/tor_page.dart';
@ -417,12 +417,10 @@ Route<dynamic> createRoute(RouteSettings settings) {
case Routes.faq: case Routes.faq:
return MaterialPageRoute<void>(builder: (_) => getIt.get<FaqPage>()); return MaterialPageRoute<void>(builder: (_) => getIt.get<FaqPage>());
case Routes.preSeed: case Routes.warningPage:
return MaterialPageRoute<void>( return MaterialPageRoute<void>(
builder: (_) => getIt.get<PreSeedPage>( builder: (_) => getIt.get<WarningPage>(
param1: settings.arguments as WalletType, param1: settings.arguments as int));
param2: getIt.get<AdvancedPrivacySettingsViewModel>(
param1: settings.arguments as WalletType)));
case Routes.backup: case Routes.backup:
return CupertinoPageRoute<void>( return CupertinoPageRoute<void>(

View file

@ -47,7 +47,7 @@ class Routes {
static const exchangeTemplate = '/exchange_template'; static const exchangeTemplate = '/exchange_template';
static const restoreWalletType = '/restore_wallet_type'; static const restoreWalletType = '/restore_wallet_type';
static const restoreWallet = '/restore_wallet'; static const restoreWallet = '/restore_wallet';
static const preSeed = '/pre_seed'; static const warningPage = '/warning_page';
static const backup = '/backup'; static const backup = '/backup';
static const editBackupPassword = '/edit_backup_passowrd'; static const editBackupPassword = '/edit_backup_passowrd';
static const restoreFromBackup = '/restore_from_backup'; static const restoreFromBackup = '/restore_from_backup';

View file

@ -67,7 +67,7 @@ class _WalletNameFormState extends State<WalletNameForm> {
_stateReaction ??= reaction((_) => _walletNewVM.state, (ExecutionState state) async { _stateReaction ??= reaction((_) => _walletNewVM.state, (ExecutionState state) async {
if (state is ExecutedSuccessfullyState) { if (state is ExecutedSuccessfullyState) {
Navigator.of(navigatorKey.currentContext!) Navigator.of(navigatorKey.currentContext!)
.pushNamed(Routes.preSeed, arguments: _walletNewVM.type); .pushNamed(Routes.warningPage, arguments: _walletNewVM.seedPhraseWordsLength);
} }
if (state is FailureState) { if (state is FailureState) {

View file

@ -9,20 +9,14 @@ import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/themes/theme_base.dart'; import 'package:cake_wallet/themes/theme_base.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class PreSeedPage extends BasePage { class WarningPage extends BasePage {
PreSeedPage(this.type, this.advancedPrivacySettingsViewModel) WarningPage(this.seedPhraseLength)
: imageLight = Image.asset('assets/images/pre_seed_light.png'), : imageLight = Image.asset('assets/images/pre_seed_light.png'),
imageDark = Image.asset('assets/images/pre_seed_dark.png'), imageDark = Image.asset('assets/images/pre_seed_dark.png');
seedPhraseLength = advancedPrivacySettingsViewModel.seedPhraseLength.value {
wordsCount = _wordsCount(type, seedPhraseLength);
}
final Image imageDark; final Image imageDark;
final Image imageLight; final Image imageLight;
final WalletType type; final int? seedPhraseLength;
final AdvancedPrivacySettingsViewModel advancedPrivacySettingsViewModel;
final int seedPhraseLength;
late final int wordsCount;
@override @override
Widget? leading(BuildContext context) => null; Widget? leading(BuildContext context) => null;
@ -53,7 +47,7 @@ class PreSeedPage extends BasePage {
Padding( Padding(
padding: EdgeInsets.all(10), padding: EdgeInsets.all(10),
child: Text( child: Text(
S.of(context).pre_seed_description(wordsCount.toString()), S.of(context).pre_seed_description(seedPhraseLength.toString()),
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
fontSize: 14, fontSize: 14,
@ -72,16 +66,4 @@ class PreSeedPage extends BasePage {
), ),
)); ));
} }
static int _wordsCount(WalletType type, int seedPhraseLength) {
switch (type) {
case WalletType.monero:
return 25;
case WalletType.ethereum:
case WalletType.bitcoinCash:
return seedPhraseLength;
default:
return 24;
}
}
} }

View file

@ -15,6 +15,7 @@ import 'package:cw_core/wallet_type.dart';
import 'package:cake_wallet/view_model/wallet_creation_vm.dart'; import 'package:cake_wallet/view_model/wallet_creation_vm.dart';
import 'package:cake_wallet/bitcoin/bitcoin.dart'; import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/haven/haven.dart'; import 'package:cake_wallet/haven/haven.dart';
import 'advanced_privacy_settings_view_model.dart';
part 'wallet_new_vm.g.dart'; part 'wallet_new_vm.g.dart';
@ -22,16 +23,30 @@ class WalletNewVM = WalletNewVMBase with _$WalletNewVM;
abstract class WalletNewVMBase extends WalletCreationVM with Store { abstract class WalletNewVMBase extends WalletCreationVM with Store {
WalletNewVMBase(AppStore appStore, WalletCreationService walletCreationService, WalletNewVMBase(AppStore appStore, WalletCreationService walletCreationService,
Box<WalletInfo> walletInfoSource, Box<WalletInfo> walletInfoSource, this.advancedPrivacySettingsViewModel,
{required WalletType type}) {required WalletType type})
: selectedMnemonicLanguage = '', : selectedMnemonicLanguage = '',
super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: false); super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: false);
final AdvancedPrivacySettingsViewModel advancedPrivacySettingsViewModel;
@observable @observable
String selectedMnemonicLanguage; String selectedMnemonicLanguage;
bool get hasLanguageSelector => type == WalletType.monero || type == WalletType.haven; bool get hasLanguageSelector => type == WalletType.monero || type == WalletType.haven;
int get seedPhraseWordsLength {
switch (type) {
case WalletType.monero:
return 25;
case WalletType.ethereum:
case WalletType.bitcoinCash:
return advancedPrivacySettingsViewModel.seedPhraseLength.value;
default:
return 24;
}
}
@override @override
WalletCredentials getCredentials(dynamic options) { WalletCredentials getCredentials(dynamic options) {
switch (type) { switch (type) {