Skip to content

Commit

Permalink
Fixes estimated Pending Rewards value decreased unexpectedly - follow…
Browse files Browse the repository at this point in the history
… up to #16678
  • Loading branch information
tmancey committed Jul 8, 2021
1 parent 2dececc commit bd06342
Show file tree
Hide file tree
Showing 44 changed files with 314 additions and 1,169 deletions.
1 change: 0 additions & 1 deletion browser/extensions/api/brave_rewards_api.cc
Expand Up @@ -1103,7 +1103,6 @@ BraveRewardsGetAdsAccountStatementFunction::Run() {

void BraveRewardsGetAdsAccountStatementFunction::OnGetAdsAccountStatement(
const bool success,
const double estimated_pending_rewards,
const int64_t next_payment_date,
const int ads_received_this_month,
const double earnings_this_month,
Expand Down
1 change: 0 additions & 1 deletion browser/extensions/api/brave_rewards_api.h
Expand Up @@ -400,7 +400,6 @@ class BraveRewardsGetAdsAccountStatementFunction : public ExtensionFunction {

private:
void OnGetAdsAccountStatement(const bool success,
const double estimated_pending_rewards,
const int64_t next_payment_date,
const int ads_received_this_month,
const double earnings_this_month,
Expand Down
2 changes: 0 additions & 2 deletions browser/ui/webui/brave_rewards_page_ui.cc
Expand Up @@ -126,7 +126,6 @@ class RewardsDOMHandler : public WebUIMessageHandler,
void GetExcludedSites(const base::ListValue* args);

void OnGetStatement(const bool success,
const double estimated_pending_rewards,
const int64_t next_payment_date,
const int ads_received_this_month,
const double earnings_this_month,
Expand Down Expand Up @@ -1433,7 +1432,6 @@ void RewardsDOMHandler::GetStatement(
}

void RewardsDOMHandler::OnGetStatement(const bool success,
const double estimated_pending_rewards,
const int64_t next_payment_date,
const int ads_received_this_month,
const double earnings_this_month,
Expand Down
2 changes: 2 additions & 0 deletions components/brave_ads/browser/ads_service.cc
Expand Up @@ -67,6 +67,8 @@ void AdsService::RegisterProfilePrefs(
registry->RegisterStringPref(ads::prefs::kEpsilonGreedyBanditEligibleSegments,
"");

registry->RegisterDoublePref(ads::prefs::kUnreconciledTransactions, 0.0);

registry->RegisterBooleanPref(ads::prefs::kHasMigratedConversionState, false);
}

Expand Down
1 change: 0 additions & 1 deletion components/brave_ads/browser/ads_service.h
Expand Up @@ -54,7 +54,6 @@ using OnGetInlineContentAdCallback = base::OnceCallback<
void(const bool, const std::string&, const base::DictionaryValue&)>;

using GetAccountStatementCallback = base::OnceCallback<void(const bool,
const double,
const int64_t,
const int,
const double,
Expand Down
9 changes: 4 additions & 5 deletions components/brave_ads/browser/ads_service_impl.cc
Expand Up @@ -427,7 +427,7 @@ void AdsServiceImpl::GetAdsHistory(const uint64_t from_timestamp,

void AdsServiceImpl::GetAccountStatement(GetAccountStatementCallback callback) {
if (!connected()) {
std::move(callback).Run(/* success */ false, 0.0, 0, 0, 0.0, 0.0);
std::move(callback).Run(/* success */ false, 0, 0, 0.0, 0.0);
return;
}

Expand Down Expand Up @@ -1304,17 +1304,16 @@ void AdsServiceImpl::OnGetAccountStatement(GetAccountStatementCallback callback,
const bool success,
const std::string& json) {
if (!success) {
std::move(callback).Run(success, 0.0, 0, 0, 0.0, 0.0);
std::move(callback).Run(success, 0, 0, 0.0, 0.0);
return;
}

ads::StatementInfo statement;
statement.FromJson(json);

std::move(callback).Run(
success, statement.estimated_pending_rewards, statement.next_payment_date,
statement.ads_received_this_month, statement.earnings_this_month,
statement.earnings_last_month);
success, statement.next_payment_date, statement.ads_received_this_month,
statement.earnings_this_month, statement.earnings_last_month);
}

void AdsServiceImpl::OnRemoveAllHistory(const int32_t result) {
Expand Down
1 change: 0 additions & 1 deletion components/brave_ads/test/BUILD.gn
Expand Up @@ -13,7 +13,6 @@ source_set("brave_ads_unit_tests") {
if (brave_ads_enabled) {
sources = [
"//brave/vendor/bat-native-ads/src/bat/ads/ad_event_history_unittest.cc",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/account/ad_rewards/ad_grants/ad_grants_unittest.cc",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/account/ad_rewards/ad_rewards_delegate_mock.cc",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/account/ad_rewards/ad_rewards_delegate_mock.h",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/account/ad_rewards/ad_rewards_test.cc",
Expand Down
2 changes: 1 addition & 1 deletion ios/browser/api/ads/brave_ads.mm
Expand Up @@ -681,7 +681,7 @@ - (void)detailsForCurrentCycle:(void (^)(NSInteger adsReceived,
nextPaymentDate =
[NSDate dateWithTimeIntervalSince1970:list.next_payment_date];
}
completion(list.ads_received_this_month, list.estimated_pending_rewards,
completion(list.ads_received_this_month, list.earnings_this_month,
nextPaymentDate);
});
}
Expand Down
4 changes: 0 additions & 4 deletions vendor/bat-native-ads/BUILD.gn
Expand Up @@ -106,10 +106,6 @@ source_set("ads") {
"src/bat/ads/internal/account/account.cc",
"src/bat/ads/internal/account/account.h",
"src/bat/ads/internal/account/account_observer.h",
"src/bat/ads/internal/account/ad_rewards/ad_grants/ad_grants.cc",
"src/bat/ads/internal/account/ad_rewards/ad_grants/ad_grants.h",
"src/bat/ads/internal/account/ad_rewards/ad_grants/ad_grants_url_request_builder.cc",
"src/bat/ads/internal/account/ad_rewards/ad_grants/ad_grants_url_request_builder.h",
"src/bat/ads/internal/account/ad_rewards/ad_rewards.cc",
"src/bat/ads/internal/account/ad_rewards/ad_rewards.h",
"src/bat/ads/internal/account/ad_rewards/ad_rewards_delegate.h",
Expand Down
4 changes: 1 addition & 3 deletions vendor/bat-native-ads/data/test/confirmations.json
@@ -1,14 +1,12 @@
{
"ads_rewards": {
"grants_balance": 4.21,
"payments": [
{
"balance": 48.0,
"month": "2021-04",
"transaction_count": "16"
}
],
"unreconciled_estimated_pending_rewards": 0
]
},
"catalog_issuers": {
},
Expand Down
@@ -1,6 +1,5 @@
{
"ads_rewards": {
"grants_balance": 40.355,
"payments": [
{
"balance": 0.6075,
Expand Down Expand Up @@ -47,8 +46,7 @@
"month": "2020-09",
"transaction_count": "93"
}
],
"unreconciled_estimated_pending_rewards": 0.41750000000000015
]
},
"catalog_issuers": {
},
Expand Down
@@ -1,14 +1,12 @@
{
"ads_rewards": {
"grants_balance": 4.21,
"payments": [
{
"balance": 48.0,
"month": "2021-04",
"transaction_count": "16"
}
],
"unreconciled_estimated_pending_rewards": 0
]
},
"catalog_issuers": {
"issuers": [
Expand Down
6 changes: 3 additions & 3 deletions vendor/bat-native-ads/include/bat/ads/ads.h
Expand Up @@ -208,9 +208,9 @@ class ADS_EXPORT Ads {
const uint64_t to_timestamp) = 0;

// Should be called to get the statement of accounts. The callback takes one
// argument - |StatementInfo| which contains estimated pending rewards, next
// payment date, ads received this month, pending rewards, cleared
// transactions and uncleared transactions
// argument - |StatementInfo| which contains next payment date, ads received
// this month, earnings this month, earnings last month, cleared transactions
// and uncleared transactions
virtual void GetAccountStatement(GetAccountStatementCallback callback) = 0;

// Should be called to indicate interest in the specified ad. This is a
Expand Down
2 changes: 2 additions & 0 deletions vendor/bat-native-ads/include/bat/ads/pref_names.h
Expand Up @@ -37,6 +37,8 @@ extern const char kCatalogLastUpdated[];
extern const char kEpsilonGreedyBanditArms[];
extern const char kEpsilonGreedyBanditEligibleSegments[];

extern const char kUnreconciledTransactions[];

extern const char kHasMigratedConversionState[];

} // namespace prefs
Expand Down
12 changes: 3 additions & 9 deletions vendor/bat-native-ads/include/bat/ads/statement_info.h
Expand Up @@ -26,18 +26,14 @@ struct ADS_EXPORT StatementInfo {
std::string ToJson() const;
bool FromJson(const std::string& json);

double estimated_pending_rewards = 0.0;
int64_t next_payment_date = 0;
int ads_received_this_month = 0;
double earnings_this_month = 0.0;
double earnings_last_month = 0.0;
TransactionList transactions;
TransactionList cleared_transactions;
TransactionList uncleared_transactions;

private:
double GetEstimatedPendingRewardsFromDictionary(
base::DictionaryValue* dictionary) const;

uint64_t GetNextPaymentDateFromDictionary(
base::DictionaryValue* dictionary) const;

Expand All @@ -46,14 +42,12 @@ struct ADS_EXPORT StatementInfo {

double GetEarningsThisMonthFromDictionary(
base::DictionaryValue* dictionary) const;

double GetEarningsLastMonthFromDictionary(
base::DictionaryValue* dictionary) const;

base::Value GetTransactionsAsList() const;
TransactionList GetTransactionsFromDictionary(
base::Value GetClearedTransactionsAsList() const;
TransactionList GetClearedTransactionsFromDictionary(
base::DictionaryValue* dictionary) const;

base::Value GetUnclearedTransactionsAsList() const;
TransactionList GetUnclearedTransactionsFromDictionary(
base::DictionaryValue* dictionary) const;
Expand Down
13 changes: 3 additions & 10 deletions vendor/bat-native-ads/src/bat/ads/internal/account/account.cc
Expand Up @@ -9,7 +9,6 @@
#include "bat/ads/internal/account/ad_rewards/ad_rewards_util.h"
#include "bat/ads/internal/account/confirmations/confirmation_info.h"
#include "bat/ads/internal/account/confirmations/confirmations.h"
#include "bat/ads/internal/account/confirmations/confirmations_state.h"
#include "bat/ads/internal/account/statement/statement.h"
#include "bat/ads/internal/account/transactions/transactions.h"
#include "bat/ads/internal/account/wallet/wallet.h"
Expand Down Expand Up @@ -191,18 +190,12 @@ void Account::OnDidReconcileAdRewards() {
NotifyAdRewardsChanged();
}

void Account::OnDidRedeemUnblindedPaymentTokens() {
void Account::OnDidRedeemUnblindedPaymentTokens(
const privacy::UnblindedTokenList unblinded_tokens) {
BLOG(1, "Successfully redeemed unblinded payment tokens");

if (ConfirmationsState::Get()->get_unblinded_payment_tokens()->IsEmpty()) {
return;
}

const TransactionList transactions = transactions::GetUncleared();
ad_rewards_->SetUnreconciledTransactions(transactions);

ConfirmationsState::Get()->get_unblinded_payment_tokens()->RemoveAllTokens();
ConfirmationsState::Get()->Save();
ad_rewards_->AppendUnreconciledTransactions(transactions);

Reconcile();
}
Expand Down
3 changes: 2 additions & 1 deletion vendor/bat-native-ads/src/bat/ads/internal/account/account.h
Expand Up @@ -92,7 +92,8 @@ class Account : public AdRewardsDelegate,
void OnConfirmAdFailed(const ConfirmationInfo& confirmation) override;

// RedeemUnblindedPaymentTokensDelegate implementation
void OnDidRedeemUnblindedPaymentTokens() override;
void OnDidRedeemUnblindedPaymentTokens(
const privacy::UnblindedTokenList unblinded_tokens) override;
void OnFailedToRedeemUnblindedPaymentTokens() override;
void OnDidRetryRedeemingUnblindedPaymentTokens() override;
};
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit bd06342

Please sign in to comment.