feat: get current network details

Adds settings API for getting current network details.

Uses the current network details to display the correct etherscan link in QML (etherscan URL is a setting in the current network settings).
This commit is contained in:
emizzle 2020-07-21 17:15:04 +10:00 committed by Iuri Matias
parent e334e80774
commit d4d532691e
7 changed files with 60 additions and 14 deletions

View File

@ -1,4 +1,4 @@
import NimQml, Tables, sequtils
import NimQml, Tables, sequtils, sugar
import ../../../status/chat/stickers, ./sticker_list
import ../../../status/libstatus/types, ../../../status/libstatus/utils
@ -83,7 +83,7 @@ QtObject:
proc `[]`*(self: StickerPackList, packId: int): StickerPack =
if not self.hasKey(packId):
raise newException(ValueError, "Sticker pack list does not have a pack with id " & $packId)
result = self.packs.filterIt(it.pack.id == packId)[0].pack
result = find(self.packs, (view: StickerPackView) => view.pack.id == packId).pack
proc addStickerPackToList*(self: StickerPackList, pack: StickerPack, stickers: StickerList, installed, bought: bool) =
self.beginInsertRows(newQModelIndex(), 0, 0)

View File

@ -3,6 +3,8 @@ import NimQml, eventemitter, strformat, strutils, chronicles
import view
import views/[asset_list, account_list, account_item]
import ../../status/libstatus/wallet as status_wallet
import ../../status/libstatus/settings as status_settings
import ../../status/libstatus/types as status_types
import ../../signals/types
import ../../status/[status, wallet]
@ -40,6 +42,8 @@ proc init*(self: WalletController) =
self.status.events.on("assetChanged") do(e: Args):
self.view.updateView()
self.view.setEtherscanLink(status_settings.getCurrentNetworkDetails().etherscanLink)
method onSignal(self: WalletController, data: Signal) =
debug "New signal received"
discard

View File

@ -12,6 +12,7 @@ QtObject:
currentTransactions: TransactionList
status: Status
totalFiatBalance: string
etherscanLink: string
proc delete(self: WalletView) =
self.accounts.delete
@ -32,8 +33,22 @@ QtObject:
result.currentTransactions = newTransactionList()
result.currentCollectiblesList = newCollectiblesList()
result.totalFiatBalance = ""
result.etherscanLink = ""
result.setup
proc etherscanLinkChanged*(self: WalletView) {.signal.}
proc getEtherscanLink*(self: WalletView): QVariant {.slot.} =
newQVariant(self.etherscanLink.replace("/address", "/tx"))
proc setEtherscanLink*(self: WalletView, link: string) =
self.etherscanLink = link
self.etherscanLinkChanged()
QtProperty[QVariant] etherscanLink:
read = getEtherscanLink
notify = etherscanLinkChanged
proc currentAccountChanged*(self: WalletView) {.signal.}
proc setCurrentAssetList*(self: WalletView, assetList: seq[Asset])

View File

@ -1,5 +1,5 @@
import core, ./types, ../../signals/types as statusgo_types, ./accounts/constants, ./utils
import json, tables
import json, tables, sugar, sequtils
import json_serialization
var settings: JsonNode = %*{}
@ -36,4 +36,9 @@ proc getSetting*[T](name: Setting, useCached: bool = true): T =
proc getCurrentNetwork*(): Network =
result = Network.Mainnet
if getSetting[string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME) == "testnet_rpc":
result = Network.Testnet
result = Network.Testnet
proc getCurrentNetworkDetails*(): NetworkDetails =
let currNetwork = getSetting[string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME)
let networks = getSetting[seq[NetworkDetails]](Setting.Networks_Networks)
networks.find((network: NetworkDetails) => network.id == currNetwork)

View File

@ -138,11 +138,28 @@ type
Setting* {.pure.} = enum
Appearance = "appearance",
Currency = "currency,"
Currency = "currency"
EtherscanLink = "etherscan-link"
InstallationId = "installation-id"
Mnemonic = "mnemonic",
Networks_CurrentNetwork = "networks/current-network",
NodeConfig = "node-config",
PublicKey = "public-key",
Stickers_PacksInstalled = "stickers/packs-installed",
Stickers_Recent = "stickers/recent-stickers"
Mnemonic = "mnemonic"
Networks_Networks = "networks/networks"
Networks_CurrentNetwork = "networks/current-network"
NodeConfig = "node-config"
PublicKey = "public-key"
Stickers_PacksInstalled = "stickers/packs-installed"
Stickers_Recent = "stickers/recent-stickers"
UpstreamConfig* = ref object
enabled* {.serializedFieldName("Enabled").}: bool
url* {.serializedFieldName("URL").}: string
NodeConfig* = ref object
networkId* {.serializedFieldName("NetworkId").}: int
dataDir* {.serializedFieldName("DataDir").}: string
upstreamConfig* {.serializedFieldName("UpstreamConfig").}: UpstreamConfig
NetworkDetails* = ref object
id*: string
name*: string
etherscanLink* {.serializedFieldName("etherscan-link").}: string
config*: NodeConfig

View File

@ -1,4 +1,4 @@
import json, types, random, strutils, strformat, tables
import json, random, strutils, strformat, tables
import stint, nim_status
from times import getTime, toUnix, nanosecond
import accounts/signing_phrases
@ -70,3 +70,9 @@ proc isEmpty*(a: JsonNode): bool =
of JNull: return true
else:
return false
proc find*[T](s: seq[T], pred: proc(x: T): bool {.closure.}): T {.inline.} =
let results = s.filter(pred)
if results.len == 0:
return default(type(T))
result = results[0]

View File

@ -43,8 +43,7 @@ Item {
return sendingError.open()
}
//% "Transaction sent to the blockchain. You can watch the progress on Etherscan: https://etherscan.io/tx/%1"
sendingSuccess.text = qsTrId("transaction-sent-to-the-blockchain.-you-can-watch-the-progress-on-etherscan:-https://etherscan.io/tx/%1").arg(result)
sendingSuccess.text = qsTr("Transaction sent to the blockchain. You can watch the progress on Etherscan: %2/%1").arg(result).arg(walletModel.etherscanLink)
sendingSuccess.open()
}