diff --git a/src/app/chat/views/sticker_pack_list.nim b/src/app/chat/views/sticker_pack_list.nim index ed29e8d218..0bcee5279e 100644 --- a/src/app/chat/views/sticker_pack_list.nim +++ b/src/app/chat/views/sticker_pack_list.nim @@ -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) diff --git a/src/app/wallet/core.nim b/src/app/wallet/core.nim index cecce13369..cc820366a2 100644 --- a/src/app/wallet/core.nim +++ b/src/app/wallet/core.nim @@ -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 diff --git a/src/app/wallet/view.nim b/src/app/wallet/view.nim index de5f97d6f2..816849c2bc 100644 --- a/src/app/wallet/view.nim +++ b/src/app/wallet/view.nim @@ -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]) diff --git a/src/status/libstatus/settings.nim b/src/status/libstatus/settings.nim index de247b4bbc..9aad246895 100644 --- a/src/status/libstatus/settings.nim +++ b/src/status/libstatus/settings.nim @@ -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 \ No newline at end of file + 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) \ No newline at end of file diff --git a/src/status/libstatus/types.nim b/src/status/libstatus/types.nim index 1f779004c8..734839fab6 100644 --- a/src/status/libstatus/types.nim +++ b/src/status/libstatus/types.nim @@ -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" \ No newline at end of file + 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 \ No newline at end of file diff --git a/src/status/libstatus/utils.nim b/src/status/libstatus/utils.nim index eadb804d0b..a745a02440 100644 --- a/src/status/libstatus/utils.nim +++ b/src/status/libstatus/utils.nim @@ -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] diff --git a/ui/app/AppLayouts/Wallet/components/SendModalContent.qml b/ui/app/AppLayouts/Wallet/components/SendModalContent.qml index af34558f1f..56c462252f 100644 --- a/ui/app/AppLayouts/Wallet/components/SendModalContent.qml +++ b/ui/app/AppLayouts/Wallet/components/SendModalContent.qml @@ -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() }