From 3b649ef6829628ff6a4bb5a6b431605c99288ad8 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Wed, 22 Sep 2021 16:47:10 +0300 Subject: [PATCH] CAKE-359 | added text field for extracted (from Yat, Unstoppable Domains, OpenAlias) address to send_card.dart; added extractedAddress and isParsedAddress parameters to output.dart; applied extractedAddress to monero_wallet.dart and electrum_wallet.dart; added TextValidator to send_view_model.dart --- lib/bitcoin/electrum_wallet.dart | 6 +- lib/monero/monero_wallet.dart | 18 ++- lib/src/screens/send/send_page.dart | 1 - .../send/widgets/confirm_sending_alert.dart | 17 ++- lib/src/screens/send/widgets/send_card.dart | 130 +++++++++++------- lib/view_model/send/output.dart | 11 +- lib/view_model/send/send_view_model.dart | 2 + 7 files changed, 116 insertions(+), 69 deletions(-) diff --git a/lib/bitcoin/electrum_wallet.dart b/lib/bitcoin/electrum_wallet.dart index b2f5cf563..d8024104c 100644 --- a/lib/bitcoin/electrum_wallet.dart +++ b/lib/bitcoin/electrum_wallet.dart @@ -280,8 +280,12 @@ abstract class ElectrumWalletBase extends WalletBase - MoneroOutput( - address: output.address, - amount: output.cryptoAmount.replaceAll(',', '.'))) - .toList(); + final moneroOutputs = outputs.map((output) { + final outputAddress = output.isParsedAddress + ? output.extractedAddress + : output.address; + + return MoneroOutput( + address: outputAddress, + amount: output.cryptoAmount.replaceAll(',', '.')); + }).toList(); pendingTransactionDescription = await transaction_history.createTransactionMultDest( @@ -188,7 +192,9 @@ abstract class MoneroWalletBase extends WalletBase itemCount: itemCount, itemBuilder: (context, index) { final item = outputs[index]; - final _address = item.address; + final _address = item.isParsedAddress + ? item.extractedAddress + : item.address; final _amount = item.cryptoAmount.replaceAll(',', '.'); - final isParsedAddress = - item.parsedAddress.parseFrom != - ParseFrom.notParsed; return Column( children: [ - if (isParsedAddress) Padding( + if (item.isParsedAddress) Padding( padding: EdgeInsets.only(top: 8), child: Text( item.parsedAddress.name, @@ -334,8 +332,7 @@ class ConfirmSendingAlertContentState extends State }) : Column( children: [ - if (outputs.first.parsedAddress.parseFrom != - ParseFrom.notParsed) Padding( + if (outputs.first.isParsedAddress) Padding( padding: EdgeInsets.only(top: 8), child: Text( outputs.first.parsedAddress.name, @@ -352,7 +349,9 @@ class ConfirmSendingAlertContentState extends State Padding( padding: EdgeInsets.only(top: 8), child: Text( - outputs.first.address, + outputs.first.isParsedAddress + ? outputs.first.extractedAddress + : outputs.first.address, style: TextStyle( fontSize: 10, fontWeight: FontWeight.w600, diff --git a/lib/src/screens/send/widgets/send_card.dart b/lib/src/screens/send/widgets/send_card.dart index ad32b2905..2f08cc143 100644 --- a/lib/src/screens/send/widgets/send_card.dart +++ b/lib/src/screens/send/widgets/send_card.dart @@ -1,7 +1,6 @@ import 'dart:ui'; import 'package:cake_wallet/entities/transaction_priority.dart'; import 'package:cake_wallet/routes.dart'; -import 'package:cake_wallet/src/screens/send/widgets/parse_address_from_domain_alert.dart'; import 'package:cake_wallet/src/widgets/keyboard_done_button.dart'; import 'package:cake_wallet/src/widgets/picker.dart'; import 'package:cake_wallet/view_model/send/output.dart'; @@ -38,6 +37,7 @@ class SendCardState extends State cryptoAmountController = TextEditingController(), fiatAmountController = TextEditingController(), noteController = TextEditingController(), + extractedAddressController = TextEditingController(), cryptoAmountFocus = FocusNode(), fiatAmountFocus = FocusNode(), addressFocusNode = FocusNode(); @@ -52,6 +52,7 @@ class SendCardState extends State final TextEditingController cryptoAmountController; final TextEditingController fiatAmountController; final TextEditingController noteController; + final TextEditingController extractedAddressController; final FocusNode cryptoAmountFocus; final FocusNode fiatAmountFocus; final FocusNode addressFocusNode; @@ -101,58 +102,80 @@ class SendCardState extends State child: Padding( padding: EdgeInsets.fromLTRB(24, 100, 24, 32), child: SingleChildScrollView( - child: Column( + child: Observer(builder: (_) => Column( mainAxisSize: MainAxisSize.min, children: [ - AddressTextField( - focusNode: addressFocusNode, - controller: addressController, - onURIScanned: (uri) { - var address = ''; - var amount = ''; + Observer(builder: (_) { + final validator = output.isParsedAddress + ? sendViewModel.textValidator + : sendViewModel.addressValidator; - if (uri != null) { - address = uri.path; - amount = uri.queryParameters['tx_amount'] ?? - uri.queryParameters['amount']; - } else { - address = uri.toString(); - } + return AddressTextField( + focusNode: addressFocusNode, + controller: addressController, + onURIScanned: (uri) { + var address = ''; + var amount = ''; - addressController.text = address; - cryptoAmountController.text = amount; - }, - options: [ - AddressTextFieldOption.paste, - AddressTextFieldOption.qrCode, - AddressTextFieldOption.addressBook - ], - buttonColor: Theme.of(context) - .primaryTextTheme - .display1 - .color, - borderColor: Theme.of(context) - .primaryTextTheme - .headline - .color, - textStyle: TextStyle( - fontSize: 14, - fontWeight: FontWeight.w500, - color: Colors.white), - hintStyle: TextStyle( - fontSize: 14, - fontWeight: FontWeight.w500, - color: Theme.of(context) - .primaryTextTheme - .headline - .decorationColor), - onPushPasteButton: (context) async { - output.resetParsedAddress(); - await output.fetchParsedAddress(context); - }, - onPushAddressBookButton: (context) => - output.resetParsedAddress(), - validator: sendViewModel.addressValidator, + if (uri != null) { + address = uri.path; + amount = uri.queryParameters['tx_amount'] ?? + uri.queryParameters['amount']; + } else { + address = uri.toString(); + } + + addressController.text = address; + cryptoAmountController.text = amount; + }, + options: [ + AddressTextFieldOption.paste, + AddressTextFieldOption.qrCode, + AddressTextFieldOption.addressBook + ], + buttonColor: Theme.of(context) + .primaryTextTheme + .display1 + .color, + borderColor: Theme.of(context) + .primaryTextTheme + .headline + .color, + textStyle: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w500, + color: Colors.white), + hintStyle: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w500, + color: Theme.of(context) + .primaryTextTheme + .headline + .decorationColor), + onPushPasteButton: (context) async { + output.resetParsedAddress(); + await output.fetchParsedAddress(context); + }, + onPushAddressBookButton: (context) => + output.resetParsedAddress(), + validator: validator, + ); + }), + if (output.isParsedAddress) Padding( + padding: const EdgeInsets.only(top: 20), + child: BaseTextFormField( + controller: extractedAddressController, + readOnly: true, + borderColor: Theme.of(context) + .primaryTextTheme + .headline + .color, + textStyle: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w500, + color: Colors.white), + validator: sendViewModel.addressValidator + ) ), Observer( builder: (_) => Padding( @@ -440,7 +463,7 @@ class SendCardState extends State ) ) ], - ) + )) ), ), ) @@ -453,6 +476,7 @@ class SendCardState extends State cryptoAmountController.text = output.cryptoAmount; fiatAmountController.text = output.fiatAmount; noteController.text = output.note; + extractedAddressController.text = output.extractedAddress; if (_effectsInstalled) { return; @@ -520,6 +544,7 @@ class SendCardState extends State final address = addressController.text; if (output.address != address) { + output.resetParsedAddress(); output.address = address; } }); @@ -532,11 +557,14 @@ class SendCardState extends State addressFocusNode.addListener(() async { if (!addressFocusNode.hasFocus && addressController.text.isNotEmpty) { - output.resetParsedAddress(); await output.fetchParsedAddress(context); } }); + reaction((_) => output.extractedAddress, (String extractedAddress) { + extractedAddressController.text = extractedAddress; + }); + _effectsInstalled = true; } diff --git a/lib/view_model/send/output.dart b/lib/view_model/send/output.dart index 85f97b97b..5d6d7b835 100644 --- a/lib/view_model/send/output.dart +++ b/lib/view_model/send/output.dart @@ -47,8 +47,16 @@ abstract class OutputBase with Store { @observable bool sendAll; + @observable ParsedAddress parsedAddress; + @observable + String extractedAddress; + + @computed + bool get isParsedAddress => parsedAddress.parseFrom != ParseFrom.notParsed + && parsedAddress.name.isNotEmpty; + @computed int get formattedCryptoAmount { int amount = 0; @@ -134,6 +142,7 @@ abstract class OutputBase with Store { } void resetParsedAddress() { + extractedAddress = ''; parsedAddress = ParsedAddress(addresses: []); } @@ -206,6 +215,6 @@ abstract class OutputBase with Store { final domain = address; final ticker = _wallet.currency.title.toLowerCase(); parsedAddress = await parseAddressFromDomain(domain, ticker); - address = await defineAddress(context, parsedAddress); + extractedAddress = await defineAddress(context, parsedAddress); } } \ No newline at end of file diff --git a/lib/view_model/send/send_view_model.dart b/lib/view_model/send/send_view_model.dart index 650b74023..2fc37e7a1 100644 --- a/lib/view_model/send/send_view_model.dart +++ b/lib/view_model/send/send_view_model.dart @@ -117,6 +117,8 @@ abstract class SendViewModelBase with Store { Validator get addressValidator => AddressValidator(type: _wallet.currency); + Validator get textValidator => TextValidator(); + @observable PendingTransaction pendingTransaction;