From b720a611c42146cd5cf00ff36be38c0cdd041337 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 28 Jun 2021 14:43:49 -0400 Subject: [PATCH] fix(wallet): fix loading of initial balances --- src/app/wallet/views/balance.nim | 27 ++++++++++++++++++------- src/app/wallet/views/history.nim | 13 +++++++----- src/status/wallet.nim | 2 +- ui/app/AppLayouts/Wallet/HistoryTab.qml | 12 +++++------ 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/app/wallet/views/balance.nim b/src/app/wallet/views/balance.nim index 023a3142b0..8089aec7b7 100644 --- a/src/app/wallet/views/balance.nim +++ b/src/app/wallet/views/balance.nim @@ -101,14 +101,27 @@ QtObject: if loadTransactions: self.historyView.loadTransactionsForAccount(accountAddress) + proc initBalance(self: BalanceView, acc: WalletAccount, loadTransactions: bool = true) = + let + accountAddress = acc.address + tokenList = acc.assetList.filter(proc(x:Asset): bool = x.address != "").map(proc(x: Asset): string = x.address) + self.initBalances("getAccountBalanceSuccess", accountAddress, tokenList) + if loadTransactions: + self.historyView.loadTransactionsForAccount(accountAddress) + proc initBalance*(self: BalanceView, accountAddress: string, loadTransactions: bool = true) = - echo "initBalance" - #var found = false - #let acc = self.status.wallet.accounts.find(acc => acc.address.toLowerAscii == accountAddress.toLowerAscii, found) - #if not found: - # error "Failed to init balance: could not find account", account=accountAddress - # return - #self.initBalance(acc, loadTransactions) + var found = false + var acc: WalletAccount + for a in self.status.wallet.accounts: + if a.address.toLowerAscii == accountAddress.toLowerAscii: + found = true + acc = a + break + + if not found: + error "Failed to init balance: could not find account", account=accountAddress + return + self.initBalance(acc, loadTransactions) proc getAccountBalanceSuccess*(self: BalanceView, jsonResponse: string) {.slot.} = let jsonObj = jsonResponse.parseJson() diff --git a/src/app/wallet/views/history.nim b/src/app/wallet/views/history.nim index ebb551978b..2a6e976ee8 100644 --- a/src/app/wallet/views/history.nim +++ b/src/app/wallet/views/history.nim @@ -33,8 +33,11 @@ proc loadTransactions*[T](self: T, slot: string, address: string, toBlock: Uint2 let arg = LoadTransactionsTaskArg( tptr: cast[ByteAddress](loadTransactionsTask), vptr: cast[ByteAddress](self.vptr), - slot: slot, address: address, - toBlock: toBlock, limit: limit, loadMore: loadMore + slot: slot, + address: address, + toBlock: toBlock, + limit: limit, + loadMore: loadMore ) self.status.tasks.threadpool.start(arg) @@ -58,10 +61,12 @@ QtObject: proc historyWasFetched*(self: HistoryView) {.signal.} + proc loadingTrxHistoryChanged*(self: HistoryView, isLoading: bool, address: string) {.signal.} + proc setHistoryFetchState*(self: HistoryView, accounts: seq[string], isFetching: bool) = for acc in accounts: self.fetchingHistoryState[acc] = isFetching - if not isFetching: self.historyWasFetched() + self.loadingTrxHistoryChanged(isFetching, acc) proc isFetchingHistory*(self: HistoryView, address: string): bool {.slot.} = if self.fetchingHistoryState.hasKey(address): @@ -71,8 +76,6 @@ QtObject: proc isHistoryFetched*(self: HistoryView, address: string): bool {.slot.} = return self.transactionsView.currentTransactions.rowCount() > 0 - proc loadingTrxHistoryChanged*(self: HistoryView, isLoading: bool, address: string) {.signal.} - proc loadTransactionsForAccount*(self: HistoryView, address: string, toBlock: string = "0x0", limit: int = 20, loadMore: bool = false) {.slot.} = self.loadingTrxHistoryChanged(true, address) let toBlockParsed = stint.fromHex(Uint256, toBlock) diff --git a/src/status/wallet.nim b/src/status/wallet.nim index 4ea74d350f..bb673e9e07 100644 --- a/src/status/wallet.nim +++ b/src/status/wallet.nim @@ -340,7 +340,7 @@ proc addCustomToken*(self: WalletModel, symbol: string, enable: bool, address: s addCustomToken(address, name, symbol, decimals, color) proc getTransfersByAddress*(self: WalletModel, address: string, toBlock: Uint256, limit: int, loadMore: bool): seq[Transaction] = - result = status_wallet.getTransfersByAddress(address, toBlock, limit, loadMore) + result = status_wallet.getTransfersByAddress(address, toBlock, limit, loadMore) proc validateMnemonic*(self: WalletModel, mnemonic: string): string = result = status_wallet.validateMnemonic(mnemonic).parseJSON()["error"].getStr diff --git a/ui/app/AppLayouts/Wallet/HistoryTab.qml b/ui/app/AppLayouts/Wallet/HistoryTab.qml index 63cecdc50e..a7a04e6ba9 100644 --- a/ui/app/AppLayouts/Wallet/HistoryTab.qml +++ b/ui/app/AppLayouts/Wallet/HistoryTab.qml @@ -11,19 +11,19 @@ import "../../../shared/status" Item { property int pageSize: 20 // number of transactions per page property var tokens: { - const count = walletModel.tokensView.defaultTokenList.rowCount() + let count = walletModel.tokensView.defaultTokenList.rowCount() const toks = [] - for (var i = 0; i < count; i++) { + for (let i = 0; i < count; i++) { toks.push({ "address": walletModel.tokensView.defaultTokenList.rowData(i, 'address'), "symbol": walletModel.tokensView.defaultTokenList.rowData(i, 'symbol') }) } - count = walletModel.customTokenList.rowCount() - for (var i = 0; i < count; i++) { + count = walletModel.tokensView.customTokenList.rowCount() + for (let j = 0; j < count; j++) { toks.push({ - "address": walletModel.customTokenList.rowData(i, 'address'), - "symbol": walletModel.customTokenList.rowData(i, 'symbol') + "address": walletModel.customTokenList.rowData(j, 'address'), + "symbol": walletModel.customTokenList.rowData(j, 'symbol') }) } return toks