Skip to content

Commit

Permalink
delay fetching trasnaction until sync has completed
Browse files Browse the repository at this point in the history
  • Loading branch information
dreacot committed May 16, 2021
1 parent 68ff2e6 commit c68a4e0
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 38 deletions.
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.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() {
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 @@ -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() {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c68a4e0

Please sign in to comment.