feat(@wallet): resolve token multi network
This commit is contained in:
parent
e07094137c
commit
756db3f95d
|
@ -9,25 +9,29 @@ 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)
|
||||
try:
|
||||
let response = backend.discoverToken(arg.chainId, arg.address).result
|
||||
for chainId in arg.chainIds:
|
||||
try:
|
||||
let response = backend.discoverToken(chainId, arg.address).result
|
||||
|
||||
let output = %* {
|
||||
"address": arg.address,
|
||||
"name": response{"name"}.getStr,
|
||||
"symbol": response{"symbol"}.getStr,
|
||||
"decimals": response{"decimals"}.getInt
|
||||
}
|
||||
arg.finish(output)
|
||||
return
|
||||
except Exception as e:
|
||||
continue
|
||||
|
||||
let output = %* {
|
||||
"address": arg.address,
|
||||
"name": response{"name"}.getStr,
|
||||
"symbol": response{"symbol"}.getStr,
|
||||
"decimals": response{"decimals"}.getInt
|
||||
}
|
||||
arg.finish(output)
|
||||
except Exception as e:
|
||||
let output = %* {
|
||||
"address": arg.address,
|
||||
"error": "Is this an ERC-20 or ERC-721 contract?",
|
||||
}
|
||||
arg.finish(output)
|
||||
let output = %* {
|
||||
"address": arg.address,
|
||||
"error": "Is this an ERC-20 or ERC-721 contract?",
|
||||
}
|
||||
arg.finish(output)
|
||||
|
|
|
@ -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)
|
||||
self.threadpool.start(arg)
|
Loading…
Reference in New Issue