feat(@wallet): resolve token multi network
This commit is contained in:
parent
e07094137c
commit
756db3f95d
|
@ -9,14 +9,15 @@ import ../../../backend/backend as backend
|
|||
|
||||
type
|
||||
GetTokenDetailsTaskArg = ref object of QObjectTaskArg
|
||||
chainId: int
|
||||
chainIds: seq[int]
|
||||
address: string
|
||||
|
||||
|
||||
const getTokenDetailsTask*: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
||||
let arg = decode[GetTokenDetailsTaskArg](argEncoded)
|
||||
for chainId in arg.chainIds:
|
||||
try:
|
||||
let response = backend.discoverToken(arg.chainId, arg.address).result
|
||||
let response = backend.discoverToken(chainId, arg.address).result
|
||||
|
||||
let output = %* {
|
||||
"address": arg.address,
|
||||
|
@ -25,7 +26,10 @@ const getTokenDetailsTask*: Task = proc(argEncoded: string) {.gcsafe, nimcall.}
|
|||
"decimals": response{"decimals"}.getInt
|
||||
}
|
||||
arg.finish(output)
|
||||
return
|
||||
except Exception as e:
|
||||
continue
|
||||
|
||||
let output = %* {
|
||||
"address": arg.address,
|
||||
"error": "Is this an ERC-20 or ERC-721 contract?",
|
||||
|
|
|
@ -170,13 +170,12 @@ QtObject:
|
|||
))
|
||||
|
||||
proc getTokenDetails*(self: Service, address: string) =
|
||||
# TODO: use multi network rather than first enabled network
|
||||
let chainId = self.networkService.getEnabledNetworks()[0].chainId
|
||||
let chainIds = self.networkService.getNetworks().map(n => n.chainId)
|
||||
let arg = GetTokenDetailsTaskArg(
|
||||
tptr: cast[ByteAddress](getTokenDetailsTask),
|
||||
vptr: cast[ByteAddress](self.vptr),
|
||||
slot: "tokenDetailsResolved",
|
||||
chainId: chainId,
|
||||
chainIds: chainIds,
|
||||
address: address
|
||||
)
|
||||
self.threadpool.start(arg)
|
Loading…
Reference in New Issue