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

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)
self.threadpool.start(arg)