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

This commit is contained in:
OleksandrSobol
2021-09-22 16:47:10 +03:00
parent 9958f6c2e0
commit 3b649ef682
7 changed files with 116 additions and 69 deletions
-1
View File
@@ -1,5 +1,4 @@
import 'dart:ui';
import 'package:cake_wallet/src/screens/send/widgets/parse_address_from_domain_alert.dart';
import 'package:cake_wallet/src/screens/send/widgets/send_card.dart';
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
import 'package:cake_wallet/src/widgets/template_tile.dart';
@@ -1,4 +1,3 @@
import 'package:cake_wallet/entities/parsed_address.dart';
import 'package:cake_wallet/palette.dart';
import 'package:cake_wallet/view_model/send/output.dart';
import 'package:flutter/material.dart';
@@ -274,16 +273,15 @@ class ConfirmSendingAlertContentState extends State<ConfirmSendingAlertContent>
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<ConfirmSendingAlertContent>
})
: 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<ConfirmSendingAlertContent>
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,
+79 -51
View File
@@ -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<SendCard>
cryptoAmountController = TextEditingController(),
fiatAmountController = TextEditingController(),
noteController = TextEditingController(),
extractedAddressController = TextEditingController(),
cryptoAmountFocus = FocusNode(),
fiatAmountFocus = FocusNode(),
addressFocusNode = FocusNode();
@@ -52,6 +52,7 @@ class SendCardState extends State<SendCard>
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<SendCard>
child: Padding(
padding: EdgeInsets.fromLTRB(24, 100, 24, 32),
child: SingleChildScrollView(
child: Column(
child: Observer(builder: (_) => Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
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<SendCard>
)
)
],
)
))
),
),
)
@@ -453,6 +476,7 @@ class SendCardState extends State<SendCard>
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<SendCard>
final address = addressController.text;
if (output.address != address) {
output.resetParsedAddress();
output.address = address;
}
});
@@ -532,11 +557,14 @@ class SendCardState extends State<SendCard>
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;
}