TMP 3
M committed
Jun 3, 2020 at 12:56 UTC
cfde445d3242d1df8259b1c628e4a32b52ae45cb
6 files changed
+102
-63
lib/core/app_service.dart
new
+16
@@ -0,0 +1,16 @@
1
+import 'package:mobx/mobx.dart';
2
+import 'package:cake_wallet/core/auth_service.dart';
3
+import 'package:cake_wallet/core/wallet_base.dart';
4
+import 'package:cake_wallet/core/wallet_creation_service.dart';
5
+
6
+part 'app_service.g.dart';
7
+
8
+class AppService = AppServiceBase with _$AppService;
9
+
10
+abstract class AppServiceBase with Store {
11
+ AppServiceBase({this.walletCreationService, this.authService, this.wallet});
12
+
13
+ WalletCreationService walletCreationService;
14
+ AuthService authService;
15
+ WalletBase wallet;
16
+}
\ No newline at end of file
lib/core/app_store.dart
deleted
-12
@@ -1,12 +0,0 @@
1
-import 'package:mobx/mobx.dart';
2
-
3
-part 'app_store.g.dart';
4
-
5
-class AppStore = AppStoreBase with _$AppStore;
6
-
7
-abstract class AppStoreBase with Store {
8
- // Sign Up
9
- // Auth
10
- // Wallet
11
- // Settings
12
-}
\ No newline at end of file
lib/core/bitcoin_wallet.dart
+2
-2
@@ -24,7 +24,7 @@ part 'bitcoin_wallet.g.dart';
24
class BitcoinWallet = BitcoinWalletBase with _$BitcoinWallet;
25
26
abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
27
- static Future<BitcoinWallet> load(
27
+ static Future<BitcoinWalletBase> load(
28
{@required String name, @required String password}) async {
29
final walletDirPath =
30
await pathForWalletDir(name: name, type: WalletType.bitcoin);
@@ -37,7 +37,7 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
37
? 0
38
: int.parse(jsoned['account_index'] as String);
39
40
- return BitcoinWallet.build(
40
+ return BitcoinWalletBase.build(
41
mnemonic: mnemonic,
42
password: password,
43
name: name,
lib/core/wallet_creation_service.dart
+4
@@ -16,9 +16,13 @@ abstract class WalletCreationServiceBase with Store {
16
@observable
17
WalletCreationState state;
18
19
+ WalletType type;
20
+
21
WalletListService _service;
22
23
void changeWalletType({@required WalletType type}) {
24
+ this.type = type;
25
+
26
switch (type) {
27
case WalletType.monero:
28
_service = MoneroWalletListService();
lib/main.dart
+15
-3
@@ -1,3 +1,6 @@
1
+import 'package:cake_wallet/core/app_service.dart';
2
+import 'package:cake_wallet/core/auth_service.dart';
3
+import 'package:cake_wallet/core/wallet_creation_service.dart';
4
import 'package:flutter_localizations/flutter_localizations.dart';
5
import 'package:path_provider/path_provider.dart';
6
import 'package:shared_preferences/shared_preferences.dart';
@@ -41,7 +44,6 @@ import 'package:cake_wallet/generated/i18n.dart';
44
import 'package:cake_wallet/src/domain/common/language.dart';
45
import 'package:cake_wallet/src/stores/seed_language/seed_language_store.dart';
46
44
-
47
void main() async {
48
WidgetsFlutterBinding.ensureInitialized();
49
@@ -73,7 +75,8 @@ void main() async {
75
await Hive.openBox<Trade>(Trade.boxName, encryptionKey: tradesBoxKey);
76
final walletInfoSource = await Hive.openBox<WalletInfo>(WalletInfo.boxName);
77
final templates = await Hive.openBox<Template>(Template.boxName);
76
- final exchangeTemplates = await Hive.openBox<ExchangeTemplate>(ExchangeTemplate.boxName);
78
+ final exchangeTemplates =
79
+ await Hive.openBox<ExchangeTemplate>(ExchangeTemplate.boxName);
80
81
final sharedPreferences = await SharedPreferences.getInstance();
82
final walletService = WalletService();
@@ -111,7 +114,13 @@ void main() async {
114
sharedPreferences: sharedPreferences, walletsService: walletListService);
115
final seedLanguageStore = SeedLanguageStore();
116
final sendTemplateStore = SendTemplateStore(templateSource: templates);
114
- final exchangeTemplateStore = ExchangeTemplateStore(templateSource: exchangeTemplates);
117
+ final exchangeTemplateStore =
118
+ ExchangeTemplateStore(templateSource: exchangeTemplates);
119
+
120
+ final walletCreationService = WalletCreationService();
121
+ final authService = AuthService();
122
+ final appStore = AppService(
123
+ walletCreationService: walletCreationService, authService: authService);
124
125
setReactions(
126
settingsStore: settingsStore,
@@ -140,6 +149,9 @@ void main() async {
149
Provider(create: (_) => seedLanguageStore),
150
Provider(create: (_) => sendTemplateStore),
151
Provider(create: (_) => exchangeTemplateStore),
152
+ Provider(create: (_) => appStore),
153
+ Provider(create: (_) => walletCreationService),
154
+ Provider(create: (_) => authService)
155
], child: CakeWalletApp()));
156
}
157
lib/src/screens/new_wallet/new_wallet_page.dart
+65
-46
@@ -1,3 +1,7 @@
1
+import 'package:cake_wallet/core/monero_wallet_list_service.dart';
2
+import 'package:cake_wallet/core/wallet_creation_service.dart';
3
+import 'package:cake_wallet/core/wallet_credentials.dart';
4
+import 'package:cake_wallet/src/domain/common/wallet_type.dart';
5
import 'package:mobx/mobx.dart';
6
import 'package:provider/provider.dart';
7
import 'package:shared_preferences/shared_preferences.dart';
@@ -55,9 +59,13 @@ class _WalletNameFormState extends State<WalletNameForm> {
59
@override
60
Widget build(BuildContext context) {
61
final walletCreationStore = Provider.of<WalletCreationStore>(context);
62
+ final walletCreationService = Provider.of<WalletCreationService>(context);
63
+
64
+ // FIXME: Does seed language store is really needed ???
65
+
66
final seedLanguageStore = Provider.of<SeedLanguageStore>(context);
67
60
- final List<String> seedLocales = [
68
+ final seedLocales = [
69
S.current.seed_language_english,
70
S.current.seed_language_chinese,
71
S.current.seed_language_dutch,
@@ -68,13 +76,8 @@ class _WalletNameFormState extends State<WalletNameForm> {
76
S.current.seed_language_spanish
77
];
78
71
- nameController.addListener(() {
72
- if (nameController.text.isNotEmpty) {
73
- walletCreationStore.setDisabledStatus(false);
74
- } else {
75
- walletCreationStore.setDisabledStatus(true);
76
- }
77
- });
79
+ nameController.addListener(() =>
80
+ walletCreationStore.setDisabledStatus(!nameController.text.isNotEmpty));
81
82
reaction((_) => walletCreationStore.state, (WalletCreationState state) {
83
if (state is WalletCreatedSuccessfully) {
@@ -90,8 +93,7 @@ class _WalletNameFormState extends State<WalletNameForm> {
93
alertTitle: S.current.new_wallet,
94
alertContent: state.error,
95
buttonText: S.of(context).ok,
93
- buttonAction: () => Navigator.of(context).pop()
94
- );
96
+ buttonAction: () => Navigator.of(context).pop());
97
});
98
});
99
}
@@ -101,15 +103,14 @@ class _WalletNameFormState extends State<WalletNameForm> {
103
padding: EdgeInsets.only(top: 24),
104
child: ScrollableWithBottomSection(
105
contentPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
104
- content: Column(
105
- crossAxisAlignment: CrossAxisAlignment.center,
106
- children: [
107
- Padding(
108
- padding: EdgeInsets.only(left: 12, right: 12),
109
- child: AspectRatio(
110
- aspectRatio: aspectRatioImage,
111
- child: FittedBox(child: walletNameImage, fit: BoxFit.fill)),
112
- ),
106
+ content:
107
+ Column(crossAxisAlignment: CrossAxisAlignment.center, children: [
108
+ Padding(
109
+ padding: EdgeInsets.only(left: 12, right: 12),
110
+ child: AspectRatio(
111
+ aspectRatio: aspectRatioImage,
112
+ child: FittedBox(child: walletNameImage, fit: BoxFit.fill)),
113
+ ),
114
Padding(
115
padding: EdgeInsets.only(top: 24),
116
child: Form(
@@ -124,11 +125,13 @@ class _WalletNameFormState extends State<WalletNameForm> {
125
decoration: InputDecoration(
126
hintStyle: TextStyle(
127
fontSize: 16.0,
127
- color: Theme.of(context).primaryTextTheme.caption.color),
128
+ color: Theme.of(context)
129
+ .primaryTextTheme
130
+ .caption
131
+ .color),
132
hintText: S.of(context).wallet_name,
133
focusedBorder: UnderlineInputBorder(
130
- borderSide:
131
- BorderSide(
134
+ borderSide: BorderSide(
135
color: Theme.of(context).dividerColor,
136
width: 1.0)),
137
enabledBorder: UnderlineInputBorder(
@@ -141,42 +144,42 @@ class _WalletNameFormState extends State<WalletNameForm> {
144
},
145
)),
146
),
144
- Padding(padding: EdgeInsets.only(top: 40),
147
+ Padding(
148
+ padding: EdgeInsets.only(top: 40),
149
child: Text(
150
S.of(context).seed_language_choose,
151
textAlign: TextAlign.center,
152
style: TextStyle(
149
- fontSize: 16.0,
150
- fontWeight: FontWeight.w600,
151
- color: Theme.of(context).primaryTextTheme.title.color
152
- ),
153
+ fontSize: 16.0,
154
+ fontWeight: FontWeight.w600,
155
+ color: Theme.of(context).primaryTextTheme.title.color),
156
),
157
),
155
- Padding(padding: EdgeInsets.only(top: 24),
158
+ Padding(
159
+ padding: EdgeInsets.only(top: 24),
160
child: Observer(
157
- builder: (_) => SelectButton(
158
- image: null,
159
- text: seedLocales[seedLanguages.indexOf(seedLanguageStore.selectedSeedLanguage)],
160
- color: Theme.of(context).accentTextTheme.title.backgroundColor,
161
- textColor: Theme.of(context).primaryTextTheme.title.color,
162
- onTap: () async => await showDialog(
163
- context: context,
164
- builder: (BuildContext context) => SeedLanguagePicker()
165
- )
166
- )
167
- ),
161
+ builder: (_) => SelectButton(
162
+ image: null,
163
+ text: seedLocales[seedLanguages
164
+ .indexOf(seedLanguageStore.selectedSeedLanguage)],
165
+ color: Theme.of(context)
166
+ .accentTextTheme
167
+ .title
168
+ .backgroundColor,
169
+ textColor: Theme.of(context).primaryTextTheme.title.color,
170
+ onTap: () async => await showDialog(
171
+ context: context,
172
+ builder: (BuildContext context) =>
173
+ SeedLanguagePicker()))),
174
)
175
]),
170
- bottomSectionPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
176
+ bottomSectionPadding:
177
+ EdgeInsets.only(left: 24, right: 24, bottom: 24),
178
bottomSection: Observer(
179
builder: (context) {
180
return LoadingPrimaryButton(
174
- onPressed: () {
175
- if (_formKey.currentState.validate()) {
176
- walletCreationStore.create(name: nameController.text,
177
- language: seedLanguageStore.selectedSeedLanguage);
178
- }
179
- },
181
+ onPressed: () => _confirmForm(walletCreationService,
182
+ seedLanguageStore.selectedSeedLanguage),
183
text: S.of(context).continue_text,
184
color: Colors.green,
185
textColor: Colors.white,
@@ -187,4 +190,20 @@ class _WalletNameFormState extends State<WalletNameForm> {
190
)),
191
);
192
}
193
+
194
+ void _confirmForm(
195
+ WalletCreationService walletCreationService, String language) {
196
+ if (!_formKey.currentState.validate()) {
197
+ return;
198
+ }
199
+
200
+ WalletCredentials credentials;
201
+
202
+ if (walletCreationService.type == WalletType.monero) {
203
+ credentials = MoneroNewWalletCredentials(
204
+ name: nameController.text, language: language);
205
+ }
206
+
207
+ walletCreationService.create(credentials);
208
+ }
209
}