mirror of
https://github.com/monero-project/monero-gui
synced 2024-11-21 12:44:14 +01:00
TxUtils: add handleOpenAliasResolution func, simplify code
This commit is contained in:
parent
f650e96363
commit
6bd11f2270
@ -76,3 +76,34 @@ function isValidOpenAliasAddress(address) {
|
||||
// make sure it is not some kind of floating number
|
||||
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)
|
||||
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 {
|
||||
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"))
|
||||
const response = TxUtils.handleOpenAliasResolution(addressLine.text, descriptionLine.text);
|
||||
if (response) {
|
||||
if (response.message) {
|
||||
oa_message(response.message);
|
||||
}
|
||||
if (response.address) {
|
||||
addressLine.text = response.address;
|
||||
}
|
||||
if (response.description) {
|
||||
descriptionLine.text = response.description;
|
||||
}
|
||||
} else {
|
||||
root.oa_message(qsTr("No address found"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -415,41 +415,18 @@ Rectangle {
|
||||
text: qsTr("Resolve") + translationManager.emptyString
|
||||
visible: TxUtils.isValidOpenAliasAddress(address)
|
||||
onClicked: {
|
||||
var result = walletManager.resolveOpenAlias(address)
|
||||
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 ? 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"))
|
||||
}
|
||||
const response = TxUtils.handleOpenAliasResolution(address, descriptionLine.text);
|
||||
if (response) {
|
||||
if (response.message) {
|
||||
oa_message(response.message);
|
||||
}
|
||||
else {
|
||||
oa_message(qsTr("Internal error"))
|
||||
if (response.address) {
|
||||
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 New Issue
Block a user