Skip to content

Commit

Permalink
Fix ad notifications received this month should not include transacti…
Browse files Browse the repository at this point in the history
…on count from server

Fixes brave/brave-browser#5119
  • Loading branch information
tmancey authored Jul 23, 2019
1 parent fd55545 commit 33e17f4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,8 @@ void AdsRewards::Update() {
confirmations_->GetNextTokenRedemptionDateInSeconds());
uint64_t next_payment_date_in_seconds = next_payment_date.ToDoubleT();

auto ad_notifications_received_this_month =
payments_->GetTransactionCountForMonth(now);

confirmations_->UpdateAdsRewards(estimated_pending_rewards,
next_payment_date_in_seconds, ad_notifications_received_this_month);
next_payment_date_in_seconds);
}

double AdsRewards::CalculateEstimatedPendingRewards() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ ConfirmationsImpl::ConfirmationsImpl(
unblinded_payment_tokens_(std::make_unique<UnblindedTokens>(this)),
estimated_pending_rewards_(0.0),
next_payment_date_in_seconds_(0),
ad_notifications_received_this_month_(0),
ads_rewards_(std::make_unique<AdsRewards>(this, confirmations_client)),
retry_getting_signed_tokens_timer_id_(0),
refill_tokens_(std::make_unique<RefillTokens>(
Expand Down Expand Up @@ -837,8 +836,7 @@ void ConfirmationsImpl::UpdateAdsRewards(const bool should_refresh) {

void ConfirmationsImpl::UpdateAdsRewards(
const double estimated_pending_rewards,
const uint64_t next_payment_date_in_seconds,
const uint64_t ad_notifications_received_this_month) {
const uint64_t next_payment_date_in_seconds) {
if (!state_has_loaded_) {
// We should not update ads rewards until state has successfully loaded
// otherwise our values will be overwritten
Expand All @@ -847,7 +845,6 @@ void ConfirmationsImpl::UpdateAdsRewards(

estimated_pending_rewards_ = estimated_pending_rewards;
next_payment_date_in_seconds_ = next_payment_date_in_seconds;
ad_notifications_received_this_month_ = ad_notifications_received_this_month;

SaveState();

Expand All @@ -857,13 +854,12 @@ void ConfirmationsImpl::UpdateAdsRewards(
void ConfirmationsImpl::GetTransactionHistory(
OnGetTransactionHistory callback) {
auto unredeemed_transactions = GetUnredeemedTransactions();

double unredeemed_estimated_pending_rewards =
GetEstimatedPendingRewardsForTransactions(unredeemed_transactions);

uint64_t unredeemed_ad_notifications_received_this_month =
GetAdNotificationsReceivedThisMonthForTransactions(
unredeemed_transactions);
auto all_transactions = GetTransactions();
uint64_t ad_notifications_received_this_month =
GetAdNotificationsReceivedThisMonthForTransactions(all_transactions);

auto transactions_info = std::make_unique<TransactionsInfo>();

Expand All @@ -874,8 +870,7 @@ void ConfirmationsImpl::GetTransactionHistory(
next_payment_date_in_seconds_;

transactions_info->ad_notifications_received_this_month =
ad_notifications_received_this_month_ +
unredeemed_ad_notifications_received_this_month;
ad_notifications_received_this_month;

auto to_timestamp_in_seconds = Time::NowInSeconds();
auto transactions = GetTransactionHistory(0, to_timestamp_in_seconds);
Expand All @@ -894,9 +889,6 @@ void ConfirmationsImpl::AddTransactionsToPendingRewards(
estimated_pending_rewards_ +=
GetEstimatedPendingRewardsForTransactions(transactions);

ad_notifications_received_this_month_ +=
GetAdNotificationsReceivedThisMonthForTransactions(transactions);

confirmations_client_->ConfirmationsTransactionHistoryDidChange();
}

Expand All @@ -916,7 +908,7 @@ double ConfirmationsImpl::GetEstimatedPendingRewardsForTransactions(

uint64_t ConfirmationsImpl::GetAdNotificationsReceivedThisMonthForTransactions(
const std::vector<TransactionInfo>& transactions) const {
double ad_notifications_received_this_month = 0.0;
uint64_t ad_notifications_received_this_month = 0;

auto now = base::Time::Now();
base::Time::Exploded now_exploded;
Expand Down Expand Up @@ -956,6 +948,10 @@ std::vector<TransactionInfo> ConfirmationsImpl::GetTransactionHistory(
return transactions;
}

std::vector<TransactionInfo> ConfirmationsImpl::GetTransactions() const {
return transaction_history_;
}

std::vector<TransactionInfo> ConfirmationsImpl::GetUnredeemedTransactions() {
auto count = unblinded_payment_tokens_->Count();
if (count == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ class ConfirmationsImpl : public Confirmations {

void UpdateAdsRewards(
const double estimated_pending_rewards,
const uint64_t next_payment_date_in_seconds,
const uint64_t ad_notifications_received_this_month);
const uint64_t next_payment_date_in_seconds);

// Transaction history
void GetTransactionHistory(
Expand All @@ -70,6 +69,7 @@ class ConfirmationsImpl : public Confirmations {
std::vector<TransactionInfo> GetTransactionHistory(
const uint64_t from_timestamp_in_seconds,
const uint64_t to_timestamp_in_seconds);
std::vector<TransactionInfo> GetTransactions() const;
std::vector<TransactionInfo> GetUnredeemedTransactions();
void AppendTransactionToHistory(
const double estimated_redemption_value,
Expand Down Expand Up @@ -124,7 +124,6 @@ class ConfirmationsImpl : public Confirmations {
// Ads rewards
double estimated_pending_rewards_;
uint64_t next_payment_date_in_seconds_;
uint64_t ad_notifications_received_this_month_;
std::unique_ptr<AdsRewards> ads_rewards_;

// Refill tokens
Expand Down

0 comments on commit 33e17f4

Please sign in to comment.