refactor(@desktop/profile-advance): adding custom networks

This commit is contained in:
Sale Djenic 2021-12-16 11:33:27 +01:00
parent c7d53a31e0
commit 63b4397670
18 changed files with 469 additions and 306 deletions

View File

@ -136,3 +136,14 @@ method toggleDebug*(self: Controller) =
method isDebugEnabled*(self: Controller): bool =
return self.nodeConfigurationService.getDebugLevel() == $LogLevel.DEBUG
method getCustomNetworks*(self: Controller): seq[settings_service.Network] =
return self.settingsService.getAvailableCustomNetworks()
method addCustomNetwork*(self: Controller, network: settings_service.Network) =
if (not self.settingsService.addCustomNetwork(network)):
# in the future we may do a call from here to show a popup about this error
error "an error occurred, we couldn't add a custom network"
return
self.delegate.onCustomNetworkAdded(network)

View File

@ -51,3 +51,9 @@ method toggleDebug*(self: AccessInterface) {.base.} =
method isDebugEnabled*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method getCustomNetworks*(self: AccessInterface): seq[settings_service_type.Network] {.base.} =
raise newException(ValueError, "No implementation available")
method addCustomNetwork*(self: AccessInterface, network: Network) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -0,0 +1,61 @@
import NimQml, Tables, strformat
type
ModelRole {.pure.} = enum
Id = UserRole + 1
Name
QtObject:
type
Model* = ref object of QAbstractListModel
items: seq[tuple[id: string, name: string]]
proc delete*(self: Model) =
self.items = @[]
self.QAbstractListModel.delete
proc setup(self: Model) =
self.QAbstractListModel.setup
proc newModel*(): Model =
new(result, delete)
result.setup
proc `$`*(self: Model): string =
for i in 0 ..< self.items.len:
result &= fmt"""
[{i}]:(id: {self.items[i].id}, name: {self.items[i].name})
"""
method rowCount(self: Model, index: QModelIndex = nil): int =
return self.items.len
method roleNames(self: Model): Table[int, string] =
{
ModelRole.Id.int:"id",
ModelRole.Name.int:"name",
}.toTable
method data(self: Model, index: QModelIndex, role: int): QVariant =
if (not index.isValid):
return
if (index.row < 0 or index.row >= self.items.len):
return
let item = self.items[index.row]
let enumRole = role.ModelRole
case enumRole:
of ModelRole.Id:
result = newQVariant(item.id)
of ModelRole.Name:
result = newQVariant(item.name)
proc add*(self: Model, id: string, name: string) =
let parentModelIndex = newQModelIndex()
defer: parentModelIndex.delete
self.beginInsertRows(parentModelIndex, self.items.len, self.items.len)
self.items.add((id: id, name: name))
self.endInsertRows()

View File

@ -1,7 +1,7 @@
import NimQml, chronicles
import NimQml, chronicles, uuids
import io_interface
import ../io_interface as delegate_interface
import view, controller
import view, controller, custom_networks_model
import ../../../../../constants
import ../../../../global/global_singleton
@ -43,6 +43,10 @@ method isLoaded*(self: Module): bool =
return self.moduleLoaded
method viewDidLoad*(self: Module) =
let customNetworks = self.controller.getCustomNetworks()
for n in customNetworks:
self.view.customNetworksModel().add(n.id, n.name)
self.moduleLoaded = true
self.delegate.advancedModuleDidLoad()
@ -123,4 +127,16 @@ method onDebugToggled*(self: Module) =
info "quit the app because of successful debug level changed"
quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported
method addCustomNetwork*(self: Module, name: string, endpoint: string, networkId: int, networkType: string) =
var network: settings_service.Network
network.id = $genUUID()
network.name = name
network.config.NetworkId = networkId
network.config.DataDir = "/ethereum/" & networkType
network.config.UpstreamConfig.Enabled = true
network.config.UpstreamConfig.URL = endpoint
self.controller.addCustomNetwork(network)
method onCustomNetworkAdded*(self: Module, network: settings_service.Network) =
self.view.customNetworksModel().add(network.id, network.name)

View File

@ -1,3 +1,5 @@
import ../../../../../../app_service/service/settings/dto/settings as settings_service_type
method onCurrentNetworkSet*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
@ -18,3 +20,6 @@ method onAutoMessageToggled*(self: AccessInterface) {.base.} =
method onDebugToggled*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method onCustomNetworkAdded*(self: AccessInterface, network: settings_service_type.Network) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -48,3 +48,7 @@ method isDebugEnabled*(self: AccessInterface): bool {.base.} =
method toggleDebug*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method addCustomNetwork*(self: AccessInterface, name: string, endpoint: string, networkId: int, networkType: string)
{.slot.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,18 +1,25 @@
import NimQml
import io_interface
import custom_networks_model
QtObject:
type
View* = ref object of QObject
delegate: io_interface.AccessInterface
customNetworksModel: Model
customNetworksModelVariant: QVariant
proc delete*(self: View) =
self.customNetworksModel.delete
self.customNetworksModelVariant.delete
self.QObject.delete
proc newView*(delegate: io_interface.AccessInterface): View =
new(result, delete)
result.QObject.setup
result.delegate = delegate
result.customNetworksModel = newModel()
result.customNetworksModelVariant = newQVariant(result.customNetworksModel)
proc load*(self: View) =
self.delegate.viewDidLoad()
@ -121,3 +128,16 @@ QtObject:
proc toggleDebug*(self: View) {.slot.} =
self.delegate.toggleDebug()
proc customNetworksModel*(self: View): Model =
return self.customNetworksModel
proc customNetworksModelChanged*(self: View) {.signal.}
proc getCustomNetworksModel(self: View): QVariant {.slot.} =
return self.customNetworksModelVariant
QtProperty[QVariant] customNetworksModel:
read = getCustomNetworksModel
notify = customNetworksModelChanged
proc addCustomNetwork*(self: View, name: string, endpoint: string, networkId: int, networkType: string) {.slot.} =
self.delegate.addCustomNetwork(name, endpoint, networkId, networkType)

View File

@ -1,9 +1,3 @@
import # std libs
json, os
import utils
import chronicles
const GENERATED* = "generated"
const SEED* = "seed"
const KEY* = "key"
@ -19,264 +13,4 @@ const PATH_DEFAULT_WALLET* = PATH_WALLET_ROOT & "/0"
# EIP1581 Chat Key 0, the default whisper key
const PATH_WHISPER* = PATH_EIP_1581 & "/0'/0"
# set via `nim c` param `-d:INFURA_TOKEN:[token]`; should be set in CI/release builds
const INFURA_TOKEN {.strdefine.} = ""
# allow runtime override via environment variable; core contributors can set a
# release token in this way for local development
let INFURA_TOKEN_ENV = $getEnv("INFURA_TOKEN")
let INFURA_TOKEN_RESOLVED =
if INFURA_TOKEN_ENV != "":
INFURA_TOKEN_ENV
else:
INFURA_TOKEN
let DEFAULT_NETWORKS* = %* [
{
"id": "testnet_rpc",
"etherscan-link": "https://ropsten.etherscan.io/address/",
"name": "Ropsten with upstream RPC",
"config": {
"NetworkId": 3,
"DataDir": "/ethereum/testnet_rpc",
"UpstreamConfig": {
"Enabled": true,
"URL": "https://ropsten.infura.io/v3/" & INFURA_TOKEN_RESOLVED
}
}
},
{
"id": "rinkeby_rpc",
"etherscan-link": "https://rinkeby.etherscan.io/address/",
"name": "Rinkeby with upstream RPC",
"config": {
"NetworkId": 4,
"DataDir": "/ethereum/rinkeby_rpc",
"UpstreamConfig": {
"Enabled": true,
"URL": "https://rinkeby.infura.io/v3/" & INFURA_TOKEN_RESOLVED
}
}
},
{
"id": "goerli_rpc",
"etherscan-link": "https://goerli.etherscan.io/address/",
"name": "Goerli with upstream RPC",
"config": {
"NetworkId": 5,
"DataDir": "/ethereum/goerli_rpc",
"UpstreamConfig": {
"Enabled": true,
"URL": "https://goerli.blockscout.com/"
}
}
},
{
"id": "mainnet_rpc",
"etherscan-link": "https://etherscan.io/address/",
"name": "Mainnet with upstream RPC",
"config": {
"NetworkId": 1,
"DataDir": "/ethereum/mainnet_rpc",
"UpstreamConfig": {
"Enabled": true,
"URL": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED
}
}
},
{
"id": "xdai_rpc",
"name": "xDai Chain",
"config": {
"NetworkId": 100,
"DataDir": "/ethereum/xdai_rpc",
"UpstreamConfig": {
"Enabled": true,
"URL": "https://dai.poa.network"
}
}
},
{
"id": "poa_rpc",
"name": "POA Network",
"config": {
"NetworkId": 99,
"DataDir": "/ethereum/poa_rpc",
"UpstreamConfig": {
"Enabled": true,
"URL": "https://core.poa.network"
}
}
}
]
var NODE_CONFIG* = %* {
"BrowsersConfig": {
"Enabled": true
},
"ClusterConfig": {
"Enabled": true
},
"Web3ProviderConfig": {
"Enabled": true
},
"DataDir": "./ethereum/mainnet",
"EnableNTPSync": true,
"KeyStoreDir": "./keystore",
# TODO: commented since it's not necessary (we do the connections thru C bindings). Enable it thru an option once status-nodes are able to be configured in desktop
#"ListenAddr": ":30304",
"LogEnabled": true,
"LogFile": "geth.log",
"LogLevel": $LogLevel.INFO,
"MailserversConfig": {
"Enabled": true
},
"Name": "StatusDesktop",
"NetworkId": 1,
"NoDiscovery": false,
"PermissionsConfig": {
"Enabled": true
},
"Rendezvous": true,
"RegisterTopics": @["whispermail"],
"RequireTopics": {
"whisper": {
"Max": 2,
"Min": 2
}
},
"ShhextConfig": {
"BackupDisabledDataDir": "./",
"EnableMailserverCycle": true,
"DataSyncEnabled": true,
"InstallationID": "aef27732-8d86-5039-a32e-bdbe094d8791",
"MailServerConfirmations": true,
"MaxMessageDeliveryAttempts": 6,
"PFSEnabled": true,
"VerifyENSContractAddress": "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
"VerifyENSURL": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED,
"VerifyTransactionChainID": 1,
"VerifyTransactionURL": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED
},
"StatusAccountsConfig": {
"Enabled": true
},
"UpstreamConfig": {
"Enabled": true,
"URL": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED
},
"WakuConfig": {
"BloomFilterMode": true,
"Enabled": true,
"LightClient": true,
"MinimumPoW": 0.001
},
"WakuV2Config": {
"Enabled": false,
"Host": "0.0.0.0",
"Port": 0,
"LightClient": false
},
"WalletConfig": {
"Enabled": true
},
"EnsConfig": {
"Enabled": true
},
"Networks": [
{
"chainId": 1,
"chainName": "Ethereum Mainnet",
"rpcUrl": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED,
"blockExplorerUrl": "https://etherscan.io/",
"iconUrl": "",
"nativeCurrencyName": "Ether",
"nativeCurrencySymbol": "ETH",
"nativeCurrencyDecimals": 18,
"isTest": false,
"layer": 1,
"enabled": true,
},
{
"chainId": 3,
"chainName": "Ropsten",
"rpcUrl": "https://ropsten.infura.io/v3/" & INFURA_TOKEN_RESOLVED,
"blockExplorerUrl": "https://ropsten.etherscan.io/",
"iconUrl": "",
"nativeCurrencyName": "Ether",
"nativeCurrencySymbol": "ETH",
"nativeCurrencyDecimals": 18,
"isTest": true,
"layer": 1,
"enabled": false,
},
{
"chainId": 4,
"chainName": "Rinkeby",
"rpcUrl": "https://rinkeby.infura.io/v3/" & INFURA_TOKEN_RESOLVED,
"blockExplorerUrl": "https://rinkeby.etherscan.io/",
"iconUrl": "",
"nativeCurrencyName": "Ether",
"nativeCurrencySymbol": "ETH",
"nativeCurrencyDecimals": 18,
"isTest": true,
"layer": 1,
"enabled": false,
},
{
"chainId": 5,
"chainName": "Goerli",
"rpcUrl": "http://goerli.blockscout.com/",
"blockExplorerUrl": "https://goerli.etherscan.io/",
"iconUrl": "",
"nativeCurrencyName": "Ether",
"nativeCurrencySymbol": "ETH",
"nativeCurrencyDecimals": 18,
"isTest": true,
"layer": 1,
"enabled": false,
},
{
"chainId": 10,
"chainName": "Optimistic Ethereum",
"rpcUrl": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED,
"blockExplorerUrl": "https://optimistic.etherscan.io",
"iconUrl": "",
"nativeCurrencyName": "Ether",
"nativeCurrencySymbol": "ETH",
"nativeCurrencyDecimals": 18,
"isTest": false,
"layer": 2,
"enabled": true,
}
]
}
const DEFAULT_NETWORK_NAME* = "mainnet_rpc"
const sep = when defined(windows): "\\" else: "/"
proc getNetworkConfig*(currentNetwork: string): JsonNode =
result = DEFAULT_NETWORKS.first("id", currentNetwork)
proc defaultDataDir(): string =
let homeDir = getHomeDir()
let parentDir =
if defined(development):
parentDir(getAppDir())
elif homeDir == "":
getCurrentDir()
elif defined(macosx):
joinPath(homeDir, "Library", "Application Support")
elif defined(windows):
let targetDir = getEnv("LOCALAPPDATA").string
if targetDir == "":
joinPath(homeDir, "AppData", "Local")
else:
targetDir
else:
let targetDir = getEnv("XDG_CONFIG_HOME").string
if targetDir == "":
joinPath(homeDir, ".config")
else:
targetDir
absolutePath(joinPath(parentDir, "Status"))

View File

@ -0,0 +1,232 @@
import json, os, chronicles, utils
# set via `nim c` param `-d:INFURA_TOKEN:[token]`; should be set in CI/release builds
const INFURA_TOKEN {.strdefine.} = ""
# allow runtime override via environment variable; core contributors can set a
# release token in this way for local development
let INFURA_TOKEN_ENV = $getEnv("INFURA_TOKEN")
let INFURA_TOKEN_RESOLVED =
if INFURA_TOKEN_ENV != "":
INFURA_TOKEN_ENV
else:
INFURA_TOKEN
const DEFAULT_NETWORK_NAME* = "mainnet_rpc"
const DEFAULT_NETWORKS_IDS* = @["mainnet_rpc", "testnet_rpc", "rinkeby_rpc", "goerli_rpc", "xdai_rpc", "poa_rpc" ]
let DEFAULT_NETWORKS* = %* [
{
"id": "testnet_rpc",
"etherscan-link": "https://ropsten.etherscan.io/address/",
"name": "Ropsten with upstream RPC",
"config": {
"NetworkId": 3,
"DataDir": "/ethereum/testnet_rpc",
"UpstreamConfig": {
"Enabled": true,
"URL": "https://ropsten.infura.io/v3/" & INFURA_TOKEN_RESOLVED
}
}
},
{
"id": "rinkeby_rpc",
"etherscan-link": "https://rinkeby.etherscan.io/address/",
"name": "Rinkeby with upstream RPC",
"config": {
"NetworkId": 4,
"DataDir": "/ethereum/rinkeby_rpc",
"UpstreamConfig": {
"Enabled": true,
"URL": "https://rinkeby.infura.io/v3/" & INFURA_TOKEN_RESOLVED
}
}
},
{
"id": "goerli_rpc",
"etherscan-link": "https://goerli.etherscan.io/address/",
"name": "Goerli with upstream RPC",
"config": {
"NetworkId": 5,
"DataDir": "/ethereum/goerli_rpc",
"UpstreamConfig": {
"Enabled": true,
"URL": "https://goerli.blockscout.com/"
}
}
},
{
"id": "mainnet_rpc",
"etherscan-link": "https://etherscan.io/address/",
"name": "Mainnet with upstream RPC",
"config": {
"NetworkId": 1,
"DataDir": "/ethereum/mainnet_rpc",
"UpstreamConfig": {
"Enabled": true,
"URL": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED
}
}
},
{
"id": "xdai_rpc",
"name": "xDai Chain",
"config": {
"NetworkId": 100,
"DataDir": "/ethereum/xdai_rpc",
"UpstreamConfig": {
"Enabled": true,
"URL": "https://dai.poa.network"
}
}
},
{
"id": "poa_rpc",
"name": "POA Network",
"config": {
"NetworkId": 99,
"DataDir": "/ethereum/poa_rpc",
"UpstreamConfig": {
"Enabled": true,
"URL": "https://core.poa.network"
}
}
}
]
var NODE_CONFIG* = %* {
"BrowsersConfig": {
"Enabled": true
},
"ClusterConfig": {
"Enabled": true
},
"DataDir": "./ethereum/mainnet",
"EnableNTPSync": true,
"KeyStoreDir": "./keystore",
# TODO: commented since it's not necessary (we do the connections thru C bindings). Enable it thru an option once status-nodes are able to be configured in desktop
#"ListenAddr": ":30304",
"LogEnabled": true,
"LogFile": "geth.log",
"LogLevel": $LogLevel.INFO,
"MailserversConfig": {
"Enabled": true
},
"Name": "StatusDesktop",
"NetworkId": 1,
"NoDiscovery": false,
"PermissionsConfig": {
"Enabled": true
},
"Rendezvous": true,
"RegisterTopics": @["whispermail"],
"RequireTopics": {
"whisper": {
"Max": 2,
"Min": 2
}
},
"ShhextConfig": {
"BackupDisabledDataDir": "./",
"DataSyncEnabled": true,
"InstallationID": "aef27732-8d86-5039-a32e-bdbe094d8791",
"MailServerConfirmations": true,
"MaxMessageDeliveryAttempts": 6,
"PFSEnabled": true,
"VerifyENSContractAddress": "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
"VerifyENSURL": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED,
"VerifyTransactionChainID": 1,
"VerifyTransactionURL": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED
},
"StatusAccountsConfig": {
"Enabled": true
},
"UpstreamConfig": {
"Enabled": true,
"URL": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED
},
"WakuConfig": {
"BloomFilterMode": true,
"Enabled": true,
"LightClient": true,
"MinimumPoW": 0.001
},
"WakuV2Config": {
"Enabled": false,
"Host": "0.0.0.0",
"Port": 0,
"LightClient": false
},
"WalletConfig": {
"Enabled": true
},
"Networks": [
{
"chainId": 1,
"chainName": "Ethereum Mainnet",
"rpcUrl": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED,
"blockExplorerUrl": "https://etherscan.io/",
"iconUrl": "",
"nativeCurrencyName": "Ether",
"nativeCurrencySymbol": "ETH",
"nativeCurrencyDecimals": 18,
"isTest": false,
"layer": 1,
"enabled": true,
},
{
"chainId": 3,
"chainName": "Ropsten",
"rpcUrl": "https://ropsten.infura.io/v3/" & INFURA_TOKEN_RESOLVED,
"blockExplorerUrl": "https://ropsten.etherscan.io/",
"iconUrl": "",
"nativeCurrencyName": "Ether",
"nativeCurrencySymbol": "ETH",
"nativeCurrencyDecimals": 18,
"isTest": true,
"layer": 1,
"enabled": false,
},
{
"chainId": 4,
"chainName": "Rinkeby",
"rpcUrl": "https://rinkeby.infura.io/v3/" & INFURA_TOKEN_RESOLVED,
"blockExplorerUrl": "https://rinkeby.etherscan.io/",
"iconUrl": "",
"nativeCurrencyName": "Ether",
"nativeCurrencySymbol": "ETH",
"nativeCurrencyDecimals": 18,
"isTest": true,
"layer": 1,
"enabled": false,
},
{
"chainId": 5,
"chainName": "Goerli",
"rpcUrl": "http://goerli.blockscout.com/",
"blockExplorerUrl": "https://goerli.etherscan.io/",
"iconUrl": "",
"nativeCurrencyName": "Ether",
"nativeCurrencySymbol": "ETH",
"nativeCurrencyDecimals": 18,
"isTest": true,
"layer": 1,
"enabled": false,
},
{
"chainId": 10,
"chainName": "Optimistic Ethereum",
"rpcUrl": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED,
"blockExplorerUrl": "https://optimistic.etherscan.io",
"iconUrl": "",
"nativeCurrencyName": "Ether",
"nativeCurrencySymbol": "ETH",
"nativeCurrencyDecimals": 18,
"isTest": false,
"layer": 2,
"enabled": true,
}
]
}
proc getNetworkConfig*(currentNetwork: string): JsonNode =
result = DEFAULT_NETWORKS.first("id", currentNetwork)

View File

@ -1,4 +1,4 @@
import json, random, times, strutils
import json, random, times, strutils, os
import signing_phrases
@ -24,3 +24,28 @@ proc first*(jArray: JsonNode, fieldName, id: string): JsonNode =
proc prettyEnsName*(ensName: string): string =
if ensName.endsWith(".eth"):
return "@" & ensName.split(".")[0]
const sep = when defined(windows): "\\" else: "/"
proc defaultDataDir(): string =
let homeDir = getHomeDir()
let parentDir =
if defined(development):
parentDir(getAppDir())
elif homeDir == "":
getCurrentDir()
elif defined(macosx):
joinPath(homeDir, "Library", "Application Support")
elif defined(windows):
let targetDir = getEnv("LOCALAPPDATA").string
if targetDir == "":
joinPath(homeDir, "AppData", "Local")
else:
targetDir
else:
let targetDir = getEnv("XDG_CONFIG_HOME").string
if targetDir == "":
joinPath(homeDir, ".config")
else:
targetDir
absolutePath(joinPath(parentDir, "Status"))

View File

@ -8,7 +8,7 @@ import status/statusgo_backend_new/accounts as status_account
import status/statusgo_backend_new/general as status_general
import ../../../app/core/fleets/fleet_configuration
import ../../common/[account_constants, utils, string_utils]
import ../../common/[account_constants, network_constants, utils, string_utils]
import ../../../constants as main_constants
export service_interface

View File

@ -27,7 +27,7 @@ proc newService*(fleetConfiguration: FleetConfiguration, settingsService: settin
proc adaptNodeSettingsForTheAppNeed(self: Service) =
let currentNetworkDetails = self.settingsService.getCurrentNetworkDetails()
var dataDir = currentNetworkDetails.config.dataDir
var dataDir = currentNetworkDetails.config.DataDir
dataDir.removeSuffix("_rpc")
self.configuration.DataDir = dataDir
@ -102,14 +102,14 @@ method setNetwork*(self: Service, network: string): bool =
return false
let currentNetworkDetails = self.settingsService.getCurrentNetworkDetails()
var dataDir = currentNetworkDetails.config.dataDir
var dataDir = currentNetworkDetails.config.DataDir
dataDir.removeSuffix("_rpc")
var newConfiguration = self.configuration
newConfiguration.NetworkId = currentNetworkDetails.config.networkId
newConfiguration.NetworkId = currentNetworkDetails.config.NetworkId
newConfiguration.DataDir = dataDir
newConfiguration.UpstreamConfig.Enabled = currentNetworkDetails.config.upstreamConfig.enabled
newConfiguration.UpstreamConfig.URL = currentNetworkDetails.config.upstreamConfig.url
newConfiguration.UpstreamConfig.Enabled = currentNetworkDetails.config.UpstreamConfig.Enabled
newConfiguration.UpstreamConfig.URL = currentNetworkDetails.config.UpstreamConfig.URL
return self.saveConfiguration(newConfiguration)
method setBloomFilterMode*(self: Service, bloomFilterMode: bool): bool =

View File

@ -1,4 +1,4 @@
import json, options, tables, strutils
import json, options, tables, strutils, marshal
import ../../stickers/dto/stickers
include ../../../common/json_utils
@ -41,13 +41,13 @@ const KEY_WAKU_BLOOM_FILTER_MODE* = "waku-bloom-filter-mode"
const KEY_AUTO_MESSAGE_ENABLED* = "auto-message-enabled?"
type UpstreamConfig* = object
enabled*: bool
url*: string
Enabled*: bool
URL*: string
type Config* = object
networkId*: int
dataDir*: string
upstreamConfig*: UpstreamConfig
NetworkId*: int
DataDir*: string
UpstreamConfig*: UpstreamConfig
type Network* = object
id*: string
@ -105,16 +105,16 @@ type
autoMessageEnabled*: bool
proc toUpstreamConfig*(jsonObj: JsonNode): UpstreamConfig =
discard jsonObj.getProp("Enabled", result.enabled)
discard jsonObj.getProp("URL", result.url)
discard jsonObj.getProp("Enabled", result.Enabled)
discard jsonObj.getProp("URL", result.URL)
proc toConfig*(jsonObj: JsonNode): Config =
discard jsonObj.getProp("NetworkId", result.networkId)
discard jsonObj.getProp("DataDir", result.dataDir)
discard jsonObj.getProp("NetworkId", result.NetworkId)
discard jsonObj.getProp("DataDir", result.DataDir)
var upstreamConfigObj: JsonNode
if(jsonObj.getProp("UpstreamConfig", upstreamConfigObj)):
result.upstreamConfig = toUpstreamConfig(upstreamConfigObj)
result.UpstreamConfig = toUpstreamConfig(upstreamConfigObj)
proc toNetwork*(jsonObj: JsonNode): Network =
discard jsonObj.getProp("id", result.id)
@ -207,3 +207,23 @@ proc toSettingsDto*(jsonObj: JsonNode): SettingsDto =
discard jsonObj.getProp(KEY_NODE_CONFIG, result.nodeConfig)
discard jsonObj.getProp(KEY_WAKU_BLOOM_FILTER_MODE, result.wakuBloomFilterMode)
proc configToJsonNode*(config: Config): JsonNode =
let configAsString = $$config
result = parseJson(configAsString)
proc networkToJsonNode*(network: Network): JsonNode =
## we cannot use the same technique as we did for `configToJsonNode` cause we cannot have
## variable name with a dash in order to map `etherscan-link` appropriatelly
return %*{
"id": network.id,
"etherscan-link": network.etherscanLink,
"name": network.name,
"config": configToJsonNode(network.config)
}
proc availableNetworksToJsonNode*(networks: seq[Network]): JsonNode =
var availableNetworksAsJson = newJArray()
for n in networks:
availableNetworksAsJson.add(networkToJsonNode(n))
return availableNetworksAsJson

View File

@ -1,5 +1,6 @@
import chronicles, json, sequtils, tables, sugar
import ../../common/[network_constants]
import service_interface, ./dto/settings
import status/statusgo_backend_new/settings as status_settings
@ -282,6 +283,9 @@ method getFleet*(self: Service): string =
method getAvailableNetworks*(self: Service): seq[Network] =
return self.settings.availableNetworks
method getAvailableCustomNetworks*(self: Service): seq[Network] =
return self.settings.availableNetworks.filterIt(it.id notin DEFAULT_NETWORKS_IDS)
method getCurrentNetworkDetails*(self: Service): Network =
for n in self.settings.availableNetworks:
if(n.id == self.getCurrentNetwork()):
@ -290,8 +294,18 @@ method getCurrentNetworkDetails*(self: Service): Network =
# we should never be here
error "error: current network is not among available networks"
method addCustomNetwork*(self: Service, network: Network): bool =
var newAvailableNetworks = self.settings.availableNetworks
newAvailableNetworks.add(network)
let availableNetworksAsJson = availableNetworksToJsonNode(newAvailableNetworks)
if(self.saveSetting(KEY_NETWORKS_ALL_NETWORKS, availableNetworksAsJson)):
self.settings.availableNetworks = newAvailableNetworks
return true
return false
method getCurrentNetworkId*(self: Service): int =
self.getCurrentNetworkDetails().config.networkId
self.getCurrentNetworkDetails().config.NetworkId
method getCurrentUserStatus*(self: Service): CurrentUserStatus =
self.settings.currentUserStatus
@ -311,7 +325,7 @@ method saveWalletVisibleTokens*(self: Service, tokens: seq[string]): bool =
return false
method isEIP1559Enabled*(self: Service, blockNumber: int): bool =
let networkId = self.getCurrentNetworkDetails().config.networkId
let networkId = self.getCurrentNetworkDetails().config.NetworkId
let activationBlock = case networkId:
of 3: 10499401 # Ropsten
of 4: 8897988 # Rinkeby

View File

@ -182,6 +182,12 @@ method getFleet*(self: ServiceInterface): string {.base.} =
method getAvailableNetworks*(self: ServiceInterface): seq[Network] {.base.} =
raise newException(ValueError, "No implementation available")
method getAvailableCustomNetworks*(self: ServiceInterface): seq[Network] {.base.} =
raise newException(ValueError, "No implementation available")
method addCustomNetwork*(self: ServiceInterface, network: Network): bool {.base.} =
raise newException(ValueError, "No implementation available")
method getCurrentNetworkDetails*(self: ServiceInterface): Network {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -73,6 +73,7 @@ ModalPopup {
id: addNetworkPopupComponent
NewCustomNetworkModal {
anchors.centerIn: parent
advancedStore: popup.advancedStore
onClosed: {
destroy()
}
@ -149,16 +150,15 @@ ModalPopup {
anchors.rightMargin: -Style.current.padding
}
// Not Refactored Yet
// Repeater {
// model: profileModel.network.customNetworkList
// delegate: NetworkRadioSelector {
// advancedStore: popup.advancedStore
// networkName: name
// network: customNetworkId
// buttonGroup: radioGroup
// }
// }
Repeater {
model: popup.advancedStore.customNetworksModel
delegate: NetworkRadioSelector {
advancedStore: popup.advancedStore
networkName: model.name
network: model.id
buttonGroup: radioGroup
}
}
}
}
}

View File

@ -14,6 +14,8 @@ StatusModal {
header.title: qsTrId("add-network")
height: 644
property var advancedStore
property string nameValidationError: ""
property string rpcValidationError: ""
property string networkValidationError: ""
@ -80,9 +82,10 @@ StatusModal {
addNetworkPopup.networkId = parseInt(networkInput.text, 10);
}
// Not Refactored Yet
// profileModel.network.add(nameInput.text, rpcInput.text, addNetworkPopup.networkId, addNetworkPopup.networkType)
// profileModel.network.reloadCustomNetworks();
addNetworkPopup.advancedStore.addCustomNetwork(nameInput.text,
rpcInput.text,
addNetworkPopup.networkId,
addNetworkPopup.networkType)
addNetworkPopup.close()
}
}

View File

@ -16,6 +16,8 @@ QtObject {
property bool isAutoMessageEnabled: advancedModule.isAutoMessageEnabled
property bool isDebugEnabled: advancedModule.isDebugEnabled
property var customNetworksModel: advancedModule.customNetworksModel
property bool isWakuV2: root.fleet === Constants.waku_prod ||
root.fleet === Constants.waku_test
@ -50,4 +52,8 @@ QtObject {
function toggleDebug() {
root.advancedModule.toggleDebug()
}
function addCustomNetwork(name, endpoint, networkId, networkType) {
root.advancedModule.addCustomNetwork(name, endpoint, networkId, networkType)
}
}