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:
parent
b59e4c0b93
commit
a715c6b62e
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue