Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delay fetching transactions until sync has completed #752

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions Decred Wallet/Features/Overview/OverviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.isSyncing {
// 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() {
Expand Down Expand Up @@ -609,6 +611,7 @@ extension OverviewViewController: DcrlibwalletSyncProgressListenerProtocol {
func onSyncCompleted() {
DispatchQueue.main.async {
self.updateUI(syncCompletedSuccessfully: true)
self.updateRecentActivity()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class TransactionsViewController: UIViewController {
self.txTableView.registerCellNib(TransactionTableViewCell.self)

// register for new transactions notifications
try? WalletLoader.shared.multiWallet.add(self, uniqueIdentifier: "\(self)")
let txNotificationListener = self as DcrlibwalletTxAndBlockNotificationListenerProtocol
try? WalletLoader.shared.multiWallet.add(txNotificationListener, uniqueIdentifier: "\(self)")

self.setupWalletSelector()
}
Expand Down Expand Up @@ -125,26 +126,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.isSyncing {
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() {
Expand Down Expand Up @@ -249,6 +252,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
Expand Down