Skip to content

Commit

Permalink
ci fix
Browse files Browse the repository at this point in the history
translations update
add advanced fields to create form
  • Loading branch information
MrCyjaneK committed Oct 9, 2024
1 parent 03fef01 commit a0ae814
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 86 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
8 changes: 7 additions & 1 deletion lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
6 changes: 4 additions & 2 deletions lib/view_model/abstract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
}
Expand Down
130 changes: 80 additions & 50 deletions lib/view_model/create_wallet_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@ class CreateWalletViewModel extends ViewModel {
final CreateMethod createMethod;

bool isPinSet = false;

bool showExtra = false;
@override
String get screenName => L.create_wallet;

List<Coin> get coins => walletCoins;

bool isCreate = true;

void toggleAdvancedOptions() {
showExtra = !showExtra;
markNeedsBuild();
}

late Coin? selectedCoin = () {
if (coins.length == 1) {
return coins[0];
Expand All @@ -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<FormElement>? currentForm = () {
if (createMethods.length == 1) {
Expand All @@ -140,12 +165,14 @@ class CreateWalletViewModel extends ViewModel {
walletPassword,
walletName,
walletSeedType,
seedOffset
];

late final List<FormElement> _restoreSeedForm = [
walletPassword,
walletName,
seed,
seedOffset
];

late final List<FormElement> _restoreFormKeysForm = [
Expand Down Expand Up @@ -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;
Expand All @@ -272,6 +300,8 @@ class StringFormElement extends FormElement {
@override
String get value => ctrl.text;

bool isExtra;

@override
bool get isOk => validator(value) == null;

Expand Down
68 changes: 42 additions & 26 deletions lib/views/create_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
);
}
}
1 change: 1 addition & 0 deletions lib/views/open_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class OpenWallet extends AbstractView {
],
scaffoldContext: context,
isPinSet: false,
showExtra: false,
),
],
);
Expand Down
16 changes: 10 additions & 6 deletions lib/widgets/form_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<FormElement> formElements;
final BuildContext scaffoldContext;
final void Function(bool isPinSet)? rebuild;
final bool isPinSet;
final bool showExtra;
@override
State<FormBuilder> createState() => _FormBuilderState();
}
Expand Down Expand Up @@ -75,6 +78,7 @@ class _FormBuilderState extends State<FormBuilder> {
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(
Expand Down

0 comments on commit a0ae814

Please sign in to comment.