CAKE-92 | fixed templates saving bug on send and exchange pages; added comma for keyboard on templates pages; added fiat amount controller to send page; added crypto amount and fiat amount controllers to send template pages; added send template store to send view model; added updateTemplate(), addTemplate(), removeTemplate() to send view model and exchange view model; fixed remove template alert on send and exchange pages
OleksandrSobol committed
Oct 7, 2020 at 08:58 UTC
521d7294a7ad47eb5b443f4cb74faad4e7cd9362
7 files changed
+138
-78
lib/di.dart
+5
-5
@@ -222,10 +222,10 @@ Future setup(
222
addressEditOrCreateViewModel:
223
getIt.get<WalletAddressEditOrCreateViewModel>(param1: item)));
224
225
- // getIt.get<SendTemplateStore>()
225
getIt.registerFactory<SendViewModel>(() => SendViewModel(
226
getIt.get<AppStore>().wallet,
227
getIt.get<AppStore>().settingsStore,
228
+ getIt.get<SendTemplateStore>(),
229
getIt.get<FiatConversionStore>()));
230
231
getIt.registerFactory(
@@ -318,10 +318,10 @@ Future setup(
318
() => NodeCreateOrEditPage(getIt.get<NodeCreateOrEditViewModel>()));
319
320
getIt.registerFactory(() => ExchangeViewModel(
321
- wallet: getIt.get<AppStore>().wallet,
322
- exchangeTemplateStore: getIt.get<ExchangeTemplateStore>(),
323
- trades: tradesSource,
324
- tradesStore: getIt.get<TradesStore>()));
321
+ getIt.get<AppStore>().wallet,
322
+ tradesSource,
323
+ getIt.get<ExchangeTemplateStore>(),
324
+ getIt.get<TradesStore>()));
325
326
getIt.registerFactory(() => ExchangeTradeViewModel(
327
wallet: getIt.get<AppStore>().wallet,
lib/src/screens/exchange/exchange_page.dart
+7
-10
@@ -307,8 +307,7 @@ class ExchangePage extends BasePage {
307
),
308
Observer(builder: (_) {
309
final templates = exchangeViewModel.templates;
310
- final itemCount =
311
- exchangeViewModel.templates.length;
310
+ final itemCount = templates.length;
311
312
return ListView.builder(
313
scrollDirection: Axis.horizontal,
@@ -338,24 +337,22 @@ class ExchangePage extends BasePage {
337
alertContent: S
338
.of(context)
339
.confirm_delete_template,
341
- leftButtonText:
342
- S.of(context).delete,
340
rightButtonText:
341
+ S.of(context).delete,
342
+ leftButtonText:
343
S.of(context).cancel,
345
- actionLeftButton: () {
344
+ actionRightButton: () {
345
Navigator.of(
346
dialogContext)
347
.pop();
348
exchangeViewModel
350
- .exchangeTemplateStore
351
- .remove(
349
+ .removeTemplate(
350
template:
351
template);
352
exchangeViewModel
355
- .exchangeTemplateStore
356
- .update();
353
+ .updateTemplate();
354
},
358
- actionRightButton: () =>
355
+ actionLeftButton: () =>
356
Navigator.of(
357
dialogContext)
358
.pop());
lib/src/screens/exchange/exchange_template_page.dart
+3
-2
@@ -134,6 +134,7 @@ class ExchangeTemplatePage extends BasePage {
134
initialIsAddressEditable: exchangeViewModel
135
.isDepositAddressEnabled,
136
isAmountEstimated: false,
137
+ hasRefundAddress: true,
138
currencies: CryptoCurrency.all,
139
onCurrencySelected: (currency) =>
140
exchangeViewModel.changeDepositCurrency(
@@ -220,7 +221,7 @@ class ExchangeTemplatePage extends BasePage {
221
PrimaryButton(
222
onPressed: () {
223
if (_formKey.currentState.validate()) {
223
- exchangeViewModel.exchangeTemplateStore.addTemplate(
224
+ exchangeViewModel.addTemplate(
225
amount: exchangeViewModel.depositAmount,
226
depositCurrency:
227
exchangeViewModel.depositCurrency.toString(),
@@ -229,7 +230,7 @@ class ExchangeTemplatePage extends BasePage {
230
provider: exchangeViewModel.provider.toString(),
231
depositAddress: exchangeViewModel.depositAddress,
232
receiveAddress: exchangeViewModel.receiveAddress);
232
- exchangeViewModel.exchangeTemplateStore.update();
233
+ exchangeViewModel.updateTemplate();
234
Navigator.of(context).pop();
235
}
236
},
lib/src/screens/send/send_page.dart
+57
-47
@@ -1,7 +1,9 @@
1
import 'dart:ui';
2
import 'package:cake_wallet/entities/transaction_priority.dart';
3
+import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
4
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
5
import 'package:cake_wallet/src/widgets/picker.dart';
6
+import 'package:cake_wallet/src/widgets/template_tile.dart';
7
import 'package:flutter/cupertino.dart';
8
import 'package:flutter/material.dart';
9
import 'package:flutter/services.dart';
@@ -416,53 +418,53 @@ class SendPage extends BasePage {
418
)),
419
),
420
),
419
- // Observer(
420
- // builder: (_) {
421
- // final templates = sendViewModel.templates;
422
- // final itemCount = templates.length;
423
-
424
- // return ListView.builder(
425
- // scrollDirection: Axis.horizontal,
426
- // shrinkWrap: true,
427
- // physics: NeverScrollableScrollPhysics(),
428
- // itemCount: itemCount,
429
- // itemBuilder: (context, index) {
430
- // final template = templates[index];
431
-
432
- // return TemplateTile(
433
- // key: UniqueKey(),
434
- // to: template.name,
435
- // amount: template.amount,
436
- // from: template.cryptoCurrency,
437
- // onTap: () {
438
- // _addressController.text = template.address;
439
- // _cryptoAmountController.text = template.amount;
440
- // getOpenaliasRecord(context);
441
- // },
442
- // onRemove: () {
443
- // showPopUp<void>(
444
- // context: context,
445
- // builder: (dialogContext) {
446
- // return AlertWithTwoActions(
447
- // alertTitle: S.of(context).template,
448
- // alertContent: S.of(context).confirm_delete_template,
449
- // leftButtonText: S.of(context).delete,
450
- // rightButtonText: S.of(context).cancel,
451
- // actionLeftButton: () {
452
- // Navigator.of(dialogContext).pop();
453
- // sendViewModel.sendTemplateStore.remove(template: template);
454
- // sendViewModel.sendTemplateStore.update();
455
- // },
456
- // actionRightButton: () => Navigator.of(dialogContext).pop()
457
- // );
458
- // }
459
- // );
460
- // },
461
- // );
462
- // }
463
- // );
464
- // }
465
- // )
421
+ Observer(
422
+ builder: (_) {
423
+ final templates = sendViewModel.templates;
424
+ final itemCount = templates.length;
425
+
426
+ return ListView.builder(
427
+ scrollDirection: Axis.horizontal,
428
+ shrinkWrap: true,
429
+ physics: NeverScrollableScrollPhysics(),
430
+ itemCount: itemCount,
431
+ itemBuilder: (context, index) {
432
+ final template = templates[index];
433
+
434
+ return TemplateTile(
435
+ key: UniqueKey(),
436
+ to: template.name,
437
+ amount: template.amount,
438
+ from: template.cryptoCurrency,
439
+ onTap: () {
440
+ _addressController.text = template.address;
441
+ _cryptoAmountController.text = template.amount;
442
+ getOpenaliasRecord(context);
443
+ },
444
+ onRemove: () {
445
+ showPopUp<void>(
446
+ context: context,
447
+ builder: (dialogContext) {
448
+ return AlertWithTwoActions(
449
+ alertTitle: S.of(context).template,
450
+ alertContent: S.of(context).confirm_delete_template,
451
+ rightButtonText: S.of(context).delete,
452
+ leftButtonText: S.of(context).cancel,
453
+ actionRightButton: () {
454
+ Navigator.of(dialogContext).pop();
455
+ sendViewModel.removeTemplate(template: template);
456
+ sendViewModel.updateTemplate();
457
+ },
458
+ actionLeftButton: () => Navigator.of(dialogContext).pop()
459
+ );
460
+ }
461
+ );
462
+ },
463
+ );
464
+ }
465
+ );
466
+ }
467
+ )
468
],
469
),
470
),
@@ -507,6 +509,14 @@ class SendPage extends BasePage {
509
}
510
});
511
512
+ _fiatAmountController.addListener(() {
513
+ final amount = _fiatAmountController.text;
514
+
515
+ if (amount != sendViewModel.fiatAmount) {
516
+ sendViewModel.setFiatAmount(amount);
517
+ }
518
+ });
519
+
520
reaction((_) => sendViewModel.sendAll, (bool all) {
521
if (all) {
522
_cryptoAmountController.text = S.current.all;
lib/src/screens/send/send_template_page.dart
+24
-8
@@ -134,7 +134,7 @@ class SendTemplatePage extends BasePage {
134
signed: false, decimal: true),
135
inputFormatters: [
136
BlacklistingTextInputFormatter(
137
- RegExp('[\\-|\\ |\\,]'))
137
+ RegExp('[\\-|\\ ]'))
138
],
139
prefixIcon: Padding(
140
padding: EdgeInsets.only(top: 9),
@@ -172,7 +172,7 @@ class SendTemplatePage extends BasePage {
172
signed: false, decimal: true),
173
inputFormatters: [
174
BlacklistingTextInputFormatter(
175
- RegExp('[\\-|\\ |\\,]'))
175
+ RegExp('[\\-|\\ ]'))
176
],
177
prefixIcon: Padding(
178
padding: EdgeInsets.only(top: 9),
@@ -210,12 +210,12 @@ class SendTemplatePage extends BasePage {
210
bottomSection: PrimaryButton(
211
onPressed: () {
212
if (_formKey.currentState.validate()) {
213
- // sendViewModel.sendTemplateStore.addTemplate(
214
- // name: _nameController.text,
215
- // address: _addressController.text,
216
- // cryptoCurrency: sendViewModel.currency.title,
217
- // amount: _cryptoAmountController.text);
218
- // sendViewModel.sendTemplateStore.update();
213
+ sendViewModel.addTemplate(
214
+ name: _nameController.text,
215
+ address: _addressController.text,
216
+ cryptoCurrency: sendViewModel.currency.title,
217
+ amount: _cryptoAmountController.text);
218
+ sendViewModel.updateTemplate();
219
Navigator.of(context).pop();
220
}
221
},
@@ -249,6 +249,22 @@ class SendTemplatePage extends BasePage {
249
}
250
});
251
252
+ _cryptoAmountController.addListener(() {
253
+ final amount = _cryptoAmountController.text;
254
+
255
+ if (amount != sendViewModel.cryptoAmount) {
256
+ sendViewModel.setCryptoAmount(amount);
257
+ }
258
+ });
259
+
260
+ _fiatAmountController.addListener(() {
261
+ final amount = _fiatAmountController.text;
262
+
263
+ if (amount != sendViewModel.fiatAmount) {
264
+ sendViewModel.setFiatAmount(amount);
265
+ }
266
+ });
267
+
268
_addressController.addListener(() {
269
final address = _addressController.text;
270
lib/view_model/exchange/exchange_view_model.dart
+21
-5
@@ -27,10 +27,10 @@ class ExchangeViewModel = ExchangeViewModelBase with _$ExchangeViewModel;
27
28
abstract class ExchangeViewModelBase with Store {
29
ExchangeViewModelBase(
30
- {this.wallet,
30
+ this.wallet,
31
this.trades,
32
- this.exchangeTemplateStore,
33
- this.tradesStore}) {
32
+ this._exchangeTemplateStore,
33
+ this.tradesStore) {
34
providerList = [
35
XMRTOExchangeProvider(),
36
ChangeNowExchangeProvider(),
@@ -54,7 +54,7 @@ abstract class ExchangeViewModelBase with Store {
54
55
final WalletBase wallet;
56
final Box<Trade> trades;
57
- final ExchangeTemplateStore exchangeTemplateStore;
57
+ final ExchangeTemplateStore _exchangeTemplateStore;
58
final TradesStore tradesStore;
59
60
@observable
@@ -101,7 +101,7 @@ abstract class ExchangeViewModelBase with Store {
101
102
@computed
103
ObservableList<ExchangeTemplate> get templates =>
104
- exchangeTemplateStore.templates;
104
+ _exchangeTemplateStore.templates;
105
106
@action
107
void changeProvider({ExchangeProvider provider}) {
@@ -267,6 +267,22 @@ abstract class ExchangeViewModelBase with Store {
267
_onPairChange();
268
}
269
270
+ void updateTemplate() => _exchangeTemplateStore.update();
271
+
272
+ void addTemplate({String amount, String depositCurrency, String receiveCurrency,
273
+ String provider, String depositAddress, String receiveAddress}) =>
274
+ _exchangeTemplateStore.addTemplate(
275
+ amount: amount,
276
+ depositCurrency: depositCurrency,
277
+ receiveCurrency: receiveCurrency,
278
+ provider: provider,
279
+ depositAddress: depositAddress,
280
+ receiveAddress: receiveAddress
281
+ );
282
+
283
+ void removeTemplate({ExchangeTemplate template}) =>
284
+ _exchangeTemplateStore.remove(template: template);
285
+
286
List<ExchangeProvider> providersForCurrentPair() {
287
return _providersForPair(from: depositCurrency, to: receiveCurrency);
288
}
lib/view_model/send/send_view_model.dart
+21
-1
@@ -1,4 +1,6 @@
1
import 'package:cake_wallet/entities/openalias_record.dart';
2
+import 'package:cake_wallet/entities/template.dart';
3
+import 'package:cake_wallet/store/templates/send_template_store.dart';
4
import 'package:intl/intl.dart';
5
import 'package:mobx/mobx.dart';
6
import 'package:cake_wallet/core/template_validator.dart';
@@ -29,7 +31,8 @@ class SendViewModel = SendViewModelBase with _$SendViewModel;
31
32
abstract class SendViewModelBase with Store {
33
SendViewModelBase(
32
- this._wallet, this._settingsStore, this._fiatConversationStore)
34
+ this._wallet, this._settingsStore, this._sendTemplateStore,
35
+ this._fiatConversationStore)
36
: state = InitialExecutionState(),
37
_cryptoNumberFormat = NumberFormat(),
38
sendAll = false {
@@ -88,8 +91,12 @@ abstract class SendViewModelBase with Store {
91
@computed
92
bool get isReadyForSend => _wallet.syncStatus is SyncedSyncStatus;
93
94
+ @computed
95
+ ObservableList<Template> get templates => _sendTemplateStore.templates;
96
+
97
final WalletBase _wallet;
98
final SettingsStore _settingsStore;
99
+ final SendTemplateStore _sendTemplateStore;
100
final FiatConversionStore _fiatConversationStore;
101
final NumberFormat _cryptoNumberFormat;
102
@@ -219,4 +226,17 @@ abstract class SendViewModelBase with Store {
226
227
_cryptoNumberFormat.maximumFractionDigits = maximumFractionDigits;
228
}
229
+
230
+ void updateTemplate() => _sendTemplateStore.update();
231
+
232
+ void addTemplate({String name, String address, String cryptoCurrency,
233
+ String amount}) => _sendTemplateStore
234
+ .addTemplate(
235
+ name: name,
236
+ address: address,
237
+ cryptoCurrency: cryptoCurrency,
238
+ amount: amount);
239
+
240
+ void removeTemplate({Template template}) =>
241
+ _sendTemplateStore.remove(template: template);
242
}