Integrated wallet names generation
M committed
Oct 22, 2020 at 21:24 UTC
0c197660a8dd3e3aa5377e6fb5acf569777a1b87
9 files changed
+89
-34
lib/di.dart
+6
-2
@@ -14,6 +14,7 @@ import 'package:cake_wallet/src/screens/exchange_trade/exchange_trade_page.dart'
14
import 'package:cake_wallet/src/screens/faq/faq_page.dart';
15
import 'package:cake_wallet/src/screens/nodes/node_create_or_edit_page.dart';
16
import 'package:cake_wallet/src/screens/nodes/nodes_list_page.dart';
17
+import 'package:cake_wallet/src/screens/pin_code/pin_code_widget.dart';
18
import 'package:cake_wallet/src/screens/rescan/rescan_page.dart';
19
import 'package:cake_wallet/src/screens/restore/wallet_restore_page.dart';
20
import 'package:cake_wallet/src/screens/seed/wallet_seed_page.dart';
@@ -237,7 +238,10 @@ Future setup(
238
() => SendTemplatePage(sendViewModel: getIt.get<SendViewModel>()));
239
240
getIt.registerFactory(() => WalletListViewModel(
240
- walletInfoSource, getIt.get<AppStore>(), getIt.get<KeyService>()));
241
+ walletInfoSource,
242
+ getIt.get<AppStore>(),
243
+ getIt.get<KeyService>(),
244
+ getIt.get<WalletNewVM>(param1: WalletType.monero)));
245
246
getIt.registerFactory(() =>
247
WalletListPage(walletListViewModel: getIt.get<WalletListViewModel>()));
@@ -361,7 +365,7 @@ Future setup(
365
getIt.get<AuthService>(), getIt.get<SettingsStore>()));
366
367
getIt.registerFactoryParam<SetupPinCodePage,
364
- void Function(BuildContext, String), void>(
368
+ void Function(PinCodeState<PinCodeWidget>, String), void>(
369
(onSuccessfulPinSetup, _) => SetupPinCodePage(
370
getIt.get<SetupPinCodeViewModel>(),
371
onSuccessfulPinSetup: onSuccessfulPinSetup));
lib/entities/generate_name.dart
new
+18
@@ -0,0 +1,18 @@
1
+import 'dart:math';
2
+
3
+import 'package:flutter/services.dart';
4
+
5
+Future<String> generateName() async {
6
+ final randomThing = Random();
7
+ final adjectiveStringRaw =
8
+ await rootBundle.loadString('assets/text/Wallet_Adjectives.txt');
9
+ final nounStringRaw =
10
+ await rootBundle.loadString('assets/text/Wallet_Nouns.txt');
11
+ final adjectives = List<String>.from(adjectiveStringRaw.split('\n'));
12
+ final nouns = List<String>.from(nounStringRaw.split('\n'));
13
+ final chosenAdjective = adjectives[randomThing.nextInt(adjectives.length)];
14
+ final chosenNoun = nouns[randomThing.nextInt(nouns.length)];
15
+ final returnString = chosenAdjective + ' ' + chosenNoun;
16
+
17
+ return returnString;
18
+}
\ No newline at end of file
lib/router.dart
+12
-2
@@ -1,4 +1,5 @@
1
import 'package:cake_wallet/entities/contact_record.dart';
2
+import 'package:cake_wallet/src/screens/pin_code/pin_code_widget.dart';
3
import 'package:cake_wallet/src/screens/restore/wallet_restore_page.dart';
4
import 'package:flutter/cupertino.dart';
5
import 'package:flutter/material.dart';
@@ -57,8 +58,17 @@ Route<dynamic> createRoute(RouteSettings settings) {
58
case Routes.newWalletFromWelcome:
59
return CupertinoPageRoute<void>(
60
builder: (_) => getIt.get<SetupPinCodePage>(
60
- param1: (BuildContext context, dynamic _) =>
61
- Navigator.pushNamed(context, Routes.newWallet)),
61
+ param1: (PinCodeState<PinCodeWidget> context, dynamic _) async {
62
+ try {
63
+ context.changeProcessText('Creating new wallet'); // FIXME: Unnamed constant
64
+ final newWalletVM = getIt.get<WalletNewVM>(param1: WalletType.monero);
65
+ await newWalletVM.create(options: 'English'); // FIXME: Unnamed constant
66
+ context.hideProgressText();
67
+ await Navigator.of(context.context).pushNamed(Routes.seed, arguments: true);
68
+ } catch(e) {
69
+ context.changeProcessText('Error: ${e.toString()}');
70
+ }
71
+ }),
72
fullscreenDialog: true);
73
74
case Routes.newWalletType:
lib/src/screens/pin_code/pin_code_widget.dart
+14
@@ -1,3 +1,5 @@
1
+import 'package:cake_wallet/utils/show_bar.dart';
2
+import 'package:flushbar/flushbar.dart';
3
import 'package:flutter/material.dart';
4
import 'package:flutter/cupertino.dart';
5
import 'package:cake_wallet/generated/i18n.dart';
@@ -33,6 +35,7 @@ class PinCodeState<T extends PinCodeWidget> extends State<T> {
35
String pin;
36
String title;
37
double _aspectRatio;
38
+ Flushbar<void> _progressBar;
39
40
int currentPinLength() => pin.length;
41
@@ -80,6 +83,17 @@ class PinCodeState<T extends PinCodeWidget> extends State<T> {
83
setState(() {});
84
}
85
86
+ void changeProcessText(String text) {
87
+ hideProgressText();
88
+ _progressBar = createBar<void>(text, duration: null)
89
+ ..show(_key.currentContext);
90
+ }
91
+
92
+ void hideProgressText() {
93
+ _progressBar?.dismiss();
94
+ _progressBar = null;
95
+ }
96
+
97
@override
98
Widget build(BuildContext context) => Scaffold(
99
key: _key, body: body(context), resizeToAvoidBottomPadding: false);
lib/src/screens/setup_pin_code/setup_pin_code.dart
+8
-4
@@ -8,19 +8,23 @@ import 'package:cake_wallet/view_model/setup_pin_code_view_model.dart';
8
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
9
10
class SetupPinCodePage extends BasePage {
11
- SetupPinCodePage(this.pinCodeViewModel, {this.onSuccessfulPinSetup});
11
+ SetupPinCodePage(this.pinCodeViewModel, {this.onSuccessfulPinSetup})
12
+ : pinCodeStateKey = GlobalKey<PinCodeState>();
13
14
final SetupPinCodeViewModel pinCodeViewModel;
14
- final void Function(BuildContext, String) onSuccessfulPinSetup;
15
+ final void Function(PinCodeState<PinCodeWidget>, String) onSuccessfulPinSetup;
16
+ final GlobalKey<PinCodeState> pinCodeStateKey;
17
18
@override
19
String get title => S.current.setup_pin;
20
21
@override
22
Widget body(BuildContext context) => PinCodeWidget(
23
+ key: pinCodeStateKey,
24
hasLengthSwitcher: true,
25
onFullPin: (String pin, PinCodeState<PinCodeWidget> state) async {
23
- if (pinCodeViewModel.isOriginalPinCodeFull && !pinCodeViewModel.isRepeatedPinCodeFull) {
26
+ if (pinCodeViewModel.isOriginalPinCodeFull &&
27
+ !pinCodeViewModel.isRepeatedPinCodeFull) {
28
state.title = S.current.enter_your_pin_again;
29
state.clear();
30
return;
@@ -53,7 +57,7 @@ class SetupPinCodePage extends BasePage {
57
buttonText: S.of(context).ok,
58
buttonAction: () {
59
Navigator.of(context).pop();
56
- onSuccessfulPinSetup(context, pin);
60
+ onSuccessfulPinSetup(pinCodeStateKey.currentState, pin);
61
state.reset();
62
},
63
alertBarrierDismissible: false,
lib/src/screens/wallet_list/wallet_list_page.dart
+25
-2
@@ -1,8 +1,10 @@
1
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
2
import 'package:cake_wallet/src/screens/wallet_list/widgets/wallet_menu_alert.dart';
3
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
4
+import 'package:cake_wallet/utils/show_bar.dart';
5
import 'package:cake_wallet/utils/show_pop_up.dart';
6
import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart';
7
+import 'package:flushbar/flushbar.dart';
8
import 'package:flutter/material.dart';
9
import 'package:flutter/cupertino.dart';
10
import 'package:flutter_mobx/flutter_mobx.dart';
@@ -42,6 +44,7 @@ class WalletListBodyState extends State<WalletListBody> {
44
Image.asset('assets/images/bitcoin.png', height: 24, width: 24);
45
final scrollController = ScrollController();
46
final double tileHeight = 60;
47
+ Flushbar<void> _progressBar;
48
49
@override
50
Widget build(BuildContext context) {
@@ -164,8 +167,7 @@ class WalletListBodyState extends State<WalletListBody> {
167
),
168
bottomSection: Column(children: <Widget>[
169
PrimaryImageButton(
167
- onPressed: () =>
168
- Navigator.of(context).pushNamed(Routes.newWallet),
170
+ onPressed: () => _generateNewWallet(),
171
image: newWalletImage,
172
text: S.of(context).wallet_list_create_new_wallet,
173
color: Theme.of(context).accentTextTheme.subtitle.decorationColor,
@@ -237,4 +239,25 @@ class WalletListBodyState extends State<WalletListBody> {
239
auth.close();
240
});
241
}
242
+
243
+ Future<void> _generateNewWallet() async {
244
+ try {
245
+ changeProcessText('Creating new wallet'); // FIXME: Unnamed constant
246
+ await widget.walletListViewModel.walletNewVM.create(options: 'English'); // FIXME: Unnamed constant
247
+ hideProgressText();
248
+ await Navigator.of(context).pushNamed(Routes.seed, arguments: true);
249
+ } catch(e) {
250
+ changeProcessText('Error: ${e.toString()}');
251
+ }
252
+ }
253
+
254
+ void changeProcessText(String text) {
255
+ _progressBar = createBar<void>(text, duration: null)
256
+ ..show(context);
257
+ }
258
+
259
+ void hideProgressText() {
260
+ _progressBar?.dismiss();
261
+ _progressBar = null;
262
+ }
263
}
lib/view_model/wallet_creation_vm.dart
+2
-20
@@ -8,8 +8,7 @@ import 'package:cake_wallet/entities/pathForWallet.dart';
8
import 'package:cake_wallet/entities/wallet_info.dart';
9
import 'package:cake_wallet/entities/wallet_type.dart';
10
import 'package:cake_wallet/store/app_store.dart';
11
-import 'package:flutter/services.dart';
12
-import 'dart:math';
11
+import 'package:cake_wallet/entities/generate_name.dart';
12
13
part 'wallet_creation_vm.g.dart';
14
@@ -33,26 +32,9 @@ abstract class WalletCreationVMBase with Store {
32
final Box<WalletInfo> _walletInfoSource;
33
final AppStore _appStore;
34
36
- Future<String> generateName() async {
37
- final adjectiveStringRaw =
38
- await rootBundle.loadString('assets/text/Wallet_Adjectives.txt');
39
- final nounStringRaw =
40
- await rootBundle.loadString('assets/text/Wallet_Nouns.txt');
41
-
42
- final randomThing = new Random();
43
-
44
- final adjectives = new List<String>.from(adjectiveStringRaw.split("\n"));
45
- final nouns = new List<String>.from(nounStringRaw.split("\n"));
46
-
47
- final chosenAdjective = adjectives[randomThing.nextInt(adjectives.length)];
48
- final chosenNoun = nouns[randomThing.nextInt(nouns.length)];
49
-
50
- final returnString = chosenAdjective + " " + chosenNoun;
51
- return returnString;
52
- }
53
-
35
Future<void> create({dynamic options}) async {
36
try {
37
+ name = await generateName();
38
state = IsExecutingState();
39
final dirPath = await pathForWalletDir(name: name, type: type);
40
final path = await pathForWallet(name: name, type: type);
lib/view_model/wallet_list/wallet_list_view_model.dart
+4
-2
@@ -1,3 +1,4 @@
1
+import 'package:cake_wallet/view_model/wallet_new_vm.dart';
2
import 'package:hive/hive.dart';
3
import 'package:mobx/mobx.dart';
4
import 'package:cake_wallet/di.dart';
@@ -12,8 +13,8 @@ part 'wallet_list_view_model.g.dart';
13
class WalletListViewModel = WalletListViewModelBase with _$WalletListViewModel;
14
15
abstract class WalletListViewModelBase with Store {
15
- WalletListViewModelBase(
16
- this._walletInfoSource, this._appStore, this._keyService) {
16
+ WalletListViewModelBase(this._walletInfoSource, this._appStore,
17
+ this._keyService, this.walletNewVM) {
18
wallets = ObservableList<WalletListItem>();
19
_updateList();
20
}
@@ -24,6 +25,7 @@ abstract class WalletListViewModelBase with Store {
25
final AppStore _appStore;
26
final Box<WalletInfo> _walletInfoSource;
27
final KeyService _keyService;
28
+ final WalletNewVM walletNewVM;
29
30
@action
31
Future<void> loadWallet(WalletListItem wallet) async {
lib/view_model/wallet_restore_view_model.dart
-2
@@ -1,7 +1,6 @@
1
import 'package:flutter/foundation.dart';
2
import 'package:hive/hive.dart';
3
import 'package:mobx/mobx.dart';
4
-import 'package:uuid/uuid.dart';
4
import 'package:cake_wallet/store/app_store.dart';
5
import 'package:cake_wallet/core/wallet_base.dart';
6
import 'package:cake_wallet/core/generate_wallet_password.dart';
@@ -37,7 +36,6 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
36
WalletCredentials getCredentials(dynamic options) {
37
final password = generateWalletPassword(type);
38
final height = options['height'] as int;
40
- name = Uuid().v4().substring(0, 10);
39
40
if (mode == WalletRestoreMode.seed) {
41
final seed = options['seed'] as String;