From a0ae814f1844429fcaac60743918537f74a8c120 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Wed, 9 Oct 2024 10:10:09 +0200 Subject: [PATCH] ci fix translations update add advanced fields to create form --- .github/workflows/lint.yaml | 1 + lib/l10n/app_en.arb | 8 +- lib/l10n/app_pl.arb | 8 +- lib/view_model/abstract.dart | 6 +- lib/view_model/create_wallet_view_model.dart | 130 ++++++++++++------- lib/views/create_wallet.dart | 68 ++++++---- lib/views/open_wallet.dart | 1 + lib/widgets/form_builder.dart | 16 ++- 8 files changed, 152 insertions(+), 86 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 72e546e..4b24e05 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -30,6 +30,7 @@ jobs: if [ -z "$(git status --porcelain)" ]; then exit 0 else + git status --porcelain exit 1 fi - name: check if there are missing translations diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 26d2d87..f6d6d2d 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -51,5 +51,11 @@ "cancel": "Cancel", "confirming": "Confirming", "canceling": "Canceling", - "balance": "Balance" + "balance": "Balance", + "wallet_seed": "Wallet seed", + "wallet_passphrase": "Wallet passphrase", + "secret_spend_key": "Secret spend key", + "secret_view_key": "Secret View Key", + "restore_height": "Restore height", + "seed_offset": "Seed offset" } \ No newline at end of file diff --git a/lib/l10n/app_pl.arb b/lib/l10n/app_pl.arb index 7931540..34d1d92 100644 --- a/lib/l10n/app_pl.arb +++ b/lib/l10n/app_pl.arb @@ -51,5 +51,11 @@ "cancel": "Anuluj", "confirming": "Potwierdzanie", "canceling": "Anulowanie", - "balance": "Saldo" + "balance": "Saldo", + "wallet_seed": "Fraza odzyskiwania", + "wallet_passphrase": "Hasło frazy odzyskiwania", + "secret_spend_key": "Tajny klucz wydatków", + "secret_view_key": "Tajny klucz podglądu", + "restore_height": "Wysokość przywracania", + "seed_offset": "Szyfrowanie frazy odzyskiwania" } \ No newline at end of file diff --git a/lib/view_model/abstract.dart b/lib/view_model/abstract.dart index d47f084..ae3bb75 100644 --- a/lib/view_model/abstract.dart +++ b/lib/view_model/abstract.dart @@ -5,12 +5,14 @@ class ViewModel { String get screenName => "screenName"; AppLocalizations get L { - if (_lcache == null && _context == null) + if (_lcache == null && _context == null) { throw Exception( "context is null in view model. Did you forget to register()?"); - if (_lcache == null && _context?.mounted != true) + } + if (_lcache == null && _context?.mounted != true) { throw Exception( "context is not mounted. Did you register incorrect context?"); + } _lcache ??= AppLocalizations.of(_context!); return _lcache!; } diff --git a/lib/view_model/create_wallet_view_model.dart b/lib/view_model/create_wallet_view_model.dart index 8b3296d..f395d49 100644 --- a/lib/view_model/create_wallet_view_model.dart +++ b/lib/view_model/create_wallet_view_model.dart @@ -33,7 +33,7 @@ class CreateWalletViewModel extends ViewModel { final CreateMethod createMethod; bool isPinSet = false; - + bool showExtra = false; @override String get screenName => L.create_wallet; @@ -41,6 +41,11 @@ class CreateWalletViewModel extends ViewModel { bool isCreate = true; + void toggleAdvancedOptions() { + showExtra = !showExtra; + markNeedsBuild(); + } + late Coin? selectedCoin = () { if (coins.length == 1) { return coins[0]; @@ -64,60 +69,80 @@ class CreateWalletViewModel extends ViewModel { ); late PinFormElement walletPassword = PinFormElement( - password: true, - validator: (String? input) { - if (input == null) return L.warning_input_cannot_be_null; - if (input == "") return L.warning_input_cannot_be_empty; - if (input.length < 4) { - return L.warning_password_too_short; - } - return null; - }); - - late StringFormElement seed = StringFormElement("Wallet seed", password: true, - validator: (String? input) { - if (input == null) return L.warning_input_cannot_be_null; - if (input == "") return L.warning_input_cannot_be_empty; - if (input.split(" ").length != 16 && input.split(" ").length != 25) { - return L.warning_seed_incorrect_length; - } - return null; - }); + password: true, + validator: (String? input) { + if (input == null) return L.warning_input_cannot_be_null; + if (input == "") return L.warning_input_cannot_be_empty; + if (input.length < 4) { + return L.warning_password_too_short; + } + return null; + }, + ); - late StringFormElement walletAddress = StringFormElement("Primary Address", - password: true, validator: (String? input) { - if (input == null) return L.warning_input_cannot_be_null; - if (input == "") return L.warning_input_cannot_be_empty; - return null; - }); + late StringFormElement seed = StringFormElement( + L.wallet_seed, + password: true, + validator: (String? input) { + if (input == null) return L.warning_input_cannot_be_null; + if (input == "") return L.warning_input_cannot_be_empty; + if (input.split(" ").length != 16 && input.split(" ").length != 25) { + return L.warning_seed_incorrect_length; + } + return null; + }, + ); - late StringFormElement secretSpendKey = StringFormElement("Secret Spend Key", - password: true, validator: (String? input) { - if (input == null) return L.warning_input_cannot_be_null; - if (input == "") return L.warning_input_cannot_be_empty; - return null; - }); + late StringFormElement walletAddress = StringFormElement( + L.primary_address_label, + password: true, + validator: (String? input) { + if (input == null) return L.warning_input_cannot_be_null; + if (input == "") return L.warning_input_cannot_be_empty; + return null; + }, + ); - late StringFormElement secretViewKey = StringFormElement("Secret View Key", - password: true, validator: (String? input) { - if (input == null) return L.warning_input_cannot_be_null; - if (input == "") return L.warning_input_cannot_be_empty; - return null; - }); + late StringFormElement secretSpendKey = StringFormElement( + L.secret_spend_key, + password: true, + validator: (String? input) { + if (input == null) return L.warning_input_cannot_be_null; + if (input == "") return L.warning_input_cannot_be_empty; + return null; + }, + ); - late StringFormElement restoreHeight = StringFormElement("Restore height", - password: true, validator: (String? input) { - if (input == null) return L.warning_input_cannot_be_null; - if (input == "") return L.warning_input_cannot_be_empty; - return null; - }); + late StringFormElement secretViewKey = StringFormElement( + L.secret_view_key, + password: true, + validator: (String? input) { + if (input == null) return L.warning_input_cannot_be_null; + if (input == "") return L.warning_input_cannot_be_empty; + return null; + }, + ); - late StringFormElement seedOffset = StringFormElement("Seed offset", - password: true, validator: (String? input) { - if (input == null) return L.warning_input_cannot_be_null; - if (input == "") return L.warning_input_cannot_be_empty; - return null; - }); + late StringFormElement restoreHeight = StringFormElement( + L.restore_height, + password: true, + validator: (String? input) { + if (input == null) return L.warning_input_cannot_be_null; + if (input == "") return L.warning_input_cannot_be_empty; + return null; + }, + ); + + late StringFormElement seedOffset = StringFormElement( + L.seed_offset, + password: true, + isExtra: true, + validator: (String? input) { + if (input == null) return L.warning_input_cannot_be_null; + if (input == "") return L.warning_input_cannot_be_empty; + return null; + }, + ); late List? currentForm = () { if (createMethods.length == 1) { @@ -140,12 +165,14 @@ class CreateWalletViewModel extends ViewModel { walletPassword, walletName, walletSeedType, + seedOffset ]; late final List _restoreSeedForm = [ walletPassword, walletName, seed, + seedOffset ]; late final List _restoreFormKeysForm = [ @@ -263,6 +290,7 @@ class StringFormElement extends FormElement { String initialText = "", this.password = false, this.validator = _defaultValidator, + this.isExtra = false, }) : ctrl = TextEditingController(text: initialText); TextEditingController ctrl; @@ -272,6 +300,8 @@ class StringFormElement extends FormElement { @override String get value => ctrl.text; + bool isExtra; + @override bool get isOk => validator(value) == null; diff --git a/lib/views/create_wallet.dart b/lib/views/create_wallet.dart index 6528c19..3c1638e 100644 --- a/lib/views/create_wallet.dart +++ b/lib/views/create_wallet.dart @@ -79,34 +79,48 @@ class CreateWallet extends AbstractView { scaffoldContext: context, rebuild: (bool val) => setPinSet(context, val), isPinSet: viewModel.isPinSet, + showExtra: viewModel.showExtra, ); - return Column(children: [ - if (viewModel.isPinSet) + return Column( + children: [ + if (viewModel.isPinSet) + Padding( + padding: const EdgeInsets.symmetric(horizontal: 64.0), + child: Assets.mobile.lottie(), + ), Padding( - padding: const EdgeInsets.symmetric(horizontal: 64.0), - child: Assets.mobile.lottie(), + padding: const EdgeInsets.symmetric(horizontal: 24), + child: formBuilder, ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 24), - child: formBuilder, - ), - if (viewModel.isPinSet) const Spacer(), - if (viewModel.isPinSet) - LongPrimaryButton( - text: L.next, - icon: null, - onPressed: () => _next(context), - backgroundColor: const MaterialStatePropertyAll(Colors.green), - textColor: Colors.white, - ), - if (viewModel.isPinSet) - LongPrimaryButton( - text: L.advanced_options, - icon: null, - onPressed: () {}, // TODO: passphrase - backgroundColor: const MaterialStatePropertyAll(Colors.transparent), - ), - ]); + ], + ); + } + + @override + Widget? bottomNavigationBar(BuildContext context) { + if (viewModel.isPinSet) { + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + LongPrimaryButton( + text: L.next, + icon: null, + onPressed: () => _next(context), + backgroundColor: const MaterialStatePropertyAll(Colors.green), + textColor: Colors.white, + ), + LongPrimaryButton( + text: L.advanced_options, + icon: null, + onPressed: () { + viewModel.toggleAdvancedOptions(); + }, // TODO: passphrase + backgroundColor: const MaterialStatePropertyAll(Colors.transparent), + ), + ], + ); + } + return null; } void _next(BuildContext context) async { @@ -139,10 +153,12 @@ class CreateWallet extends AbstractView { @override Widget build(BuildContext context) { + viewModel.register(context); return Scaffold( appBar: appBar, - body: body(context), + body: SingleChildScrollView(child: body(context)), floatingActionButton: floatingActionButton(context), + bottomNavigationBar: bottomNavigationBar(context), ); } } diff --git a/lib/views/open_wallet.dart b/lib/views/open_wallet.dart index 80b5e95..d08fe82 100644 --- a/lib/views/open_wallet.dart +++ b/lib/views/open_wallet.dart @@ -36,6 +36,7 @@ class OpenWallet extends AbstractView { ], scaffoldContext: context, isPinSet: false, + showExtra: false, ), ], ); diff --git a/lib/widgets/form_builder.dart b/lib/widgets/form_builder.dart index a40c697..62d146f 100644 --- a/lib/widgets/form_builder.dart +++ b/lib/widgets/form_builder.dart @@ -5,17 +5,20 @@ import 'package:cup_cake/views/widgets/numerical_keyboard/main.dart'; import 'package:flutter/material.dart'; class FormBuilder extends StatefulWidget { - const FormBuilder( - {super.key, - required this.formElements, - required this.scaffoldContext, - this.rebuild, - required this.isPinSet}); + const FormBuilder({ + super.key, + required this.formElements, + required this.scaffoldContext, + this.rebuild, + required this.isPinSet, + required this.showExtra, + }); final List formElements; final BuildContext scaffoldContext; final void Function(bool isPinSet)? rebuild; final bool isPinSet; + final bool showExtra; @override State createState() => _FormBuilderState(); } @@ -75,6 +78,7 @@ class _FormBuilderState extends State { mainAxisSize: MainAxisSize.min, children: widget.formElements.map((e) { if (e is StringFormElement) { + if (e.isExtra && !widget.showExtra) return Container(); return Padding( padding: const EdgeInsets.only(bottom: 16.0), child: TextFormField(