From d36904096d74b248d799feb65d0d00554f77aa61 Mon Sep 17 00:00:00 2001 From: mmbyday Date: Fri, 1 Feb 2019 10:53:01 -0800 Subject: [PATCH] openalias: usuability improvements on addressbook/transfer page --- components/InputMulti.qml | 2 +- pages/AddressBook.qml | 90 +++++++++++++++++++++++++++++++++++++-- pages/Transfer.qml | 5 ++- 3 files changed, 92 insertions(+), 5 deletions(-) diff --git a/components/InputMulti.qml b/components/InputMulti.qml index 66ac1e6f..8712a69c 100644 --- a/components/InputMulti.qml +++ b/components/InputMulti.qml @@ -54,7 +54,7 @@ TextArea { onTextChanged: { if(addressValidation){ // js replacement for `RegExpValidator { regExp: /[0-9A-Fa-f]{95}/g }` - textArea.text = textArea.text.replace(/[^a-z0-9.@]/gi,''); + textArea.text = textArea.text.replace(/[^a-z0-9.@\-]/gi,''); var address_ok = TxUtils.checkAddress(textArea.text, appWindow.persistentSettings.nettype) || TxUtils.isValidOpenAliasAddress(textArea.text); if(!address_ok) error = true; else error = false; diff --git a/pages/AddressBook.qml b/pages/AddressBook.qml index fecb9d05..a908e467 100644 --- a/pages/AddressBook.qml +++ b/pages/AddressBook.qml @@ -28,7 +28,9 @@ import QtQuick 2.0 import QtQuick.Layouts 1.1 +import QtQuick.Dialogs 1.2 import "../components" as MoneroComponents +import "../js/TxUtils.js" as TxUtils import moneroComponents.AddressBook 1.0 import moneroComponents.AddressBookModel 1.0 import moneroComponents.Clipboard 1.0 @@ -51,9 +53,20 @@ ColumnLayout { Layout.fillWidth: true fontBold: true labelText: qsTr("Address") + translationManager.emptyString - placeholderText: qsTr("4.. / 8..") + translationManager.emptyString + placeholderText: qsTr("4.. / 8.. / OpenAlias") + translationManager.emptyString wrapMode: Text.WrapAnywhere addressValidation: true + pasteButton: true + onPaste: function(clipboardText) { + const parsed = walletManager.parse_uri_to_object(clipboardText); + if (!parsed.error) { + addressLine.text = parsed.address; + setPaymentId(parsed.payment_id); + setDescription(parsed.tx_description); + } else { + addressLine.text = clipboardText; + } + } inlineButton.icon: "../images/qr.png" inlineButton.buttonColor: MoneroComponents.Style.orange inlineButton.onClicked: { @@ -63,6 +76,50 @@ ColumnLayout { inlineButtonVisible : appWindow.qrScannerEnabled && !addressLine.text } + MoneroComponents.StandardButton { + id: resolveButton + text: qsTr("Resolve") + translationManager.emptyString + visible: TxUtils.isValidOpenAliasAddress(addressLine.text) + enabled : visible + onClicked: { + var result = walletManager.resolveOpenAlias(addressLine.text) + if (result) { + var parts = result.split("|") + if (parts.length === 2) { + var address_ok = walletManager.addressValid(parts[1], appWindow.persistentSettings.nettype) + if (parts[0] === "true") { + if (address_ok) { + // prepend openalias to description + descriptionLine.text = descriptionLine.text ? addressLine.text + " " + descriptionLine.text : addressLine.text + addressLine.text = parts[1] + } + else + oa_message(qsTr("No valid address found at this OpenAlias address")) + } + else if (parts[0] === "false") { + if (address_ok) { + addressLine.text = parts[1] + oa_message(qsTr("Address found, but the DNSSEC signatures could not be verified, so this address may be spoofed")) + } + else + { + oa_message(qsTr("No valid address found at this OpenAlias address, but the DNSSEC signatures could not be verified, so this may be spoofed")) + } + } + else { + oa_message(qsTr("Internal error")) + } + } + else { + oa_message(qsTr("Internal error")) + } + } + else { + oa_message(qsTr("No address found")) + } + } + } + MoneroComponents.LineEditMulti { id: paymentIdLine visible: appWindow.persistentSettings.showPid @@ -82,7 +139,6 @@ ColumnLayout { wrapMode: Text.WrapAnywhere } - RowLayout { id: addButton Layout.bottomMargin: 17 * scaleRatio @@ -150,7 +206,7 @@ ColumnLayout { payment_id = payment_id.trim() var address_ok = walletManager.addressValid(address, nettype) - var payment_id_ok = payment_id.length == 0 || walletManager.paymentIdValid(payment_id) + var payment_id_ok = payment_id.length === 0 || walletManager.paymentIdValid(payment_id) var ipid = walletManager.paymentIdFromAddress(address, nettype) if (ipid.length > 0 && payment_id.length > 0) payment_id_ok = false @@ -178,9 +234,37 @@ ColumnLayout { cameraUi.qrcode_decoded.disconnect(updateFromQrCode) } + function setDescription(value) { + descriptionLine.text = value; + } + + function setPaymentId(value) { + paymentIdLine.text = value; + } + function clearFields() { addressLine.text = ""; paymentIdLine.text = ""; descriptionLine.text = ""; } + + function oa_message(text) { + oaPopup.title = qsTr("OpenAlias error") + translationManager.emptyString + oaPopup.text = text + oaPopup.icon = StandardIcon.Information + oaPopup.onCloseCallback = null + oaPopup.open() + } + + MoneroComponents.StandardDialog { + // dynamically change onclose handler + property var onCloseCallback + id: oaPopup + cancelVisible: false + onAccepted: { + if (onCloseCallback) { + onCloseCallback() + } + } + } } diff --git a/pages/Transfer.qml b/pages/Transfer.qml index 904e0f60..c712f06d 100644 --- a/pages/Transfer.qml +++ b/pages/Transfer.qml @@ -216,7 +216,7 @@ Rectangle { Address ( Address book )") + translationManager.emptyString labelButtonText: qsTr("Resolve") + translationManager.emptyString - placeholderText: "4.. / 8.." + placeholderText: "4.. / 8.. / OpenAlias" wrapMode: Text.WrapAnywhere addressValidation: true onInputLabelLinkActivated: { @@ -259,6 +259,9 @@ Rectangle { var address_ok = walletManager.addressValid(parts[1], appWindow.persistentSettings.nettype) if (parts[0] === "true") { if (address_ok) { + // prepend openalias to description + descriptionLine.text = descriptionLine.text ? addressLine.text + " " + descriptionLine.text : addressLine.text + descriptionCheckbox.checked = true addressLine.text = parts[1] } else