From a715c6b62ed8e83775fce85447278308f0863d00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=A8Anthony?= <¨anthony@laibe.cc¨> Date: Tue, 12 Oct 2021 11:56:31 +0200 Subject: [PATCH] refactor(@desktop/ens): Keep only one ens view Once refactoring with module this should probably be attached to main or to something common to all module since it is accessed in low level part of the app accross multiple section --- src/app/chat/views/ens.nim | 28 ++++++++++----- src/app/wallet/v1/view.nim | 9 +---- src/app/wallet/v1/views/ens.nim | 60 --------------------------------- ui/shared/views/EnsResolver.qml | 4 +-- 4 files changed, 23 insertions(+), 78 deletions(-) delete mode 100644 src/app/wallet/v1/views/ens.nim diff --git a/src/app/chat/views/ens.nim b/src/app/chat/views/ens.nim index b68b6999e6..981ba1b901 100644 --- a/src/app/chat/views/ens.nim +++ b/src/app/chat/views/ens.nim @@ -12,18 +12,23 @@ logScope: type ResolveEnsTaskArg = ref object of QObjectTaskArg ens: string + uuid: string const resolveEnsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = let arg = decode[ResolveEnsTaskArg](argEncoded) - output = %* { "address": status_ens.address(arg.ens), "pubkey": status_ens.pubkey(arg.ens) } + output = %* { + "address": status_ens.address(arg.ens), + "pubkey": status_ens.pubkey(arg.ens), + "uuid": arg.uuid + } arg.finish(output) -proc resolveEns[T](self: T, slot: string, ens: string) = +proc resolveEns[T](self: T, slot: string, ens: string, uuid: string) = let arg = ResolveEnsTaskArg( tptr: cast[ByteAddress](resolveEnsTask), vptr: cast[ByteAddress](self.vptr), - slot: slot, ens: ens + slot: slot, ens: ens, uuid: uuid ) self.appService.threadpool.start(arg) @@ -51,15 +56,22 @@ QtObject: proc formatENSUsername*(self: EnsView, username: string): string {.slot.} = result = status_ens.addDomain(username) - # Resolving a ENS name - proc resolveENS*(self: EnsView, ens: string) {.slot.} = - self.resolveEns("ensResolved", ens) # Call self.ensResolved(string) when ens is resolved + proc resolveENSWithUUID*(self: EnsView, ens: string, uuid: string) {.slot.} = + self.resolveEns("ensResolved", ens, uuid) - proc ensWasResolved*(self: EnsView, resolvedPubKey: string, resolvedAddress: string) {.signal.} + proc resolveENS*(self: EnsView, ens: string) {.slot.} = + self.resolveEns("ensResolved", ens, "") + + proc ensWasResolved*(self: EnsView, resolvedPubKey: string, resolvedAddress: string, uuid: string) {.signal.} proc ensResolved(self: EnsView, addressPubkeyJson: string) {.slot.} = var parsed = addressPubkeyJson.parseJson address = parsed["address"].to(string) pubkey = parsed["pubkey"].to(string) - self.ensWasResolved(pubKey, address) + uuid = parsed["uuid"].to(string) + + if address == "0x": + address = "" + + self.ensWasResolved(pubKey, address, uuid) diff --git a/src/app/wallet/v1/view.nim b/src/app/wallet/v1/view.nim index 659adf2630..8af64f5ad4 100644 --- a/src/app/wallet/v1/view.nim +++ b/src/app/wallet/v1/view.nim @@ -3,7 +3,7 @@ import NimQml, chronicles, stint import status/[status, wallet], - views/[accounts, collectibles, transactions, tokens, gas, ens, dapp_browser, history, balance, utils, asset_list, account_list] + views/[accounts, collectibles, transactions, tokens, gas, dapp_browser, history, balance, utils, asset_list, account_list] import ../../../app_service/[main] QtObject: @@ -17,7 +17,6 @@ QtObject: tokensView*: TokensView dappBrowserView*: DappBrowserView gasView*: GasView - ensView*: EnsView historyView*: HistoryView balanceView*: BalanceView utilsView*: UtilsView @@ -30,7 +29,6 @@ QtObject: self.tokensView.delete self.dappBrowserView.delete self.gasView.delete - self.ensView.delete self.historyView.delete self.balanceView.delete self.utilsView.delete @@ -49,7 +47,6 @@ QtObject: result.transactionsView = newTransactionsView(status, appService, result.accountsView) result.tokensView = newTokensView(status, appService, result.accountsView) result.gasView = newGasView(status, appService) - result.ensView = newEnsView(status, appService) result.dappBrowserView = newDappBrowserView(status, result.accountsView) result.historyView = newHistoryView(status, appService, result.accountsView, result.transactionsView) result.balanceView = newBalanceView(status, appService, result.accountsView, result.transactionsView, result.historyView) @@ -78,10 +75,6 @@ QtObject: QtProperty[QVariant] tokensView: read = getTokens - proc getEns(self: WalletView): QVariant {.slot.} = newQVariant(self.ensView) - QtProperty[QVariant] ensView: - read = getEns - proc getHistory(self: WalletView): QVariant {.slot.} = newQVariant(self.historyView) QtProperty[QVariant] historyView: read = getHistory diff --git a/src/app/wallet/v1/views/ens.nim b/src/app/wallet/v1/views/ens.nim deleted file mode 100644 index 20d2abe775..0000000000 --- a/src/app/wallet/v1/views/ens.nim +++ /dev/null @@ -1,60 +0,0 @@ -import atomics, strformat, strutils, sequtils, json, std/wrapnils, parseUtils, tables, chronicles, web3/[ethtypes, conversions], stint -import NimQml, json, sequtils, chronicles, strutils, strformat, json - -import - status/[status, settings, wallet, tokens], - status/ens as status_ens -import ../../../../app_service/[main] -import ../../../../app_service/tasks/[qt, threadpool] - -import account_list, account_item, transaction_list, accounts, asset_list, token_list - -logScope: - topics = "ens-view" - -type - ResolveEnsTaskArg = ref object of QObjectTaskArg - ens: string - uuid: string - -const resolveEnsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = - let - arg = decode[ResolveEnsTaskArg](argEncoded) - output = %* { "address": status_ens.address(arg.ens), "uuid": arg.uuid } - arg.finish(output) - -proc resolveEns[T](self: T, slot: string, ens: string, uuid: string) = - let arg = ResolveEnsTaskArg( - tptr: cast[ByteAddress](resolveEnsTask), - vptr: cast[ByteAddress](self.vptr), - slot: slot, ens: ens, uuid: uuid - ) - self.appService.threadpool.start(arg) - -QtObject: - type EnsView* = ref object of QObject - status: Status - appService: AppService - - proc setup(self: EnsView) = self.QObject.setup - proc delete(self: EnsView) = self.QObject.delete - - proc newEnsView*(status: Status, appService: AppService): EnsView = - new(result, delete) - result.status = status - result.appService = appService - result.setup - - proc resolveENS*(self: EnsView, ens: string, uuid: string) {.slot.} = - self.resolveEns("ensResolved", ens, uuid) - - proc ensWasResolved*(self: EnsView, resolvedAddress: string, uuid: string) {.signal.} - - proc ensResolved(self: EnsView, addressUuidJson: string) {.slot.} = - var - parsed = addressUuidJson.parseJson - address = parsed["address"].to(string) - uuid = parsed["uuid"].to(string) - if address == "0x": - address = "" - self.ensWasResolved(address, uuid) diff --git a/ui/shared/views/EnsResolver.qml b/ui/shared/views/EnsResolver.qml index f6f6141b98..95f92efbe3 100644 --- a/ui/shared/views/EnsResolver.qml +++ b/ui/shared/views/EnsResolver.qml @@ -15,7 +15,7 @@ Item { readonly property var validateAsync: Backpressure.debounce(inpAddress, debounceDelay, function (inputValue) { root.isPending = true var name = inputValue.startsWith("@") ? inputValue.substring(1) : inputValue - walletModel.ensView.resolveENS(name, uuid) + chatsModel.ensView.resolveENSWithUUID(name, uuid) }); signal resolved(string resolvedAddress) @@ -42,7 +42,7 @@ Item { } Connections { - target: walletModel.ensView + target: chatsModel.ensView onEnsWasResolved: { if (uuid !== root.uuid) { return