feat(@wallet): resolve token multi network

This commit is contained in:
Anthony Laibe 2022-05-31 14:09:58 +02:00 committed by Anthony Laibe
parent e07094137c
commit 756db3f95d
2 changed files with 23 additions and 20 deletions

View File

@ -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?",

View File

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