mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-08 20:09:24 +00:00
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
This commit is contained in:
parent
4b5a2f8b06
commit
9193cb63f6
5 changed files with 79 additions and 12 deletions
|
@ -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<void>(builder: (_) => DisclaimerPage());
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<ReceiveBody> {
|
|||
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<ReceiveBody> {
|
|||
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<ReceiveBody> {
|
|||
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: <Widget>[
|
||||
IconSlideAction(
|
||||
caption: S.of(context).edit,
|
||||
color: PaletteDark.walletCardSubAddressField,
|
||||
icon: Icons.edit,
|
||||
onTap: () => Navigator.of(context)
|
||||
.pushNamed(Routes.newSubaddress, arguments: subaddress),
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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<NewSubaddressForm> {
|
||||
NewSubaddressFormState(this.subaddress);
|
||||
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
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<NewSubaddressForm> {
|
|||
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:
|
||||
|
|
|
@ -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<void> 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<void> _onWalletChanged(Wallet wallet) async {
|
||||
if (wallet is MoneroWallet) {
|
||||
_account = wallet.account;
|
||||
|
|
Loading…
Reference in a new issue