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
This commit is contained in:
¨Anthony 2021-10-12 11:56:31 +02:00 committed by Iuri Matias
parent b59e4c0b93
commit a715c6b62e
4 changed files with 23 additions and 78 deletions

View File

@ -12,18 +12,23 @@ logScope:
type type
ResolveEnsTaskArg = ref object of QObjectTaskArg ResolveEnsTaskArg = ref object of QObjectTaskArg
ens: string ens: string
uuid: string
const resolveEnsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = const resolveEnsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let let
arg = decode[ResolveEnsTaskArg](argEncoded) 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) 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( let arg = ResolveEnsTaskArg(
tptr: cast[ByteAddress](resolveEnsTask), tptr: cast[ByteAddress](resolveEnsTask),
vptr: cast[ByteAddress](self.vptr), vptr: cast[ByteAddress](self.vptr),
slot: slot, ens: ens slot: slot, ens: ens, uuid: uuid
) )
self.appService.threadpool.start(arg) self.appService.threadpool.start(arg)
@ -51,15 +56,22 @@ QtObject:
proc formatENSUsername*(self: EnsView, username: string): string {.slot.} = proc formatENSUsername*(self: EnsView, username: string): string {.slot.} =
result = status_ens.addDomain(username) result = status_ens.addDomain(username)
# Resolving a ENS name proc resolveENSWithUUID*(self: EnsView, ens: string, uuid: string) {.slot.} =
proc resolveENS*(self: EnsView, ens: string) {.slot.} = self.resolveEns("ensResolved", ens, uuid)
self.resolveEns("ensResolved", ens) # Call self.ensResolved(string) when ens is resolved
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.} = proc ensResolved(self: EnsView, addressPubkeyJson: string) {.slot.} =
var var
parsed = addressPubkeyJson.parseJson parsed = addressPubkeyJson.parseJson
address = parsed["address"].to(string) address = parsed["address"].to(string)
pubkey = parsed["pubkey"].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)

View File

@ -3,7 +3,7 @@ import NimQml, chronicles, stint
import import
status/[status, wallet], 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] import ../../../app_service/[main]
QtObject: QtObject:
@ -17,7 +17,6 @@ QtObject:
tokensView*: TokensView tokensView*: TokensView
dappBrowserView*: DappBrowserView dappBrowserView*: DappBrowserView
gasView*: GasView gasView*: GasView
ensView*: EnsView
historyView*: HistoryView historyView*: HistoryView
balanceView*: BalanceView balanceView*: BalanceView
utilsView*: UtilsView utilsView*: UtilsView
@ -30,7 +29,6 @@ QtObject:
self.tokensView.delete self.tokensView.delete
self.dappBrowserView.delete self.dappBrowserView.delete
self.gasView.delete self.gasView.delete
self.ensView.delete
self.historyView.delete self.historyView.delete
self.balanceView.delete self.balanceView.delete
self.utilsView.delete self.utilsView.delete
@ -49,7 +47,6 @@ QtObject:
result.transactionsView = newTransactionsView(status, appService, result.accountsView) result.transactionsView = newTransactionsView(status, appService, result.accountsView)
result.tokensView = newTokensView(status, appService, result.accountsView) result.tokensView = newTokensView(status, appService, result.accountsView)
result.gasView = newGasView(status, appService) result.gasView = newGasView(status, appService)
result.ensView = newEnsView(status, appService)
result.dappBrowserView = newDappBrowserView(status, result.accountsView) result.dappBrowserView = newDappBrowserView(status, result.accountsView)
result.historyView = newHistoryView(status, appService, result.accountsView, result.transactionsView) result.historyView = newHistoryView(status, appService, result.accountsView, result.transactionsView)
result.balanceView = newBalanceView(status, appService, result.accountsView, result.transactionsView, result.historyView) result.balanceView = newBalanceView(status, appService, result.accountsView, result.transactionsView, result.historyView)
@ -78,10 +75,6 @@ QtObject:
QtProperty[QVariant] tokensView: QtProperty[QVariant] tokensView:
read = getTokens 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) proc getHistory(self: WalletView): QVariant {.slot.} = newQVariant(self.historyView)
QtProperty[QVariant] historyView: QtProperty[QVariant] historyView:
read = getHistory read = getHistory

View File

@ -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)

View File

@ -15,7 +15,7 @@ Item {
readonly property var validateAsync: Backpressure.debounce(inpAddress, debounceDelay, function (inputValue) { readonly property var validateAsync: Backpressure.debounce(inpAddress, debounceDelay, function (inputValue) {
root.isPending = true root.isPending = true
var name = inputValue.startsWith("@") ? inputValue.substring(1) : inputValue var name = inputValue.startsWith("@") ? inputValue.substring(1) : inputValue
walletModel.ensView.resolveENS(name, uuid) chatsModel.ensView.resolveENSWithUUID(name, uuid)
}); });
signal resolved(string resolvedAddress) signal resolved(string resolvedAddress)
@ -42,7 +42,7 @@ Item {
} }
Connections { Connections {
target: walletModel.ensView target: chatsModel.ensView
onEnsWasResolved: { onEnsWasResolved: {
if (uuid !== root.uuid) { if (uuid !== root.uuid) {
return return