mirror of
https://github.com/monero-project/monero-gui.git
synced 2025-01-03 17:39:54 +00:00
TxUtils: add handleOpenAliasResolution func, simplify code
This commit is contained in:
parent
f650e96363
commit
6bd11f2270
3 changed files with 51 additions and 60 deletions
|
@ -76,3 +76,34 @@ function isValidOpenAliasAddress(address) {
|
||||||
// make sure it is not some kind of floating number
|
// make sure it is not some kind of floating number
|
||||||
return address.length > 2 && isNaN(parseFloat(address)) && address.indexOf('.') >= 0
|
return address.length > 2 && isNaN(parseFloat(address)) && address.indexOf('.') >= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleOpenAliasResolution(address, descriptionText) {
|
||||||
|
const result = walletManager.resolveOpenAlias(address);
|
||||||
|
if (!result) {
|
||||||
|
return { message: qsTr("No address found") };
|
||||||
|
}
|
||||||
|
|
||||||
|
const [isDnssecValid, resolvedAddress] = result.split("|");
|
||||||
|
const isAddressValid = walletManager.addressValid(resolvedAddress, appWindow.persistentSettings.nettype);
|
||||||
|
let updatedDescriptionText = descriptionText;
|
||||||
|
|
||||||
|
if (isDnssecValid === "true") {
|
||||||
|
if (isAddressValid) {
|
||||||
|
updatedDescriptionText = descriptionText ? `${address} ${descriptionText}` : address;
|
||||||
|
return { address: resolvedAddress, description: updatedDescriptionText };
|
||||||
|
} else {
|
||||||
|
return { message: qsTr("No valid address found at this OpenAlias address") };
|
||||||
|
}
|
||||||
|
} else if (isDnssecValid === "false") {
|
||||||
|
if (isAddressValid) {
|
||||||
|
return {
|
||||||
|
address: resolvedAddress,
|
||||||
|
message: qsTr("Address found, but the DNSSEC signatures could not be verified, so this address may be spoofed"),
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return { message: qsTr("No valid address found at this OpenAlias address, but the DNSSEC signatures could not be verified, so this may be spoofed") };
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return { message: qsTr("Internal error") };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -387,34 +387,17 @@ Rectangle {
|
||||||
visible: TxUtils.isValidOpenAliasAddress(addressLine.text)
|
visible: TxUtils.isValidOpenAliasAddress(addressLine.text)
|
||||||
enabled : visible
|
enabled : visible
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var result = walletManager.resolveOpenAlias(addressLine.text)
|
const response = TxUtils.handleOpenAliasResolution(addressLine.text, descriptionLine.text);
|
||||||
if (result) {
|
if (response) {
|
||||||
var parts = result.split("|")
|
if (response.message) {
|
||||||
if (parts.length === 2) {
|
oa_message(response.message);
|
||||||
var address_ok = walletManager.addressValid(parts[1], appWindow.persistentSettings.nettype)
|
}
|
||||||
if (parts[0] === "true") {
|
if (response.address) {
|
||||||
if (address_ok) {
|
addressLine.text = response.address;
|
||||||
// prepend openalias to description
|
}
|
||||||
descriptionLine.text = descriptionLine.text ? addressLine.text + " " + descriptionLine.text : addressLine.text
|
if (response.description) {
|
||||||
addressLine.text = parts[1]
|
descriptionLine.text = response.description;
|
||||||
} else {
|
|
||||||
root.oa_message(qsTr("No valid address found at this OpenAlias address"))
|
|
||||||
}
|
|
||||||
} else if (parts[0] === "false") {
|
|
||||||
if (address_ok) {
|
|
||||||
addressLine.text = parts[1]
|
|
||||||
root.oa_message(qsTr("Address found, but the DNSSEC signatures could not be verified, so this address may be spoofed"))
|
|
||||||
} else {
|
|
||||||
root.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 {
|
|
||||||
root.oa_message(qsTr("Internal error"))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
root.oa_message(qsTr("Internal error"))
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
root.oa_message(qsTr("No address found"))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -415,41 +415,18 @@ Rectangle {
|
||||||
text: qsTr("Resolve") + translationManager.emptyString
|
text: qsTr("Resolve") + translationManager.emptyString
|
||||||
visible: TxUtils.isValidOpenAliasAddress(address)
|
visible: TxUtils.isValidOpenAliasAddress(address)
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var result = walletManager.resolveOpenAlias(address)
|
const response = TxUtils.handleOpenAliasResolution(address, descriptionLine.text);
|
||||||
if (result) {
|
if (response) {
|
||||||
var parts = result.split("|")
|
if (response.message) {
|
||||||
if (parts.length == 2) {
|
oa_message(response.message);
|
||||||
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 ? address + " " + descriptionLine.text : address
|
|
||||||
descriptionCheckbox.checked = true
|
|
||||||
recipientRepeater.itemAt(index).children[1].children[0].text = parts[1];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
oa_message(qsTr("No valid address found at this OpenAlias address"))
|
|
||||||
}
|
|
||||||
else if (parts[0] === "false") {
|
|
||||||
if (address_ok) {
|
|
||||||
recipientRepeater.itemAt(index).children[1].children[0].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 {
|
if (response.address) {
|
||||||
oa_message(qsTr("Internal error"))
|
recipientRepeater.itemAt(index).children[1].children[0].text = response.address;
|
||||||
|
}
|
||||||
|
if (response.description) {
|
||||||
|
descriptionLine.text = response.description;
|
||||||
|
descriptionCheckbox.checked = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
oa_message(qsTr("No address found"))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue