validation and ens resolution fixes
This commit is contained in:
parent
76e7897e8d
commit
fc6c68232b
|
@ -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.}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -44,8 +44,8 @@ Item {
|
|||
if (uuid !== root.uuid) {
|
||||
return
|
||||
}
|
||||
root.resolved(resolvedAddress)
|
||||
root.isPending = false
|
||||
root.resolved(resolvedAddress)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue