mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
CWA-69 | added focusNode to address_text_field, got recipient name in the openalias, added focusNode listener in the send_page
This commit is contained in:
parent
df9418c799
commit
91091a8d19
3 changed files with 58 additions and 15 deletions
|
@ -1,15 +1,17 @@
|
|||
import 'package:basic_utils/basic_utils.dart';
|
||||
|
||||
String formatDomainName(String name) {
|
||||
if (!name.contains(".")) {
|
||||
return "";
|
||||
String formattedName = name;
|
||||
|
||||
if (name.contains(".")) {
|
||||
formattedName = name.replaceAll("@", ".");
|
||||
}
|
||||
|
||||
return name.replaceAll("@", ".");
|
||||
return formattedName;
|
||||
}
|
||||
|
||||
Future<String> fetchXmrAddress(String name) async {
|
||||
String xmrAddress = "";
|
||||
Future<Map<String, String>> fetchXmrAddressAndRecipientName(String name) async {
|
||||
final map = {"recipient_address" : name, "recipient_name" : name};
|
||||
|
||||
await DnsUtils.lookupRecord(name, RRecordType.TXT, dnssec: true).then((txtRecord) {
|
||||
if (txtRecord != null) {
|
||||
|
@ -20,14 +22,25 @@ Future<String> fetchXmrAddress(String name) async {
|
|||
|
||||
if (record.contains("oa1:xmr") && record.contains("recipient_address")) {
|
||||
record = record.replaceAll('\"', "");
|
||||
xmrAddress = record.split(" ").where((item) => (item.contains("recipient_address")))
|
||||
.toString().replaceAll("recipient_address=", "").replaceAll("\;", "")
|
||||
.replaceAll("(", "").replaceAll(")", "");
|
||||
|
||||
final dataList = record.split(";");
|
||||
|
||||
map["recipient_address"] = dataList.where((item) => (item.contains("recipient_address")))
|
||||
.toString().replaceAll("oa1:xmr recipient_address=", "")
|
||||
.replaceAll("(", "").replaceAll(")", "").trim();
|
||||
|
||||
final recipientName = dataList.where((item) => (item.contains("recipient_name"))).toString();
|
||||
|
||||
if (recipientName.isNotEmpty) {
|
||||
map["recipient_name"] = recipientName.replaceAll("recipient_name=", "")
|
||||
.replaceAll("(", "").replaceAll(")", "").trim();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return xmrAddress;
|
||||
return map;
|
||||
}
|
|
@ -49,10 +49,42 @@ class SendFormState extends State<SendForm> {
|
|||
final _cryptoAmountController = TextEditingController();
|
||||
final _fiatAmountController = TextEditingController();
|
||||
|
||||
final _focusNode = FocusNode();
|
||||
|
||||
bool _effectsInstalled = false;
|
||||
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_focusNode.addListener(() async {
|
||||
if (_addressController.text.isNotEmpty) {
|
||||
await fetchXmrAddressAndRecipientName(formatDomainName(_addressController.text)).then((map) async {
|
||||
|
||||
if (_addressController.text != map["recipient_address"]) {
|
||||
_addressController.text = map["recipient_address"];
|
||||
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text("XMR Recipient Detected"),
|
||||
content: Text("You will be sending funds to\n${map["recipient_name"]}"),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: Text(S.of(context).ok),
|
||||
onPressed: () => Navigator.of(context).pop())
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final settingsStore = Provider.of<SettingsStore>(context);
|
||||
|
@ -151,6 +183,7 @@ class SendFormState extends State<SendForm> {
|
|||
AddressTextField(
|
||||
controller: _addressController,
|
||||
placeholder: S.of(context).send_monero_address,
|
||||
focusNode: _focusNode,
|
||||
onURIScanned: (uri) {
|
||||
var address = '';
|
||||
var amount = '';
|
||||
|
@ -359,12 +392,6 @@ class SendFormState extends State<SendForm> {
|
|||
// Hack. Don't ask me.
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
|
||||
final domainName = formatDomainName(_addressController.text);
|
||||
|
||||
if (domainName != "") {
|
||||
await fetchXmrAddress(domainName).then((address) => _addressController.text = address);
|
||||
}
|
||||
|
||||
if (_formKey.currentState.validate()) {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
|
|
|
@ -18,6 +18,7 @@ class AddressTextField extends StatelessWidget {
|
|||
AddressTextFieldOption.addressBook
|
||||
],
|
||||
this.onURIScanned,
|
||||
this.focusNode,
|
||||
this.validator});
|
||||
|
||||
static const prefixIconWidth = 34.0;
|
||||
|
@ -30,6 +31,7 @@ class AddressTextField extends StatelessWidget {
|
|||
final Function(Uri) onURIScanned;
|
||||
final List<AddressTextFieldOption> options;
|
||||
final FormFieldValidator<String> validator;
|
||||
FocusNode focusNode;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -37,6 +39,7 @@ class AddressTextField extends StatelessWidget {
|
|||
onFieldSubmitted: (_) => FocusScope.of(context).unfocus(),
|
||||
enabled: isActive,
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
decoration: InputDecoration(
|
||||
suffixIcon: SizedBox(
|
||||
width: prefixIconWidth * options.length +
|
||||
|
|
Loading…
Reference in a new issue