validation and ens resolution fixes

This commit is contained in:
Pascal Precht 2020-11-04 13:37:53 +01:00 committed by Iuri Matias
parent 76e7897e8d
commit fc6c68232b
5 changed files with 26 additions and 19 deletions

View File

@ -569,10 +569,12 @@ QtObject:
proc ensWasResolved*(self: WalletView, resolvedAddress: string, uuid: string) {.signal.}
proc ensResolved(self: WalletView, addressUuidJson: string) {.slot.} =
let
var
parsed = addressUuidJson.parseJson
address = parsed["address"].to(string)
uuid = parsed["uuid"].to(string)
if address == "0x":
address = ""
self.ensWasResolved(address, uuid)
proc transactionCompleted*(self: WalletView, success: bool, txHash: string, revertReason: string = "") {.signal.}

View File

@ -75,13 +75,16 @@ QtObject {
}
function isValidAddress(inputValue) {
return /^0x[a-fA-F0-9]{40}$/.test(inputValue)
return inputValue !== "0x" && /^0x[a-fA-F0-9]{40}$/.test(inputValue)
}
function isValidEns(inputValue) {
if (!inputValue) {
return false
}
const isEmail = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/.test(inputValue)
const isDomain = /(?:(?:(?<thld>[\w\-]*)(?:\.))?(?<sld>[\w\-]*))\.(?<tld>[\w\-]*)/.test(inputValue)
return isEmail || isDomain || inputValue.startsWith("@")
return isEmail || isDomain || (inputValue.startsWith("@") && inputValue.length > 1)
}

View File

@ -21,7 +21,17 @@ Item {
height: inpAddress.height
onSelectedAddressChanged: validate()
onTextChanged: ensResolver.resolveEns(text)
onTextChanged: {
metrics.text = text
root.isResolvedAddress = false
if (Utils.isValidAddress(text)) {
root.selectedAddress = text
} else {
root.selectedAddress = ""
root.validate()
}
ensResolver.resolveEns(text)
}
function resetInternal() {
selectedAddress = ""
@ -62,13 +72,6 @@ Item {
}
}
textField.rightPadding: 73
onTextEdited: {
metrics.text = text
ensResolver.resolveEns(text)
root.isResolvedAddress = false
root.selectedAddress = text
}
TextMetrics {
id: metrics
elideWidth: 97
@ -99,6 +102,7 @@ Item {
onResolved: {
root.isResolvedAddress = true
root.selectedAddress = resolvedAddress
root.validate()
}
onIsPendingChanged: {
if (isPending) {

View File

@ -44,8 +44,8 @@ Item {
if (uuid !== root.uuid) {
return
}
root.resolved(resolvedAddress)
root.isPending = false
root.resolved(resolvedAddress)
}
}
}
}

View File

@ -28,8 +28,8 @@ Item {
return inpAddress.isPending
case RecipientSelector.Type.Contact:
return selContact.isPending
case RecipientSelector.Type.Account:
return selAccount.isPending
default:
return false
}
}
property var reset: function() {}
@ -174,10 +174,8 @@ Item {
if (!selAddressSource.selectedSource || (selAddressSource.selectedSource && selAddressSource.selectedSource.value !== RecipientSelector.Type.Address)) {
return
}
var recipient = root.selectedRecipient;
recipient.address = selectedAddress
recipient.type = RecipientSelector.Type.Address
root.selectedRecipient = recipient
root.selectedRecipient = { address: selectedAddress, type: RecipientSelector.Type.Address }
}
onIsValidChanged: root.validate()
}