Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #2512: Update Rewards Balance Report fetch #2782

Merged
merged 1 commit into from
Aug 5, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ class TipsDetailViewController: UIViewController {
}

private func loadData() {
_ = getTipsThisMonth().then {
totalBatTips = $0.oneTimeDonation + $0.recurringDonation
getTipsThisMonth { [weak self] report in
guard let self = self else { return }
self.totalBatTips = report.oneTimeDonation + report.recurringDonation
(self.view as? SettingsTableView)?.tableView.reloadData()
}

state.ledger.listOneTimeTips {[weak self] infoList in
state.ledger.listOneTimeTips { [weak self] infoList in
guard let self = self else { return }
infoList.forEach({$0.category = Int32(RewardsType.oneTimeTip.rawValue)})
self.tipsList.append(contentsOf: infoList)
Expand Down Expand Up @@ -163,14 +165,12 @@ extension TipsDetailViewController: UITableViewDataSource, UITableViewDelegate {
}

extension TipsDetailViewController {
fileprivate func getTipsThisMonth() -> BalanceReportInfo {
fileprivate func getTipsThisMonth(_ completion: @escaping (BalanceReportInfo) -> Void) {
let month = Date().currentMonthNumber
let year = Date().currentYear
var report = BalanceReportInfo()
state.ledger.balanceReport(for: ActivityMonth(rawValue: month) ?? .any, year: Int32(year)) {
if let balance = $0 { report = balance }
completion($0 ?? .init())
}
return report
}

func setupLedgerObservers() {
Expand Down
34 changes: 18 additions & 16 deletions BraveRewardsUI/Wallet/RewardsSummaryProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protocol RewardsSummaryProtocol {
var summaryPeriod: String { get }

/// Rows showing different types of earnings, tips etc.
var summaryRows: [RowView] { get }
func summaryRows(_ completion: @escaping ([RowView]) -> Void)

/// A view informing users about contributing to unverified publishers.
func disclaimerLabels(for pendingContributionTotal: Double) -> [LinkLabel]
Expand Down Expand Up @@ -49,33 +49,35 @@ extension RewardsSummaryProtocol {
return "\(now.currentMonthName().uppercased()) \(now.currentYear)"
}

var summaryRows: [RowView] {
func summaryRows(_ completion: @escaping ([RowView]) -> Void) {
let now = Date()
guard let activityMonth = ActivityMonth(rawValue: now.currentMonthNumber) else {
return []
completion([])
return
}

let ledger = state.ledger
var activities: [Activity] = []
ledger.balanceReport(for: activityMonth, year: Int32(now.currentYear)) { balance in
guard let balance = balance else { return }
activities = [
let rows: [RowView] = [
Activity(balance.grants, title: Strings.totalGrantsClaimed, color: BraveUX.adsTintColor),
Activity(balance.earningFromAds, title: Strings.earningFromAds, color: BraveUX.adsTintColor),
Activity(balance.autoContribute, title: Strings.autoContribute, color: BraveUX.autoContributeTintColor),
Activity(balance.oneTimeDonation, title: Strings.oneTimeTips, color: BraveUX.tipsTintColor),
Activity(balance.recurringDonation, title: Strings.monthlyTips, color: BraveUX.tipsTintColor)
].compactMap { $0 }
}
return activities.map {
let bat = $0.value.displayString
let usd = ledger.dollarStringForBATAmount(bat)
return RowView(
title: $0.title,
cryptoValueColor: $0.color,
batValue: bat,
usdDollarValue: usd
)
]
.compactMap { $0 }
.map {
let bat = $0.value.displayString
let usd = ledger.dollarStringForBATAmount(bat)
return RowView(
title: $0.title,
cryptoValueColor: $0.color,
batValue: bat,
usdDollarValue: usd
)
}
completion(rows)
}
}

Expand Down
32 changes: 18 additions & 14 deletions BraveRewardsUI/Wallet/WalletViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ class WalletViewController: UIViewController, RewardsSummaryProtocol {
updateExternalWallet()

rewardsSummaryView.monthYearLabel.text = summaryPeriod
rewardsSummaryView.rows = summaryRows
summaryRows { [weak self] rows in
self?.rewardsSummaryView.rows = rows
}

reloadUIState()
setupPublisherView(publisherSummaryView)
Expand Down Expand Up @@ -719,24 +721,26 @@ extension WalletViewController {
guard let self = self, self.isViewLoaded else {
return
}
let rows = self.summaryRows.map({ row -> RowView in
row.isHidden = true
return row
})
UIView.animate(withDuration: 0.15, animations: {
self.rewardsSummaryView.stackView.arrangedSubviews.forEach({
self.summaryRows { [weak self] rows in
guard let self = self else { return }
rows.forEach {
$0.isHidden = true
$0.alpha = 0
})
}, completion: { _ in
self.rewardsSummaryView.rows = rows
}
UIView.animate(withDuration: 0.15, animations: {
self.rewardsSummaryView.stackView.arrangedSubviews.forEach({
$0.isHidden = false
$0.alpha = 1
$0.isHidden = true
$0.alpha = 0
})
}, completion: { _ in
self.rewardsSummaryView.rows = rows
UIView.animate(withDuration: 0.15, animations: {
self.rewardsSummaryView.stackView.arrangedSubviews.forEach({
$0.isHidden = false
$0.alpha = 1
})
})
})
})
}
}
ledgerObserver.pendingContributionAdded = { [weak self] in
self?.updatePendingContributionsState()
Expand Down