diff --git a/src/app/wallet/core.nim b/src/app/wallet/core.nim index 3aca3e6148..3a01b76fc0 100644 --- a/src/app/wallet/core.nim +++ b/src/app/wallet/core.nim @@ -47,9 +47,15 @@ proc init*(self: WalletController) = self.status.events.on(SignalType.Wallet.event) do(e:Args): var data = WalletSignal(e) - if data.eventType == "newblock": - for acc in data.accounts: - self.status.wallet.updateAccount(acc) - # TODO: show notification - # TODO: data.eventType == history, reorg, recent-history-fetching, recent-history-ready: + case data.eventType: + of "newblock": + for acc in data.accounts: + self.status.wallet.updateAccount(acc) + # TODO: show notification + of "recent-history-fetching": + self.view.setHistoryFetchState(data.accounts, true) + of "recent-history-ready": + self.view.setHistoryFetchState(data.accounts, false) + + # TODO: handle these data.eventType: history, reorg # see status-react/src/status_im/ethereum/subscriptions.cljs diff --git a/src/app/wallet/view.nim b/src/app/wallet/view.nim index 5bca4ee1fb..9ccd505a68 100644 --- a/src/app/wallet/view.nim +++ b/src/app/wallet/view.nim @@ -1,4 +1,4 @@ -import NimQml, Tables, strformat, strutils, chronicles, json, std/wrapnils, parseUtils, stint +import NimQml, Tables, strformat, strutils, chronicles, json, std/wrapnils, parseUtils, stint, tables import ../../status/[status, wallet, threads] import ../../status/wallet/collectibles as status_collectibles import ../../status/libstatus/wallet as status_wallet @@ -25,6 +25,7 @@ QtObject: fastestGasPrice: string defaultGasLimit: string signingPhrase: string + fetchingHistoryState: Table[string, bool] proc delete(self: WalletView) = self.accounts.delete @@ -54,6 +55,7 @@ QtObject: result.fastestGasPrice = "0" result.defaultGasLimit = "21000" result.signingPhrase = "" + result.fetchingHistoryState = initTable[string, bool]() result.setup proc etherscanLinkChanged*(self: WalletView) {.signal.} @@ -115,8 +117,6 @@ QtObject: notify = currentTransactionsChanged proc loadCollectiblesForAccount*(self: WalletView, address: string, currentCollectiblesList: seq[CollectibleList]) - proc loadTransactionsForAccount*(self: WalletView, address: string) - proc currentAccountChanged*(self: WalletView) {.signal.} proc setCurrentAccountByIndex*(self: WalletView, index: int) {.slot.} = @@ -131,10 +131,8 @@ QtObject: # Display currently known collectibles, and get latest from API/Contracts self.setCurrentCollectiblesLists(selectedAccount.collectiblesLists) self.loadCollectiblesForAccount(selectedAccount.address, selectedAccount.collectiblesLists) - - # Display currently known transactions, and get latest transactions from status-go + self.setCurrentTransactions(selectedAccount.transactions) - self.loadTransactionsForAccount(selectedAccount.address) proc getCurrentAccount*(self: WalletView): QVariant {.slot.} = result = newQVariant(self.currentAccount) @@ -390,28 +388,6 @@ QtObject: self.currentCollectiblesLists.setLoadingByType(collectibleType, 1) - - proc loadingTrxHistory*(self: WalletView, isLoading: bool) {.signal.} - - proc loadTransactionsForAccount*(self: WalletView, address: string) {.slot.} = - self.loadingTrxHistory(true) - spawnAndSend(self, "setTrxHistoryResult") do: - $(%*{ - "address": address, - "history": getTransfersByAddress(address) - }) - - proc setTrxHistoryResult(self: WalletView, historyJSON: string) {.slot.} = - let historyData = parseJson(historyJSON) - let transactions = historyData["history"].to(seq[Transaction]); - let address = historyData["address"].getStr - let index = self.accounts.getAccountindexByAddress(address) - if index == -1: return - self.accounts.getAccount(index).transactions = transactions - if address == self.currentAccount.address: - self.setCurrentTransactions(transactions) - self.loadingTrxHistory(false) - proc gasPricePredictionsChanged*(self: WalletView) {.signal.} proc getGasPricePredictions*(self: WalletView) {.slot.} = @@ -462,3 +438,35 @@ QtObject: QtProperty[QVariant] defaultTokenList: read = getDefaultTokenList + proc historyWasFetched*(self: WalletView) {.signal.} + + proc setHistoryFetchState*(self: WalletView, accounts: seq[string], isFetching: bool) = + for acc in accounts: + self.fetchingHistoryState[acc] = isFetching + if not isFetching: self.historyWasFetched() + + proc isFetchingHistory*(self: WalletView, address: string): bool {.slot.} = + if self.fetchingHistoryState.hasKey(address): + return self.fetchingHistoryState[address] + return true + + proc loadingTrxHistory*(self: WalletView, isLoading: bool) {.signal.} + + proc loadTransactionsForAccount*(self: WalletView, address: string) {.slot.} = + self.loadingTrxHistory(true) + spawnAndSend(self, "setTrxHistoryResult") do: + $(%*{ + "address": address, + "history": getTransfersByAddress(address) + }) + + proc setTrxHistoryResult(self: WalletView, historyJSON: string) {.slot.} = + let historyData = parseJson(historyJSON) + let transactions = historyData["history"].to(seq[Transaction]); + let address = historyData["address"].getStr + let index = self.accounts.getAccountindexByAddress(address) + if index == -1: return + self.accounts.getAccount(index).transactions = transactions + if address == self.currentAccount.address: + self.setCurrentTransactions(transactions) + self.loadingTrxHistory(false) diff --git a/ui/app/AppLayouts/Wallet/HistoryTab.qml b/ui/app/AppLayouts/Wallet/HistoryTab.qml index 3f0eaf7644..ad77e9ada1 100644 --- a/ui/app/AppLayouts/Wallet/HistoryTab.qml +++ b/ui/app/AppLayouts/Wallet/HistoryTab.qml @@ -5,6 +5,14 @@ import "../../../imports" import "../../../shared" Item { + function checkIfHistoryIsBeingFetched(){ + if(walletModel.isFetchingHistory(walletModel.currentAccount.address)){ + loadingImg.active = true; + } else { + walletModel.loadTransactionsForAccount(walletModel.currentAccount.address) + } + } + Loader { id: loadingImg active: false @@ -22,6 +30,7 @@ Item { Connections { target: walletModel + onHistoryWasFetched: checkIfHistoryIsBeingFetched() onLoadingTrxHistory: { loadingImg.active = isLoading } diff --git a/ui/app/AppLayouts/Wallet/LeftTab.qml b/ui/app/AppLayouts/Wallet/LeftTab.qml index 9196c3000a..8afb7eee30 100644 --- a/ui/app/AppLayouts/Wallet/LeftTab.qml +++ b/ui/app/AppLayouts/Wallet/LeftTab.qml @@ -14,6 +14,7 @@ Item { } selectedAccount = newIndex walletModel.setCurrentAccountByIndex(newIndex) + walletTabBar.currentIndex = 0; } id: walletInfoContainer diff --git a/ui/app/AppLayouts/Wallet/WalletLayout.qml b/ui/app/AppLayouts/Wallet/WalletLayout.qml index 8f98e8090f..7551c3a687 100644 --- a/ui/app/AppLayouts/Wallet/WalletLayout.qml +++ b/ui/app/AppLayouts/Wallet/WalletLayout.qml @@ -87,9 +87,7 @@ SplitView { anchors.leftMargin: 32 //% "History" btnText: qsTrId("history") - onClicked: { - walletModel.loadTransactionsForAccount(walletModel.currentAccount.address) - } + onClicked: historyTab.checkIfHistoryIsBeingFetched() } } diff --git a/ui/app/AppLayouts/Wallet/components/collectiblesComponents/CollectiblesContent.qml b/ui/app/AppLayouts/Wallet/components/collectiblesComponents/CollectiblesContent.qml index 97df3e76ea..0d48bc8251 100644 --- a/ui/app/AppLayouts/Wallet/components/collectiblesComponents/CollectiblesContent.qml +++ b/ui/app/AppLayouts/Wallet/components/collectiblesComponents/CollectiblesContent.qml @@ -86,6 +86,8 @@ ScrollView { height: root.imageSize z: 1 source: modelData.image + sourceSize.width: width + sourceSize.height: height fillMode: Image.PreserveAspectCrop anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter diff --git a/ui/app/AppLayouts/Wallet/components/collectiblesComponents/CollectiblesModalContent.qml b/ui/app/AppLayouts/Wallet/components/collectiblesComponents/CollectiblesModalContent.qml index 29e878a162..834097e9c8 100644 --- a/ui/app/AppLayouts/Wallet/components/collectiblesComponents/CollectiblesModalContent.qml +++ b/ui/app/AppLayouts/Wallet/components/collectiblesComponents/CollectiblesModalContent.qml @@ -18,6 +18,8 @@ Item { height: 248 anchors.horizontalCenter: parent.horizontalCenter source: root.collectibleImage + sourceSize.width: width + sourceSize.height: height fillMode: Image.PreserveAspectCrop } diff --git a/vendor/DOtherSide b/vendor/DOtherSide index 7d8edc6db2..d663d22df6 160000 --- a/vendor/DOtherSide +++ b/vendor/DOtherSide @@ -1 +1 @@ -Subproject commit 7d8edc6db225057af5592e2f20c7470fac83fbaf +Subproject commit d663d22df625837f329aebd038d2b2e003c4dccb diff --git a/vendor/nim-serialization b/vendor/nim-serialization index 8a013591bd..474bdbf49c 160000 --- a/vendor/nim-serialization +++ b/vendor/nim-serialization @@ -1 +1 @@ -Subproject commit 8a013591bda4c5357154207060e62b5cc1eff6c8 +Subproject commit 474bdbf49cf1634ba504888ad1a1927a2703bd3f diff --git a/vendor/nim-stew b/vendor/nim-stew index 32b86bfd1f..1db43c7234 160000 --- a/vendor/nim-stew +++ b/vendor/nim-stew @@ -1 +1 @@ -Subproject commit 32b86bfd1ff97764e94447675559bf37a4ffb407 +Subproject commit 1db43c7234acb9554e3e80bf2e7b61c4cf0435cf diff --git a/vendor/nimbus-build-system b/vendor/nimbus-build-system index 767c8e0fb4..a8cafce7c0 160000 --- a/vendor/nimbus-build-system +++ b/vendor/nimbus-build-system @@ -1 +1 @@ -Subproject commit 767c8e0fb433da5276c4ac3e61b3360e003536a7 +Subproject commit a8cafce7c0d16c3c5a0d928b4a0e31207d399de0 diff --git a/vendor/nimqml b/vendor/nimqml index 57d6e6459d..d48ed1ea37 160000 --- a/vendor/nimqml +++ b/vendor/nimqml @@ -1 +1 @@ -Subproject commit 57d6e6459daab1d357adafcbf7cb008f5b8969e5 +Subproject commit d48ed1ea37a800793ed756ac5a69628d920b1dc0