CWA-209 | added possibility to show address of subaddress instead empty label; added possibility to edit label of subaddress; added setLabel method to subaddress creation store; fixed setLabelSubaddress method in the subaddress_list.dart
Oleksandr Sobol committed
May 11, 2020 at 21:00 UTC
9193cb63f6dde95f19d119254a321fcb2245dbb2
5 files changed
+79
-12
lib/router.dart
+1
-1
@@ -258,7 +258,7 @@ class Router {
258
builder: (_) => Provider(
259
create: (_) =>
260
SubadrressCreationStore(walletService: walletService),
261
- child: NewSubaddressPage()));
261
+ child: NewSubaddressPage(subaddress: settings.arguments as Subaddress,)));
262
263
case Routes.disclaimer:
264
return CupertinoPageRoute<void>(builder: (_) => DisclaimerPage());
lib/src/domain/monero/subaddress_list.dart
+1
-1
@@ -50,7 +50,7 @@ class SubaddressList {
50
{int accountIndex, int addressIndex, String label}) async {
51
await subaddress_list.setLabelForSubaddress(
52
accountIndex: accountIndex, addressIndex: addressIndex, label: label);
53
- await update();
53
+ await update(accountIndex: accountIndex);
54
}
55
56
Future refresh({int accountIndex}) async {
lib/src/screens/receive/receive_page.dart
+30
-4
@@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart';
3
import 'package:flutter/services.dart';
4
import 'package:flutter_mobx/flutter_mobx.dart';
5
import 'package:esys_flutter_share/esys_flutter_share.dart';
6
+import 'package:flutter_slidable/flutter_slidable.dart';
7
import 'package:provider/provider.dart';
8
import 'package:cake_wallet/routes.dart';
9
import 'package:cake_wallet/palette.dart';
@@ -77,6 +78,9 @@ class ReceiveBodyState extends State<ReceiveBody> {
78
final currentColor = PaletteDark.menuList;
79
final notCurrentColor = PaletteDark.historyPanel;
80
81
+ final currentTextColor = Colors.blue;
82
+ final notCurrentTextColor = PaletteDark.walletCardText;
83
+
84
amountController.addListener(() {
85
if (_formKey.currentState.validate()) {
86
walletStore.onChangedAmountValue(amountController.text);
@@ -253,9 +257,11 @@ class ReceiveBodyState extends State<ReceiveBody> {
257
final isCurrent =
258
walletStore.subaddress.address == subaddress.address;
259
256
- final label = subaddress.label;
260
+ final label = subaddress.label.isNotEmpty
261
+ ? subaddress.label
262
+ : subaddress.address;
263
258
- return InkWell(
264
+ final content = InkWell(
265
onTap: () => walletStore.setSubaddress(subaddress),
266
child: Container(
267
color: isCurrent ? currentColor : notCurrentColor,
@@ -268,13 +274,33 @@ class ReceiveBodyState extends State<ReceiveBody> {
274
child: Text(
275
label,
276
style: TextStyle(
271
- fontSize: 18,
277
+ fontSize: subaddress.label.isNotEmpty
278
+ ? 18 : 10,
279
fontWeight: FontWeight.bold,
273
- color: PaletteDark.walletCardText
280
+ color: isCurrent
281
+ ? currentTextColor
282
+ : notCurrentTextColor,
283
),
284
),
285
),
286
);
287
+
288
+ return isCurrent
289
+ ? content
290
+ : Slidable(
291
+ key: Key(subaddress.address),
292
+ actionPane: SlidableDrawerActionPane(),
293
+ child: content,
294
+ secondaryActions: <Widget>[
295
+ IconSlideAction(
296
+ caption: S.of(context).edit,
297
+ color: PaletteDark.walletCardSubAddressField,
298
+ icon: Icons.edit,
299
+ onTap: () => Navigator.of(context)
300
+ .pushNamed(Routes.newSubaddress, arguments: subaddress),
301
+ )
302
+ ]
303
+ );
304
}
305
);
306
}
lib/src/screens/subaddress/new_subaddress_page.dart
+32
-6
@@ -1,3 +1,4 @@
1
+import 'package:cake_wallet/src/domain/monero/subaddress.dart';
2
import 'package:mobx/mobx.dart';
3
import 'package:provider/provider.dart';
4
import 'package:flutter/cupertino.dart';
@@ -12,6 +13,10 @@ import 'package:cake_wallet/palette.dart';
13
import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
14
15
class NewSubaddressPage extends BasePage {
16
+ NewSubaddressPage({this.subaddress});
17
+
18
+ final Subaddress subaddress;
19
+
20
@override
21
String get title => S.current.new_subaddress_title;
22
@@ -19,7 +24,7 @@ class NewSubaddressPage extends BasePage {
24
Color get backgroundColor => PaletteDark.historyPanel;
25
26
@override
22
- Widget body(BuildContext context) => NewSubaddressForm();
27
+ Widget body(BuildContext context) => NewSubaddressForm(subaddress);
28
29
@override
30
Widget build(BuildContext context) {
@@ -38,13 +43,26 @@ class NewSubaddressPage extends BasePage {
43
}
44
45
class NewSubaddressForm extends StatefulWidget {
46
+ NewSubaddressForm(this.subaddress);
47
+
48
+ final Subaddress subaddress;
49
+
50
@override
42
- NewSubaddressFormState createState() => NewSubaddressFormState();
51
+ NewSubaddressFormState createState() => NewSubaddressFormState(subaddress);
52
}
53
54
class NewSubaddressFormState extends State<NewSubaddressForm> {
55
+ NewSubaddressFormState(this.subaddress);
56
+
57
final _formKey = GlobalKey<FormState>();
58
final _labelController = TextEditingController();
59
+ final Subaddress subaddress;
60
+
61
+ @override
62
+ void initState() {
63
+ if (subaddress != null) _labelController.text = subaddress.label;
64
+ super.initState();
65
+ }
66
67
@override
68
void dispose() {
@@ -88,12 +106,20 @@ class NewSubaddressFormState extends State<NewSubaddressForm> {
106
builder: (_) => LoadingPrimaryButton(
107
onPressed: () async {
108
if (_formKey.currentState.validate()) {
91
- await subaddressCreationStore.add(
92
- label: _labelController.text);
93
- Navigator.of(context).pop();
109
+ if (subaddress != null) {
110
+ await subaddressCreationStore.setLabel(
111
+ addressIndex: subaddress.id,
112
+ label: _labelController.text
113
+ );
114
+ } else {
115
+ await subaddressCreationStore.add(
116
+ label: _labelController.text);
117
+ }
118
}
119
},
96
- text: S.of(context).new_subaddress_create,
120
+ text: subaddress != null
121
+ ? S.of(context).rename
122
+ : S.of(context).new_subaddress_create,
123
color: Colors.green,
124
textColor: Colors.white,
125
isLoading:
lib/src/stores/subaddress_creation/subaddress_creation_store.dart
+15
@@ -27,6 +27,7 @@ abstract class SubadrressCreationStoreBase with Store {
27
walletService.onWalletChange.listen(_onWalletChanged);
28
}
29
30
+ @observable
31
SubaddressCreationState state;
32
33
@observable
@@ -70,6 +71,20 @@ abstract class SubadrressCreationStoreBase with Store {
71
}
72
}
73
74
+ Future<void> setLabel({int addressIndex, String label}) async {
75
+ try {
76
+ state = SubaddressIsCreating();
77
+ await _subaddressList.setLabelSubaddress(
78
+ accountIndex: _account.id,
79
+ addressIndex: addressIndex,
80
+ label: label
81
+ );
82
+ state = SubaddressCreatedSuccessfully();
83
+ } catch (e) {
84
+ state = SubaddressCreationFailure(error: e.toString());
85
+ }
86
+ }
87
+
88
Future<void> _onWalletChanged(Wallet wallet) async {
89
if (wallet is MoneroWallet) {
90
_account = wallet.account;