Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import wallet_secretes_config
import wallet_config
import image_crop_rectangle
import api_config
import network

export wallet_secretes_config
export wallet_config
export image_crop_rectangle
export api_config
export network

type
CreateAccountRequest* = object
Expand Down Expand Up @@ -40,6 +42,7 @@ type
verifyTransactionChainID*: Option[int64]
upstreamConfig*: string
networkID*: Option[uint64]
testOverrideNetworks*: seq[Network]

walletSecretsConfig*: WalletSecretsConfig
walletConfig*: WalletConfig
Expand Down
84 changes: 84 additions & 0 deletions src/app_service/service/accounts/dto/network.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import json
import constants as main_constants

const ANVIL_NETWORK_ID = 31337

type
RpcProvider* = object
chainId*: uint64
name*: string
url*: string
enableRpsLimiter*: bool
providerType*: string
enabled*: bool
authType*: string

Network* = object
chainID*: uint64
chainName*: string
rpcProviders*: seq[RpcProvider] # List of RPC providers, in the order in which they are accessed
nativeCurrencyName*: string
nativeCurrencySymbol*: string
nativeCurrencyDecimals*: uint64
isTest*: bool
layer*: uint64
enabled*: bool
# chainColor*: string
shortName*: string
# tokenOverrides*: seq[Token] # Assuming Token is defined elsewhere
# relatedChainID*: uint64
isActive*: bool
isDeactivatable*: bool
# eIP1559Enabled*: bool
# noBaseFee*: bool
# noPriorityFee*: bool
# communitiesSupported*: bool

proc toJson*(self: Network): JsonNode =
result = %*{
"chainId": self.chainID,
"chainName": self.chainName,
"rpcProviders": self.rpcProviders,
"nativeCurrencyName": self.nativeCurrencyName,
"nativeCurrencySymbol": self.nativeCurrencySymbol,
"nativeCurrencyDecimals": self.nativeCurrencyDecimals,
"isTest": self.isTest,
"layer": self.layer,
"enabled": self.enabled,
# "chainColor": self.chainColor,
"shortName": self.shortName,
# "tokenOverrides": self.tokenOverrides,
# "relatedChainId": self.relatedChainID,
"isActive": self.isActive,
"isDeactivatable": self.isDeactivatable,
# "eip1559Enabled": self.eIP1559Enabled,
# "noBaseFee": self.noBaseFee,
# "noPriorityFee": self.noPriorityFee,
# "communitiesSupported": self.communitiesSupported,
}

proc newAnvilNetwork*(): Network =
result = Network(
chainID: ANVIL_NETWORK_ID,
chainName: "Anvil",
rpcProviders: @[
RpcProvider(
chainId: ANVIL_NETWORK_ID,
name: "Anvil Direct",
url: main_constants.ANVIL_URL,
enableRpsLimiter: false,
providerType: "embedded-direct",
enabled: true,
authType: "no-auth"
)
],
shortName: "eth",
nativeCurrencyName: "Ether",
nativeCurrencySymbol: "ETH",
nativeCurrencyDecimals: 18,
isTest: false,
layer: 1,
enabled: true,
isActive: true,
isDeactivatable: false
)
6 changes: 5 additions & 1 deletion src/app_service/service/accounts/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ QtObject:
return defined(ios) or defined(android)

proc defaultCreateAccountRequest*(): CreateAccountRequest =
return CreateAccountRequest(
var request = CreateAccountRequest(
rootDataDir: main_constants.STATUSGODIR,
kdfIterations: KDF_ITERATIONS,
customizationColor: DEFAULT_CUSTOMIZATION_COLOR,
Expand All @@ -195,6 +195,10 @@ QtObject:
walletConfig: buildWalletConfig(),
apiConfig: defaultApiConfig(),
)
if main_constants.USE_ANVIL:
request.networkID = some(31337'u64)
request.testOverrideNetworks = @[newAnvilNetwork()]
return request

proc buildCreateAccountRequest(password: string, displayName: string, imagePath: string,
imageCropRectangle: ImageCropRectangle, thirdpartyServicesEnabled: bool): CreateAccountRequest =
Expand Down
2 changes: 2 additions & 0 deletions src/constants.nim
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ let
METRICS_ADDRESS* = desktopConfig.metricsAddress
WAKU_FLEET* = desktopConfig.wakuFleet
WAKU_FLEETS_CONFIG* = desktopConfig.wakuFleetsConfig
USE_ANVIL* = desktopConfig.useAnvil
ANVIL_URL* = desktopConfig.anvilUrl

proc hasLogLevelOption*(): bool =
for p in cliParams:
Expand Down
10 changes: 10 additions & 0 deletions src/env_cli_vars.nim
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,16 @@ type StatusDesktopConfig = object
desc: "Sets address for prometheus metrics"
name: "METRICS_ADDRESS"
abbr: "metrics-address" .}: string
useAnvil* {.
defaultValue: false
desc: "Use Anvil network"
name: "USE_ANVIL"
abbr: "use-anvil" .}: bool
anvilUrl* {.
defaultValue: "http://localhost:8545"
desc: "Anvil JSON-RPC URL"
name: "ANVIL_URL"
abbr: "anvil-url" .}: string

# On macOS the first time when a user gets the "App downloaded from the
# internet" warning, and clicks the Open button, the OS passes a unique process
Expand Down