mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 03:59:23 +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';
|
import 'package:basic_utils/basic_utils.dart';
|
||||||
|
|
||||||
String formatDomainName(String name) {
|
String formatDomainName(String name) {
|
||||||
if (!name.contains(".")) {
|
String formattedName = name;
|
||||||
return "";
|
|
||||||
|
if (name.contains(".")) {
|
||||||
|
formattedName = name.replaceAll("@", ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
return name.replaceAll("@", ".");
|
return formattedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> fetchXmrAddress(String name) async {
|
Future<Map<String, String>> fetchXmrAddressAndRecipientName(String name) async {
|
||||||
String xmrAddress = "";
|
final map = {"recipient_address" : name, "recipient_name" : name};
|
||||||
|
|
||||||
await DnsUtils.lookupRecord(name, RRecordType.TXT, dnssec: true).then((txtRecord) {
|
await DnsUtils.lookupRecord(name, RRecordType.TXT, dnssec: true).then((txtRecord) {
|
||||||
if (txtRecord != null) {
|
if (txtRecord != null) {
|
||||||
|
@ -20,14 +22,25 @@ Future<String> fetchXmrAddress(String name) async {
|
||||||
|
|
||||||
if (record.contains("oa1:xmr") && record.contains("recipient_address")) {
|
if (record.contains("oa1:xmr") && record.contains("recipient_address")) {
|
||||||
record = record.replaceAll('\"', "");
|
record = record.replaceAll('\"', "");
|
||||||
xmrAddress = record.split(" ").where((item) => (item.contains("recipient_address")))
|
|
||||||
.toString().replaceAll("recipient_address=", "").replaceAll("\;", "")
|
final dataList = record.split(";");
|
||||||
.replaceAll("(", "").replaceAll(")", "");
|
|
||||||
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return xmrAddress;
|
return map;
|
||||||
}
|
}
|
|
@ -49,10 +49,42 @@ class SendFormState extends State<SendForm> {
|
||||||
final _cryptoAmountController = TextEditingController();
|
final _cryptoAmountController = TextEditingController();
|
||||||
final _fiatAmountController = TextEditingController();
|
final _fiatAmountController = TextEditingController();
|
||||||
|
|
||||||
|
final _focusNode = FocusNode();
|
||||||
|
|
||||||
bool _effectsInstalled = false;
|
bool _effectsInstalled = false;
|
||||||
|
|
||||||
final _formKey = GlobalKey<FormState>();
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final settingsStore = Provider.of<SettingsStore>(context);
|
final settingsStore = Provider.of<SettingsStore>(context);
|
||||||
|
@ -151,6 +183,7 @@ class SendFormState extends State<SendForm> {
|
||||||
AddressTextField(
|
AddressTextField(
|
||||||
controller: _addressController,
|
controller: _addressController,
|
||||||
placeholder: S.of(context).send_monero_address,
|
placeholder: S.of(context).send_monero_address,
|
||||||
|
focusNode: _focusNode,
|
||||||
onURIScanned: (uri) {
|
onURIScanned: (uri) {
|
||||||
var address = '';
|
var address = '';
|
||||||
var amount = '';
|
var amount = '';
|
||||||
|
@ -359,12 +392,6 @@ class SendFormState extends State<SendForm> {
|
||||||
// Hack. Don't ask me.
|
// Hack. Don't ask me.
|
||||||
FocusScope.of(context).requestFocus(FocusNode());
|
FocusScope.of(context).requestFocus(FocusNode());
|
||||||
|
|
||||||
final domainName = formatDomainName(_addressController.text);
|
|
||||||
|
|
||||||
if (domainName != "") {
|
|
||||||
await fetchXmrAddress(domainName).then((address) => _addressController.text = address);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_formKey.currentState.validate()) {
|
if (_formKey.currentState.validate()) {
|
||||||
await showDialog<void>(
|
await showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
|
|
|
@ -18,6 +18,7 @@ class AddressTextField extends StatelessWidget {
|
||||||
AddressTextFieldOption.addressBook
|
AddressTextFieldOption.addressBook
|
||||||
],
|
],
|
||||||
this.onURIScanned,
|
this.onURIScanned,
|
||||||
|
this.focusNode,
|
||||||
this.validator});
|
this.validator});
|
||||||
|
|
||||||
static const prefixIconWidth = 34.0;
|
static const prefixIconWidth = 34.0;
|
||||||
|
@ -30,6 +31,7 @@ class AddressTextField extends StatelessWidget {
|
||||||
final Function(Uri) onURIScanned;
|
final Function(Uri) onURIScanned;
|
||||||
final List<AddressTextFieldOption> options;
|
final List<AddressTextFieldOption> options;
|
||||||
final FormFieldValidator<String> validator;
|
final FormFieldValidator<String> validator;
|
||||||
|
FocusNode focusNode;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -37,6 +39,7 @@ class AddressTextField extends StatelessWidget {
|
||||||
onFieldSubmitted: (_) => FocusScope.of(context).unfocus(),
|
onFieldSubmitted: (_) => FocusScope.of(context).unfocus(),
|
||||||
enabled: isActive,
|
enabled: isActive,
|
||||||
controller: controller,
|
controller: controller,
|
||||||
|
focusNode: focusNode,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
suffixIcon: SizedBox(
|
suffixIcon: SizedBox(
|
||||||
width: prefixIconWidth * options.length +
|
width: prefixIconWidth * options.length +
|
||||||
|
|
Loading…
Reference in a new issue