From b4606d03636a27aa4d316ef8c15ef65a0a5877c4 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Wed, 30 Mar 2022 11:20:34 +0200 Subject: [PATCH] fix(@desktop): network serialization --- src/app_service/service/network/dto.nim | 3 --- src/app_service/service/network/service.nim | 16 ++++++++++++++-- src/backend/backend.nim | 18 ++++++++++++++++-- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/app_service/service/network/dto.nim b/src/app_service/service/network/dto.nim index 569cc00dab..50482658c8 100644 --- a/src/app_service/service/network/dto.nim +++ b/src/app_service/service/network/dto.nim @@ -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" diff --git a/src/app_service/service/network/service.nim b/src/app_service/service/network/service.nim index c8f66c57d7..5cf58c5a5c 100644 --- a/src/app_service/service/network/service.nim +++ b/src/app_service/service/network/service.nim @@ -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 = diff --git a/src/backend/backend.nim b/src/backend/backend.nim index bf199cefa8..317820a8c5 100644 --- a/src/backend/backend.nim +++ b/src/backend/backend.nim @@ -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