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_options_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/send/send_template_page.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>(),
walletInfoSource: _walletInfoSource));
getIt.registerFactoryParam<AdvancedPrivacySettingsViewModel, WalletType, void>(
(type, _) => AdvancedPrivacySettingsViewModel(type, getIt.get<SettingsStore>()));
getIt.registerFactory<WalletLoadingService>(() => WalletLoadingService(
getIt.get<SharedPreferences>(),
getIt.get<KeyService>(),
@ -345,7 +348,7 @@ Future<void> setup({
getIt.registerFactoryParam<WalletNewVM, WalletType, void>((type, _) =>
WalletNewVM(getIt.get<AppStore>(),
getIt.get<WalletCreationService>(param1: type), _walletInfoSource,
type: type));
getIt.get<AdvancedPrivacySettingsViewModel>(param1: type),type: type));
getIt.registerFactoryParam<WalletRestorationFromQRVM, WalletType, void>((WalletType type, _) {
return WalletRestorationFromQRVM(getIt.get<AppStore>(),
@ -900,9 +903,9 @@ Future<void> setup({
getIt.registerFactoryParam<NewWalletTypePage, void Function(BuildContext, WalletType), bool?>(
(param1, isCreate) => NewWalletTypePage(onTypeSelected: param1, isCreate: isCreate ?? true));
getIt.registerFactoryParam<PreSeedPage, WalletType, AdvancedPrivacySettingsViewModel>(
(WalletType type, AdvancedPrivacySettingsViewModel advancedPrivacySettingsViewModel)
=> PreSeedPage(type, advancedPrivacySettingsViewModel));
getIt.registerFactoryParam<WarningPage, int, void>(
(seedPhraseLength, _)
=> WarningPage(seedPhraseLength));
getIt.registerFactoryParam<TradeDetailsViewModel, Trade, void>((trade, _) =>
TradeDetailsViewModel(
@ -1149,9 +1152,6 @@ Future<void> setup({
IoniaPaymentStatusPage(
getIt.get<IoniaPaymentStatusViewModel>(param1: paymentInfo, param2: committedInfo)));
getIt.registerFactoryParam<AdvancedPrivacySettingsViewModel, WalletType, void>(
(type, _) => AdvancedPrivacySettingsViewModel(type, getIt.get<SettingsStore>()));
getIt.registerFactoryParam<HomeSettingsPage, BalanceViewModel, void>((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/restore/restore_from_backup_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/trocador_providers_page.dart';
import 'package:cake_wallet/src/screens/settings/tor_page.dart';
@ -417,12 +417,10 @@ Route<dynamic> createRoute(RouteSettings settings) {
case Routes.faq:
return MaterialPageRoute<void>(builder: (_) => getIt.get<FaqPage>());
case Routes.preSeed:
case Routes.warningPage:
return MaterialPageRoute<void>(
builder: (_) => getIt.get<PreSeedPage>(
param1: settings.arguments as WalletType,
param2: getIt.get<AdvancedPrivacySettingsViewModel>(
param1: settings.arguments as WalletType)));
builder: (_) => getIt.get<WarningPage>(
param1: settings.arguments as int));
case Routes.backup:
return CupertinoPageRoute<void>(

View file

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

View file

@ -67,7 +67,7 @@ class _WalletNameFormState extends State<WalletNameForm> {
_stateReaction ??= reaction((_) => _walletNewVM.state, (ExecutionState state) async {
if (state is ExecutedSuccessfullyState) {
Navigator.of(navigatorKey.currentContext!)
.pushNamed(Routes.preSeed, arguments: _walletNewVM.type);
.pushNamed(Routes.warningPage, arguments: _walletNewVM.seedPhraseWordsLength);
}
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:flutter/material.dart';
class PreSeedPage extends BasePage {
PreSeedPage(this.type, this.advancedPrivacySettingsViewModel)
class WarningPage extends BasePage {
WarningPage(this.seedPhraseLength)
: imageLight = Image.asset('assets/images/pre_seed_light.png'),
imageDark = Image.asset('assets/images/pre_seed_dark.png'),
seedPhraseLength = advancedPrivacySettingsViewModel.seedPhraseLength.value {
wordsCount = _wordsCount(type, seedPhraseLength);
}
imageDark = Image.asset('assets/images/pre_seed_dark.png');
final Image imageDark;
final Image imageLight;
final WalletType type;
final AdvancedPrivacySettingsViewModel advancedPrivacySettingsViewModel;
final int seedPhraseLength;
late final int wordsCount;
final int? seedPhraseLength;
@override
Widget? leading(BuildContext context) => null;
@ -53,7 +47,7 @@ class PreSeedPage extends BasePage {
Padding(
padding: EdgeInsets.all(10),
child: Text(
S.of(context).pre_seed_description(wordsCount.toString()),
S.of(context).pre_seed_description(seedPhraseLength.toString()),
textAlign: TextAlign.center,
style: TextStyle(
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/bitcoin/bitcoin.dart';
import 'package:cake_wallet/haven/haven.dart';
import 'advanced_privacy_settings_view_model.dart';
part 'wallet_new_vm.g.dart';
@ -22,16 +23,30 @@ class WalletNewVM = WalletNewVMBase with _$WalletNewVM;
abstract class WalletNewVMBase extends WalletCreationVM with Store {
WalletNewVMBase(AppStore appStore, WalletCreationService walletCreationService,
Box<WalletInfo> walletInfoSource,
Box<WalletInfo> walletInfoSource, this.advancedPrivacySettingsViewModel,
{required WalletType type})
: selectedMnemonicLanguage = '',
super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: false);
final AdvancedPrivacySettingsViewModel advancedPrivacySettingsViewModel;
@observable
String selectedMnemonicLanguage;
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
WalletCredentials getCredentials(dynamic options) {
switch (type) {