fix(@desktop): network serialization

This commit is contained in:
Anthony Laibe 2022-03-30 11:20:34 +02:00 committed by Anthony Laibe
parent e344e00f8b
commit b4606d0363
3 changed files with 30 additions and 7 deletions

View File

@ -22,9 +22,6 @@ proc `$`*(self: NetworkDto): string =
proc hash*(self: NetworkDto): Hash =
return self.chainId.hash
proc toPayload*(self: NetworkDto): JsonNode =
return %* [Json.encode(self).parseJson]
proc sntSymbol*(self: NetworkDto): string =
if self.chainId == Mainnet:
return "SNT"

View File

@ -69,11 +69,23 @@ proc getEnabledNetworks*(self: Service): seq[NetworkDto] =
result.add(network)
proc upsertNetwork*(self: Service, network: NetworkDto) =
discard backend.addEthereumChain(network.toPayload())
discard backend.addEthereumChain(backend.Network(
chainId: network.chainId,
nativeCurrencyDecimals: network.nativeCurrencyDecimals,
layer: network.layer,
chainName: network.chainName,
rpcURL: network.rpcURL,
blockExplorerURL: network.blockExplorerURL,
iconURL: network.iconURL,
nativeCurrencyName: network.nativeCurrencyName,
nativeCurrencySymbol: network.nativeCurrencySymbol,
isTest: network.isTest,
enabled: network.enabled,
))
self.dirty.store(true)
proc deleteNetwork*(self: Service, network: NetworkDto) =
discard backend.deleteEthereumChain(%* [network.chainId])
discard backend.deleteEthereumChain(network.chainId)
self.dirty.store(true)
proc getNetwork*(self: Service, chainId: int): NetworkDto =

View File

@ -26,6 +26,20 @@ type
name* {.serializedFieldName("name").}: string
address* {.serializedFieldName("address").}: string
Network* = ref object of RootObj
chainId* {.serializedFieldName("chainId").}: int
nativeCurrencyDecimals* {.serializedFieldName("nativeCurrencyDecimals").}: int
layer* {.serializedFieldName("layer").}: int
chainName* {.serializedFieldName("chainName").}: string
rpcURL* {.serializedFieldName("rpcUrl").}: string
blockExplorerURL* {.serializedFieldName("blockExplorerUrl").}: string
iconURL* {.serializedFieldName("iconUrl").}: string
nativeCurrencyName* {.serializedFieldName("nativeCurrencyName").}: string
nativeCurrencySymbol* {.serializedFieldName("nativeCurrencySymbol").}: string
isTest* {.serializedFieldName("isTest").}: bool
enabled* {.serializedFieldName("enabled").}: bool
rpc(clientVersion, "web3"):
discard
@ -53,10 +67,10 @@ rpc(getEthereumChains, "wallet"):
onlyEnabled: bool
rpc(addEthereumChain, "wallet"):
payload: JsonNode
network: Network
rpc(deleteEthereumChain, "wallet"):
payload: JsonNode
chainId: int
rpc(addSavedAddress, "wallet"):
savedAddress: SavedAddress