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:
parent
e334e80774
commit
d4d532691e
|
@ -1,4 +1,4 @@
|
||||||
import NimQml, Tables, sequtils
|
import NimQml, Tables, sequtils, sugar
|
||||||
import ../../../status/chat/stickers, ./sticker_list
|
import ../../../status/chat/stickers, ./sticker_list
|
||||||
import ../../../status/libstatus/types, ../../../status/libstatus/utils
|
import ../../../status/libstatus/types, ../../../status/libstatus/utils
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ QtObject:
|
||||||
proc `[]`*(self: StickerPackList, packId: int): StickerPack =
|
proc `[]`*(self: StickerPackList, packId: int): StickerPack =
|
||||||
if not self.hasKey(packId):
|
if not self.hasKey(packId):
|
||||||
raise newException(ValueError, "Sticker pack list does not have a pack with id " & $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) =
|
proc addStickerPackToList*(self: StickerPackList, pack: StickerPack, stickers: StickerList, installed, bought: bool) =
|
||||||
self.beginInsertRows(newQModelIndex(), 0, 0)
|
self.beginInsertRows(newQModelIndex(), 0, 0)
|
||||||
|
|
|
@ -3,6 +3,8 @@ import NimQml, eventemitter, strformat, strutils, chronicles
|
||||||
import view
|
import view
|
||||||
import views/[asset_list, account_list, account_item]
|
import views/[asset_list, account_list, account_item]
|
||||||
import ../../status/libstatus/wallet as status_wallet
|
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 ../../signals/types
|
||||||
|
|
||||||
import ../../status/[status, wallet]
|
import ../../status/[status, wallet]
|
||||||
|
@ -40,6 +42,8 @@ proc init*(self: WalletController) =
|
||||||
self.status.events.on("assetChanged") do(e: Args):
|
self.status.events.on("assetChanged") do(e: Args):
|
||||||
self.view.updateView()
|
self.view.updateView()
|
||||||
|
|
||||||
|
self.view.setEtherscanLink(status_settings.getCurrentNetworkDetails().etherscanLink)
|
||||||
|
|
||||||
method onSignal(self: WalletController, data: Signal) =
|
method onSignal(self: WalletController, data: Signal) =
|
||||||
debug "New signal received"
|
debug "New signal received"
|
||||||
discard
|
discard
|
||||||
|
|
|
@ -12,6 +12,7 @@ QtObject:
|
||||||
currentTransactions: TransactionList
|
currentTransactions: TransactionList
|
||||||
status: Status
|
status: Status
|
||||||
totalFiatBalance: string
|
totalFiatBalance: string
|
||||||
|
etherscanLink: string
|
||||||
|
|
||||||
proc delete(self: WalletView) =
|
proc delete(self: WalletView) =
|
||||||
self.accounts.delete
|
self.accounts.delete
|
||||||
|
@ -32,8 +33,22 @@ QtObject:
|
||||||
result.currentTransactions = newTransactionList()
|
result.currentTransactions = newTransactionList()
|
||||||
result.currentCollectiblesList = newCollectiblesList()
|
result.currentCollectiblesList = newCollectiblesList()
|
||||||
result.totalFiatBalance = ""
|
result.totalFiatBalance = ""
|
||||||
|
result.etherscanLink = ""
|
||||||
result.setup
|
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 currentAccountChanged*(self: WalletView) {.signal.}
|
||||||
|
|
||||||
proc setCurrentAssetList*(self: WalletView, assetList: seq[Asset])
|
proc setCurrentAssetList*(self: WalletView, assetList: seq[Asset])
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import core, ./types, ../../signals/types as statusgo_types, ./accounts/constants, ./utils
|
import core, ./types, ../../signals/types as statusgo_types, ./accounts/constants, ./utils
|
||||||
import json, tables
|
import json, tables, sugar, sequtils
|
||||||
import json_serialization
|
import json_serialization
|
||||||
|
|
||||||
var settings: JsonNode = %*{}
|
var settings: JsonNode = %*{}
|
||||||
|
@ -37,3 +37,8 @@ proc getCurrentNetwork*(): Network =
|
||||||
result = Network.Mainnet
|
result = Network.Mainnet
|
||||||
if getSetting[string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME) == "testnet_rpc":
|
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)
|
|
@ -138,11 +138,28 @@ type
|
||||||
|
|
||||||
Setting* {.pure.} = enum
|
Setting* {.pure.} = enum
|
||||||
Appearance = "appearance",
|
Appearance = "appearance",
|
||||||
Currency = "currency,"
|
Currency = "currency"
|
||||||
|
EtherscanLink = "etherscan-link"
|
||||||
InstallationId = "installation-id"
|
InstallationId = "installation-id"
|
||||||
Mnemonic = "mnemonic",
|
Mnemonic = "mnemonic"
|
||||||
Networks_CurrentNetwork = "networks/current-network",
|
Networks_Networks = "networks/networks"
|
||||||
NodeConfig = "node-config",
|
Networks_CurrentNetwork = "networks/current-network"
|
||||||
PublicKey = "public-key",
|
NodeConfig = "node-config"
|
||||||
Stickers_PacksInstalled = "stickers/packs-installed",
|
PublicKey = "public-key"
|
||||||
|
Stickers_PacksInstalled = "stickers/packs-installed"
|
||||||
Stickers_Recent = "stickers/recent-stickers"
|
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
|
|
@ -1,4 +1,4 @@
|
||||||
import json, types, random, strutils, strformat, tables
|
import json, random, strutils, strformat, tables
|
||||||
import stint, nim_status
|
import stint, nim_status
|
||||||
from times import getTime, toUnix, nanosecond
|
from times import getTime, toUnix, nanosecond
|
||||||
import accounts/signing_phrases
|
import accounts/signing_phrases
|
||||||
|
@ -70,3 +70,9 @@ proc isEmpty*(a: JsonNode): bool =
|
||||||
of JNull: return true
|
of JNull: return true
|
||||||
else:
|
else:
|
||||||
return false
|
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]
|
||||||
|
|
|
@ -43,8 +43,7 @@ Item {
|
||||||
return sendingError.open()
|
return sendingError.open()
|
||||||
}
|
}
|
||||||
|
|
||||||
//% "Transaction sent to the blockchain. You can watch the progress on Etherscan: https://etherscan.io/tx/%1"
|
sendingSuccess.text = qsTr("Transaction sent to the blockchain. You can watch the progress on Etherscan: %2/%1").arg(result).arg(walletModel.etherscanLink)
|
||||||
sendingSuccess.text = qsTrId("transaction-sent-to-the-blockchain.-you-can-watch-the-progress-on-etherscan:-https://etherscan.io/tx/%1").arg(result)
|
|
||||||
sendingSuccess.open()
|
sendingSuccess.open()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue