From f3a33f414df59d05cd4cffa42d32e61d7d7c99dd Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Tue, 20 Aug 2024 14:29:56 +0200 Subject: [PATCH] fix: can't add ens name as watched address Fixes #13902 --- .../panels/WatchOnlyAddressSection.qml | 38 +++++++++++++++++-- .../addaccount/stores/AddAccountStore.qml | 9 +++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/ui/imports/shared/popups/addaccount/panels/WatchOnlyAddressSection.qml b/ui/imports/shared/popups/addaccount/panels/WatchOnlyAddressSection.qml index 2d1d01c22d..cb53786cff 100644 --- a/ui/imports/shared/popups/addaccount/panels/WatchOnlyAddressSection.qml +++ b/ui/imports/shared/popups/addaccount/panels/WatchOnlyAddressSection.qml @@ -24,10 +24,31 @@ Column { id: d property bool incorrectChecksum: false + property string uuid + property string resolvedEnsAddress function checkIfAddressChecksumIsValid(address) { d.incorrectChecksum = !root.store.isChecksumValidForAddress(address) } + + function validateEnsAsync(value) { + var name = value.startsWith("@") ? value.substring(1) : value + d.uuid = Utils.uuid() + root.store.validateEnsAsync(name, d.uuid) + } + } + + Connections { + target: root.store + function onResolvedENS(resolvedPubKey: string, resolvedAddress: string, uuid: string) { + if (uuid !== d.uuid) { + return + } + + d.resolvedEnsAddress = resolvedAddress + addressInput.validate() + root.store.changeWatchOnlyAccountAddressPostponed(resolvedAddress) + } } StatusInput { @@ -63,19 +84,30 @@ Column { } } validators: [ - StatusAddressOrEnsValidator { + StatusValidator { + name: "address-or-ens" + validate: (value) => { + return Utils.isValidAddress(value) || + Utils.isValidEns(value) && + !!d.resolvedEnsAddress + } errorMessage: qsTr("Please enter a valid Ethereum address or ENS name") } ] onTextChanged: { d.incorrectChecksum = false - if (addressInput.valid) { - const trimmedText = text.trim() + const trimmedText = text.trim() + if (Utils.isValidEns(trimmedText)) { + d.resolvedEnsAddress = "" + d.validateEnsAsync(trimmedText) + return + } else if (Utils.isValidAddress(trimmedText)) { root.store.changeWatchOnlyAccountAddressPostponed(trimmedText) d.checkIfAddressChecksumIsValid(trimmedText) return } + root.store.cleanWatchOnlyAccountAddress() } diff --git a/ui/imports/shared/popups/addaccount/stores/AddAccountStore.qml b/ui/imports/shared/popups/addaccount/stores/AddAccountStore.qml index 0b77b829fb..6490246f55 100644 --- a/ui/imports/shared/popups/addaccount/stores/AddAccountStore.qml +++ b/ui/imports/shared/popups/addaccount/stores/AddAccountStore.qml @@ -55,6 +55,11 @@ BasePopupStore { ] signal showLimitPopup(int warningType) + signal resolvedENS(string resolvedPubKey, string resolvedAddress, string uuid) + + Component.onCompleted: { + mainModule.resolvedENS.connect(root.resolvedENS) + } function resetStoreValues() { root.enteredSeedPhraseIsValid = false @@ -119,6 +124,10 @@ BasePopupStore { root.addAccountModule.changeSelectedOrigin(keyUid) } + readonly property var validateEnsAsync: Backpressure.debounce(root, 500, function (name, uuid) { + mainModule.resolveENS(name, uuid) + }); + readonly property var changeDerivationPathPostponed: Backpressure.debounce(root, 400, function (path) { root.changeDerivationPath(path) })