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 ensWasResolved*(self: WalletView, resolvedAddress: string, uuid: string) {.signal.}
proc ensResolved(self: WalletView, addressUuidJson: string) {.slot.} = proc ensResolved(self: WalletView, addressUuidJson: string) {.slot.} =
let var
parsed = addressUuidJson.parseJson parsed = addressUuidJson.parseJson
address = parsed["address"].to(string) address = parsed["address"].to(string)
uuid = parsed["uuid"].to(string) uuid = parsed["uuid"].to(string)
if address == "0x":
address = ""
self.ensWasResolved(address, uuid) self.ensWasResolved(address, uuid)
proc transactionCompleted*(self: WalletView, success: bool, txHash: string, revertReason: string = "") {.signal.} proc transactionCompleted*(self: WalletView, success: bool, txHash: string, revertReason: string = "") {.signal.}

View File

@ -75,13 +75,16 @@ QtObject {
} }
function isValidAddress(inputValue) { 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) { 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 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) 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 height: inpAddress.height
onSelectedAddressChanged: validate() 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() { function resetInternal() {
selectedAddress = "" selectedAddress = ""
@ -62,13 +72,6 @@ Item {
} }
} }
textField.rightPadding: 73 textField.rightPadding: 73
onTextEdited: {
metrics.text = text
ensResolver.resolveEns(text)
root.isResolvedAddress = false
root.selectedAddress = text
}
TextMetrics { TextMetrics {
id: metrics id: metrics
elideWidth: 97 elideWidth: 97
@ -99,6 +102,7 @@ Item {
onResolved: { onResolved: {
root.isResolvedAddress = true root.isResolvedAddress = true
root.selectedAddress = resolvedAddress root.selectedAddress = resolvedAddress
root.validate()
} }
onIsPendingChanged: { onIsPendingChanged: {
if (isPending) { if (isPending) {

View File

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

View File

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