diff --git a/src/app/profile/views/ens_manager.nim b/src/app/profile/views/ens_manager.nim index 7be5ba6a72..a5e33cdb9b 100644 --- a/src/app/profile/views/ens_manager.nim +++ b/src/app/profile/views/ens_manager.nim @@ -28,29 +28,7 @@ type const validateTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = let arg = decode[ValidateTaskArg](argEncoded) - username = arg.ens & (if(arg.isStatus): status_ens.domain else: "") - var output = "" - if arg.usernames.filter(proc(x: string):bool = x == username).len > 0: - output = "already-connected" - else: - let ownerAddr = status_ens.owner(username) - if ownerAddr == "" and arg.isStatus: - output = "available" - else: - let userPubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0") - let userWallet = status_wallet.getWalletAccounts()[0].address - let pubkey = status_ens.pubkey(arg.ens) - if ownerAddr != "": - if pubkey == "" and ownerAddr == userWallet: - output = "owned" # "Continuing will connect this username with your chat key." - elif pubkey == userPubkey: - output = "connected" - elif ownerAddr == userWallet: - output = "connected-different-key" # "Continuing will require a transaction to connect the username with your current chat key.", - else: - output = "taken" - else: - output = "taken" + var output = status_ens.validateEnsName(arg.ens, arg.isStatus, arg.usernames) arg.finish(output) proc validate[T](self: T, slot: string, ens: string, isStatus: bool, usernames: seq[string]) = diff --git a/src/status/ens.nim b/src/status/ens.nim index 039921c50d..d3bf88611e 100644 --- a/src/status/ens.nim +++ b/src/status/ens.nim @@ -1,3 +1,4 @@ +import sequtils import strutils import profile/profile import nimcrypto @@ -17,6 +18,9 @@ import web3/[ethtypes, conversions], stew/byteutils, stint import libstatus/eth/contracts import chronicles, libp2p/[multihash, multicodec, cid] +import ./settings as settings +import ./wallet as status_wallet + const domain* = ".stateofus.eth" proc userName*(ensName: string, removeSuffix: bool = false): string = @@ -307,3 +311,28 @@ proc decodeENSContentHash*(value: string): tuple[ensType: ENSType, output: strin return (ENSType.IPNS, parseHexStr(value[12..value.len-1])) return (ENSType.UNKNOWN, "") + +proc validateEnsName*(ens: string, isStatus: bool, usernames: seq[string]): string = + var username = ens & (if(isStatus): domain else: "") + result = "" + if usernames.filter(proc(x: string):bool = x == username).len > 0: + result = "already-connected" + else: + let ownerAddr = owner(username) + if ownerAddr == "" and isStatus: + result = "available" + else: + let userPubKey = getSetting[string](settings, Setting.PublicKey, "0x0") + let userWallet = status_wallet.getWalletAccounts()[0].address + let ens_pubkey = pubkey(ens) + if ownerAddr != "": + if ens_pubkey == "" and ownerAddr == userWallet: + result = "owned" # "Continuing will connect this username with your chat key." + elif ens_pubkey == userPubkey: + result = "connected" + elif ownerAddr == userWallet: + result = "connected-different-key" # "Continuing will require a transaction to connect the username with your current chat key.", + else: + result = "taken" + else: + result = "taken" diff --git a/src/status/settings.nim b/src/status/settings.nim index 08e808b324..cbe8522e40 100644 --- a/src/status/settings.nim +++ b/src/status/settings.nim @@ -27,6 +27,12 @@ proc getSetting*[T](self: SettingsModel, name: Setting, defaultValue: T, useCach proc getSetting*[T](self: SettingsModel, name: Setting, useCached: bool = true): T = result = status_settings.getSetting[T](name, useCached) +proc getSetting*[T](name: Setting, defaultValue: T, useCached: bool = true): T = + result = status_settings.getSetting(name, defaultValue, useCached) + +proc getSetting*[T](name: Setting, useCached: bool = true): T = + result = status_settings.getSetting[T](name, useCached) + proc getCurrentNetworkDetails*(self: SettingsModel): LibStatusTypes.NetworkDetails = result = status_settings.getCurrentNetworkDetails()