From c68a4e0497b7b796fad83dd6e0bba4cb688811e5 Mon Sep 17 00:00:00 2001 From: dreacot Date: Sun, 16 May 2021 23:09:35 +0100 Subject: [PATCH] delay fetching trasnaction until sync has completed --- .../Overview/OverviewViewController.swift | 41 ++++----- .../TransactionsViewController.swift | 84 ++++++++++++++----- 2 files changed, 87 insertions(+), 38 deletions(-) diff --git a/Decred Wallet/Features/Overview/OverviewViewController.swift b/Decred Wallet/Features/Overview/OverviewViewController.swift index 6fc0ddad8..76b8775f9 100644 --- a/Decred Wallet/Features/Overview/OverviewViewController.swift +++ b/Decred Wallet/Features/Overview/OverviewViewController.swift @@ -202,31 +202,33 @@ class OverviewViewController: UIViewController { } func updateRecentActivity() { - // Fetch 3 most recent transactions - guard let transactions = WalletLoader.shared.multiWallet.transactionHistory(offset: 0, count: 3), - !transactions.isEmpty + if SyncManager.shared.isSynced { + // Fetch 3 most recent transactions + guard let transactions = WalletLoader.shared.multiWallet.transactionHistory(offset: 0, count: 3), + !transactions.isEmpty else { self.recentTransactionsTableView.isHidden = true self.showAllTransactionsButton.isHidden = true self.noTransactionsLabelView.superview?.isHidden = false return + } + + if transactions.count == 0 { + self.recentTransactionsTableView.isHidden = true + self.showAllTransactionsButton.isHidden = true + self.noTransactionsLabelView.superview?.isHidden = false + return + } + + self.recentTransactions = transactions + + self.recentTransactionsTableViewHeightContraint.constant = TransactionTableViewCell.height() * CGFloat(self.recentTransactions.count) + self.recentTransactionsTableView.reloadData() + + self.recentTransactionsTableView.isHidden = false + self.showAllTransactionsButton.isHidden = false + self.noTransactionsLabelView.superview?.isHidden = true } - - if transactions.count == 0 { - self.recentTransactionsTableView.isHidden = true - self.showAllTransactionsButton.isHidden = true - self.noTransactionsLabelView.superview?.isHidden = false - return - } - - self.recentTransactions = transactions - - self.recentTransactionsTableViewHeightContraint.constant = TransactionTableViewCell.height() * CGFloat(self.recentTransactions.count) - self.recentTransactionsTableView.reloadData() - - self.recentTransactionsTableView.isHidden = false - self.showAllTransactionsButton.isHidden = false - self.noTransactionsLabelView.superview?.isHidden = true } func updateWalletStatusIndicatorAndLabel() { @@ -609,6 +611,7 @@ extension OverviewViewController: DcrlibwalletSyncProgressListenerProtocol { func onSyncCompleted() { DispatchQueue.main.async { self.updateUI(syncCompletedSuccessfully: true) + self.updateRecentActivity() } } diff --git a/Decred Wallet/Features/Transactions/TransactionsViewController.swift b/Decred Wallet/Features/Transactions/TransactionsViewController.swift index 2553ec218..f41160733 100644 --- a/Decred Wallet/Features/Transactions/TransactionsViewController.swift +++ b/Decred Wallet/Features/Transactions/TransactionsViewController.swift @@ -125,26 +125,28 @@ class TransactionsViewController: UIViewController { } func loadAllTransactions() { - self.allTransactions.removeAll() - self.refreshControl.showLoader(in: self.txTableView) - - defer { - self.refreshControl.endRefreshing() - } - - if let txs = WalletLoader.shared.wallets[self.currentWalletSelectorIndex].transactionHistory(offset: 0), !txs.isEmpty { - self.allTransactions = txs - self.txTableView.backgroundView = nil - self.txTableView.separatorStyle = .singleLine - } else { - self.txTableView.backgroundView = self.noTxsLabel - self.txTableView.separatorStyle = .none + if SyncManager.shared.isSynced { + self.allTransactions.removeAll() + self.refreshControl.showLoader(in: self.txTableView) + + defer { + self.refreshControl.endRefreshing() + } + + if let txs = WalletLoader.shared.wallets[self.currentWalletSelectorIndex].transactionHistory(offset: 0), !txs.isEmpty { + self.allTransactions = txs + self.txTableView.backgroundView = nil + self.txTableView.separatorStyle = .singleLine + } else { + self.txTableView.backgroundView = self.noTxsLabel + self.txTableView.separatorStyle = .none + } + + self.setupTxSortOrderDropDown() + self.setupTxFilterDropDown() + + self.txTableView.reloadData() } - - self.setupTxSortOrderDropDown() - self.setupTxFilterDropDown() - - self.txTableView.reloadData() } func setupTxSortOrderDropDown() { @@ -249,6 +251,50 @@ extension TransactionsViewController: UITableViewDataSource, UITableViewDelegate } } +extension TransactionsViewController: DcrlibwalletSyncProgressListenerProtocol { + func debug(_ debugInfo: DcrlibwalletDebugInfo?) { + + } + + func onAddressDiscoveryProgress(_ addressDiscoveryProgress: DcrlibwalletAddressDiscoveryProgressReport?) { + + } + + func onCFiltersFetchProgress(_ cfiltersFetchProgress: DcrlibwalletCFiltersFetchProgressReport?) { + + } + + func onHeadersFetchProgress(_ headersFetchProgress: DcrlibwalletHeadersFetchProgressReport?) { + + } + + func onHeadersRescanProgress(_ headersRescanProgress: DcrlibwalletHeadersRescanProgressReport?) { + + } + + func onPeerConnectedOrDisconnected(_ numberOfConnectedPeers: Int32) { + + } + + func onSyncCanceled(_ willRestart: Bool) { + + } + + func onSyncCompleted() { + DispatchQueue.main.async { + self.loadAllTransactions() + } + } + + func onSyncEndedWithError(_ err: Error?) { + + } + + func onSyncStarted(_ wasRestarted: Bool) { + + } +} + extension TransactionsViewController: DcrlibwalletTxAndBlockNotificationListenerProtocol { func onBlockAttached(_ walletID: Int, blockHeight: Int32) { let unconfirmedTransactions = self.allTransactions.filter {$0.confirmations <= 2}.count