From 9193cb63f6dde95f19d119254a321fcb2245dbb2 Mon Sep 17 00:00:00 2001 From: Oleksandr Sobol Date: Mon, 11 May 2020 21:00:43 +0300 Subject: [PATCH] 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 --- lib/router.dart | 2 +- lib/src/domain/monero/subaddress_list.dart | 2 +- lib/src/screens/receive/receive_page.dart | 34 +++++++++++++++-- .../subaddress/new_subaddress_page.dart | 38 ++++++++++++++++--- .../subaddress_creation_store.dart | 15 ++++++++ 5 files changed, 79 insertions(+), 12 deletions(-) diff --git a/lib/router.dart b/lib/router.dart index 0782d9a5..ff66ef62 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -258,7 +258,7 @@ class Router { builder: (_) => Provider( create: (_) => SubadrressCreationStore(walletService: walletService), - child: NewSubaddressPage())); + child: NewSubaddressPage(subaddress: settings.arguments as Subaddress,))); case Routes.disclaimer: return CupertinoPageRoute(builder: (_) => DisclaimerPage()); diff --git a/lib/src/domain/monero/subaddress_list.dart b/lib/src/domain/monero/subaddress_list.dart index 88af9374..5da67b39 100644 --- a/lib/src/domain/monero/subaddress_list.dart +++ b/lib/src/domain/monero/subaddress_list.dart @@ -50,7 +50,7 @@ class SubaddressList { {int accountIndex, int addressIndex, String label}) async { await subaddress_list.setLabelForSubaddress( accountIndex: accountIndex, addressIndex: addressIndex, label: label); - await update(); + await update(accountIndex: accountIndex); } Future refresh({int accountIndex}) async { diff --git a/lib/src/screens/receive/receive_page.dart b/lib/src/screens/receive/receive_page.dart index 83063f07..91db780d 100644 --- a/lib/src/screens/receive/receive_page.dart +++ b/lib/src/screens/receive/receive_page.dart @@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/services.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:esys_flutter_share/esys_flutter_share.dart'; +import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:provider/provider.dart'; import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/palette.dart'; @@ -77,6 +78,9 @@ class ReceiveBodyState extends State { final currentColor = PaletteDark.menuList; final notCurrentColor = PaletteDark.historyPanel; + final currentTextColor = Colors.blue; + final notCurrentTextColor = PaletteDark.walletCardText; + amountController.addListener(() { if (_formKey.currentState.validate()) { walletStore.onChangedAmountValue(amountController.text); @@ -253,9 +257,11 @@ class ReceiveBodyState extends State { final isCurrent = walletStore.subaddress.address == subaddress.address; - final label = subaddress.label; + final label = subaddress.label.isNotEmpty + ? subaddress.label + : subaddress.address; - return InkWell( + final content = InkWell( onTap: () => walletStore.setSubaddress(subaddress), child: Container( color: isCurrent ? currentColor : notCurrentColor, @@ -268,13 +274,33 @@ class ReceiveBodyState extends State { child: Text( label, style: TextStyle( - fontSize: 18, + fontSize: subaddress.label.isNotEmpty + ? 18 : 10, fontWeight: FontWeight.bold, - color: PaletteDark.walletCardText + color: isCurrent + ? currentTextColor + : notCurrentTextColor, ), ), ), ); + + return isCurrent + ? content + : Slidable( + key: Key(subaddress.address), + actionPane: SlidableDrawerActionPane(), + child: content, + secondaryActions: [ + IconSlideAction( + caption: S.of(context).edit, + color: PaletteDark.walletCardSubAddressField, + icon: Icons.edit, + onTap: () => Navigator.of(context) + .pushNamed(Routes.newSubaddress, arguments: subaddress), + ) + ] + ); } ); } diff --git a/lib/src/screens/subaddress/new_subaddress_page.dart b/lib/src/screens/subaddress/new_subaddress_page.dart index 5f2d0f0b..25dd46b0 100644 --- a/lib/src/screens/subaddress/new_subaddress_page.dart +++ b/lib/src/screens/subaddress/new_subaddress_page.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/src/domain/monero/subaddress.dart'; import 'package:mobx/mobx.dart'; import 'package:provider/provider.dart'; import 'package:flutter/cupertino.dart'; @@ -12,6 +13,10 @@ import 'package:cake_wallet/palette.dart'; import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; class NewSubaddressPage extends BasePage { + NewSubaddressPage({this.subaddress}); + + final Subaddress subaddress; + @override String get title => S.current.new_subaddress_title; @@ -19,7 +24,7 @@ class NewSubaddressPage extends BasePage { Color get backgroundColor => PaletteDark.historyPanel; @override - Widget body(BuildContext context) => NewSubaddressForm(); + Widget body(BuildContext context) => NewSubaddressForm(subaddress); @override Widget build(BuildContext context) { @@ -38,13 +43,26 @@ class NewSubaddressPage extends BasePage { } class NewSubaddressForm extends StatefulWidget { + NewSubaddressForm(this.subaddress); + + final Subaddress subaddress; + @override - NewSubaddressFormState createState() => NewSubaddressFormState(); + NewSubaddressFormState createState() => NewSubaddressFormState(subaddress); } class NewSubaddressFormState extends State { + NewSubaddressFormState(this.subaddress); + final _formKey = GlobalKey(); final _labelController = TextEditingController(); + final Subaddress subaddress; + + @override + void initState() { + if (subaddress != null) _labelController.text = subaddress.label; + super.initState(); + } @override void dispose() { @@ -88,12 +106,20 @@ class NewSubaddressFormState extends State { builder: (_) => LoadingPrimaryButton( onPressed: () async { if (_formKey.currentState.validate()) { - await subaddressCreationStore.add( - label: _labelController.text); - Navigator.of(context).pop(); + if (subaddress != null) { + await subaddressCreationStore.setLabel( + addressIndex: subaddress.id, + label: _labelController.text + ); + } else { + await subaddressCreationStore.add( + label: _labelController.text); + } } }, - text: S.of(context).new_subaddress_create, + text: subaddress != null + ? S.of(context).rename + : S.of(context).new_subaddress_create, color: Colors.green, textColor: Colors.white, isLoading: diff --git a/lib/src/stores/subaddress_creation/subaddress_creation_store.dart b/lib/src/stores/subaddress_creation/subaddress_creation_store.dart index a633185e..ab294f7c 100644 --- a/lib/src/stores/subaddress_creation/subaddress_creation_store.dart +++ b/lib/src/stores/subaddress_creation/subaddress_creation_store.dart @@ -27,6 +27,7 @@ abstract class SubadrressCreationStoreBase with Store { walletService.onWalletChange.listen(_onWalletChanged); } + @observable SubaddressCreationState state; @observable @@ -70,6 +71,20 @@ abstract class SubadrressCreationStoreBase with Store { } } + Future setLabel({int addressIndex, String label}) async { + try { + state = SubaddressIsCreating(); + await _subaddressList.setLabelSubaddress( + accountIndex: _account.id, + addressIndex: addressIndex, + label: label + ); + state = SubaddressCreatedSuccessfully(); + } catch (e) { + state = SubaddressCreationFailure(error: e.toString()); + } + } + Future _onWalletChanged(Wallet wallet) async { if (wallet is MoneroWallet) { _account = wallet.account;