From 1dd973340a6ed98351dc4bb04fd77ce07c04d13a Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Wed, 20 Nov 2024 08:36:53 +0100 Subject: [PATCH] fix(wallet): checking for an ens name now checks all users' addresses instead the default one only --- src/app_service/service/ens/async_tasks.nim | 7 ++++--- src/app_service/service/ens/service.nim | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/app_service/service/ens/async_tasks.nim b/src/app_service/service/ens/async_tasks.nim index 40234bf76d..03455f0c31 100644 --- a/src/app_service/service/ens/async_tasks.nim +++ b/src/app_service/service/ens/async_tasks.nim @@ -8,7 +8,7 @@ type chainId*: int isStatus*: bool myPublicKey*: string - myWalletAddress*: string + myAddresses*: seq[string] proc checkEnsAvailabilityTask(argEncoded: string) {.gcsafe, nimcall.} = let arg = decode[CheckEnsAvailabilityTaskArg](argEncoded) @@ -21,12 +21,13 @@ proc checkEnsAvailabilityTask(argEncoded: string) {.gcsafe, nimcall.} = availability = ENS_AVAILABILITY_STATUS_AVAILABLE else: let ensPubkey = ens_utils.publicKeyOf(arg.chainId, arg.ensUsername) + let ownerIsAmongMyAddresses = arg.myAddresses.filter(address => cmpIgnoreCase(address, ownerAddr) == 0).len == 1 if ownerAddr != "": - if ensPubkey == "" and ownerAddr == arg.myWalletAddress: + if ensPubkey == "" and ownerIsAmongMyAddresses: availability = ENS_AVAILABILITY_STATUS_OWNED # "Continuing will connect this username with your chat key." elif ensPubkey == arg.myPublicKey: availability = ENS_AVAILABILITY_STATUS_CONNECTED - elif ownerAddr == arg.myWalletAddress: + elif ownerIsAmongMyAddresses: availability = ENS_AVAILABILITY_STATUS_CONNECTED_DIFFERENT_KEY # "Continuing will require a transaction to connect the username with your current chat key.", else: availability = ENS_AVAILABILITY_STATUS_TAKEN diff --git a/src/app_service/service/ens/service.nim b/src/app_service/service/ens/service.nim index 826d804c49..e903bf95e9 100644 --- a/src/app_service/service/ens/service.nim +++ b/src/app_service/service/ens/service.nim @@ -1,4 +1,4 @@ -import NimQml, Tables, json, sequtils, strutils, stint, chronicles +import NimQml, Tables, json, sequtils, strutils, stint, sugar, chronicles import web3/ethtypes, stew/byteutils, nimcrypto, json_serialization import app/core/eventemitter @@ -132,6 +132,10 @@ QtObject: return let key = makeKey(ensDto.username, chainId) + if not self.pendingEnsUsernames.hasKey(key): + error "Error updating ens username status", message = "unknown key: " & key + return + if status == TxStatusSuccess: self.pendingEnsUsernames[key].txStatus = TxStatusSuccess let data = EnsTransactionArgs(txHash: transactionHash, ensUsername: ensDto.username, transactionType: $ensDto.txType) @@ -293,7 +297,7 @@ QtObject: chainId: self.getChainId(), isStatus: isStatus, myPublicKey: self.settingsService.getPublicKey(), - myWalletAddress: self.walletAccountService.getWalletAccount(0).address + myAddresses: self.walletAccountService.getWalletAccounts().map(a => a.address) ) self.threadpool.start(arg) @@ -340,7 +344,13 @@ QtObject: result = ("0x" & pubkey[4..67], "0x" & pubkey[68..131]) proc getEnsRegisteredAddress*(self: Service): string = - return status_ens.getRegistrarAddress(self.getChainId()).result.getStr + try: + let res = status_ens.getRegistrarAddress(self.getChainId()) + if res.error != nil: + raise newException(ValueError, res.error.message) + return res.result.getStr + except Exception as e: + error "Error getting ENS registered address", err=e.msg proc resourceUrl*(self: Service, username: string): (string, string, string) = try: