From a1e9855dea362e99433f2a5c9dddf5dca93d28d8 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Thu, 26 Sep 2019 10:06:45 -0700 Subject: [PATCH] AC verified change Resolves https://github.com/brave/brave-browser/issues/6228 --- .storybook/locale.ts | 5 +- browser/ui/webui/brave_webui_source.cc | 4 +- .../browser/rewards_service_browsertest.cc | 109 ++++++++--- .../browser/rewards_service_impl.cc | 17 +- .../browser/rewards_service_impl.h | 5 +- .../page/components/contributeBox.tsx | 19 +- .../ui/components/modalContribute/index.tsx | 3 - .../resources/brave_components_strings.grd | 10 +- .../internal/contribution/contribution.cc | 172 ++++-------------- .../internal/contribution/contribution.h | 29 +-- .../contribution/contribution_unittest.cc | 12 +- 11 files changed, 170 insertions(+), 215 deletions(-) diff --git a/.storybook/locale.ts b/.storybook/locale.ts index 6931ad1a5279..b6920eb547df 100644 --- a/.storybook/locale.ts +++ b/.storybook/locale.ts @@ -91,7 +91,7 @@ const locale: Record = { enableRewards: 'Enable Brave Rewards', enableTips: 'Enable Tips', excludeSite: 'Exclude this site', - excludedSites: 'Excluded Sites', + excludedSites: 'Sites Excluded', excludedSitesText: 'Sites excluded from Auto-Contributions:', expiresOn: 'expires on', firstTipDateText: 'Your first monthly tip will be sent on:', @@ -185,7 +185,6 @@ const locale: Record = { rewardsContribute: 'Auto-Contribute', rewardsContributeAttention: 'Attention', rewardsContributeAttentionScore: 'Attention', - rewardsContributeText1: 'You’re currently supporting', rewardsExcludedText1: 'You\'ve excluded', rewardsExcludedText2: 'sites from Auto-Contribute.', rewardsOffText1: 'Do you know that you’ve been paying for the web content with your data for the digital ads? You didn’t have a voice in it and worse, you’re exposed to privacy and security risks.', @@ -233,7 +232,7 @@ const locale: Record = { siteBannerConnectedText: 'This creator has not yet signed up to receive contributions from Brave users. Your browser will keep trying to contribute until they verify, or until 90 days have passed.', sites: 'sites', tellOthers: 'Tell others about your tip.', - supportedSites: 'Supported Sites', + supportedSites: 'Sites viewed', thankYou: 'Thank You!', termsOfService: 'Terms of Service', optOutTooltip: 'You will no longer receive\nads from this category', diff --git a/browser/ui/webui/brave_webui_source.cc b/browser/ui/webui/brave_webui_source.cc index a5a4be7e9c20..610a86caa208 100644 --- a/browser/ui/webui/brave_webui_source.cc +++ b/browser/ui/webui/brave_webui_source.cc @@ -255,7 +255,7 @@ void CustomizeWebUIHTMLSource(const std::string &name, { "contributionMinTime", IDS_BRAVE_REWARDS_LOCAL_CONTR_MIN_TIME }, { "contributionMinVisits", IDS_BRAVE_REWARDS_LOCAL_CONTR_MIN_VISITS }, { "contributionAllowed", IDS_BRAVE_REWARDS_LOCAL_CONTR_ALLOWED }, - { "contributionNonVerified", IDS_BRAVE_REWARDS_LOCAL_CONTR_ALLOW_NON_VERIFIED }, // NOLINT + { "contributionShowNonVerified", IDS_BRAVE_REWARDS_LOCAL_CONTR_SHOW_NON_VERIFIED }, // NOLINT { "contributionVideos", IDS_BRAVE_REWARDS_LOCAL_CONTR_ALLOW_VIDEOS }, { "contributionVisit1", IDS_BRAVE_REWARDS_LOCAL_CONTR_VISIT_1 }, { "contributionVisit5", IDS_BRAVE_REWARDS_LOCAL_CONTR_VISIT_5 }, @@ -263,6 +263,7 @@ void CustomizeWebUIHTMLSource(const std::string &name, { "contributionTime5", IDS_BRAVE_REWARDS_LOCAL_CONTR_TIME_5 }, { "contributionTime8", IDS_BRAVE_REWARDS_LOCAL_CONTR_TIME_8 }, { "contributionTime60", IDS_BRAVE_REWARDS_LOCAL_CONTR_TIME_60 }, + { "contributionUpTo", IDS_BRAVE_REWARDS_LOCAL_CONTR_UP_TO }, { "deviceOffline", IDS_BRAVE_REWARDS_LOCAL_DEVICE_OFFLINE }, { "donationTitle", IDS_BRAVE_REWARDS_LOCAL_DONAT_TITLE }, @@ -474,7 +475,6 @@ void CustomizeWebUIHTMLSource(const std::string &name, { "rewardsContribute", IDS_BRAVE_UI_REWARDS_CONTRIBUTE }, { "rewardsContributeAttention", IDS_BRAVE_UI_REWARDS_CONTRIBUTE_ATTENTION }, // NOLINT { "rewardsContributeAttentionScore", IDS_BRAVE_UI_REWARDS_CONTRIBUTE_ATTENTION_SCORE }, // NOLINT - { "rewardsContributeText1", IDS_BRAVE_UI_REWARDS_CONTRIBUTE_TEXT1 }, { "rewardsOffText2", IDS_BRAVE_UI_REWARDS_OFF_TEXT2 }, { "rewardsOffText3", IDS_BRAVE_UI_REWARDS_OFF_TEXT3 }, { "rewardsOffText4", IDS_BRAVE_UI_REWARDS_OFF_TEXT4 }, diff --git a/components/brave_rewards/browser/rewards_service_browsertest.cc b/components/brave_rewards/browser/rewards_service_browsertest.cc index b9732cb51844..536823a5e1b6 100644 --- a/components/brave_rewards/browser/rewards_service_browsertest.cc +++ b/components/brave_rewards/browser/rewards_service_browsertest.cc @@ -2041,7 +2041,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, } IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, - InsufficientNotificationForVerifiedsZeroAmountZeroPublishers) { + InsufficientNotificationForZeroAmountZeroPublishers) { rewards_service_->GetNotificationService()->AddObserver(this); EnableRewards(); CheckInsufficientFundsForTesting(); @@ -2051,7 +2051,9 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, if (notifications.empty()) { SUCCEED(); + return; } + bool notification_shown = false; for (const auto& notification : notifications) { if (notification.second.type_ == @@ -2068,13 +2070,10 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, } IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, - InsufficientNotificationForVerifiedsDefaultAmount) { + InsufficientNotificationForACNotEnoughFunds) { rewards_service_->AddObserver(this); rewards_service_->GetNotificationService()->AddObserver(this); EnableRewards(); - // Claim grant using panel - const bool use_panel = true; - ClaimGrant(use_panel); // Visit publishers const bool verified = true; @@ -2091,7 +2090,9 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, if (notifications.empty()) { SUCCEED(); + return; } + bool notification_shown = false; for (const auto& notification : notifications) { if (notification.second.type_ == @@ -2108,32 +2109,31 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, } IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, - InsufficientNotificationForVerifiedsSufficientAmount) { + InsufficientNotificationForInsufficientAmount) { rewards_service_->AddObserver(this); rewards_service_->GetNotificationService()->AddObserver(this); - EnableRewards(); // Claim grant using panel const bool use_panel = true; ClaimGrant(use_panel); - // Visit publishers const bool verified = true; - while (!last_publisher_added_) { - VisitPublisher("duckduckgo.com", verified); - VisitPublisher("bumpsmack.com", verified); - VisitPublisher("brave.com", !verified, true); - } + VisitPublisher("duckduckgo.com", verified); + rewards_service_->OnTip("duckduckgo.com", 20, true); - rewards_service_->SetContributionAmount(40.0); + VisitPublisher("brave.com", !verified); + rewards_service_->OnTip("brave.com", 50, true); CheckInsufficientFundsForTesting(); WaitForInsufficientFundsNotification(); const brave_rewards::RewardsNotificationService::RewardsNotificationsMap& notifications = rewards_service_->GetAllNotifications(); + if (notifications.empty()) { SUCCEED(); + return; } + bool notification_shown = false; for (const auto& notification : notifications) { if (notification.second.type_ == @@ -2150,7 +2150,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, } IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, - InsufficientNotificationForVerifiedsInsufficientAmount) { + InsufficientNotificationForVerifiedInsufficientAmount) { rewards_service_->AddObserver(this); rewards_service_->GetNotificationService()->AddObserver(this); EnableRewards(); @@ -2158,23 +2158,23 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, const bool use_panel = true; ClaimGrant(use_panel); - // Visit publishers const bool verified = true; - while (!last_publisher_added_) { - VisitPublisher("duckduckgo.com", verified); - VisitPublisher("bumpsmack.com", verified); - VisitPublisher("brave.com", !verified, true); - } - rewards_service_->SetContributionAmount(100.0); + VisitPublisher("duckduckgo.com", verified); + rewards_service_->OnTip("duckduckgo.com", 50, true); + + VisitPublisher("brave.com", !verified); + rewards_service_->OnTip("brave.com", 50, true); - rewards_service_->CheckInsufficientFundsForTesting(); + CheckInsufficientFundsForTesting(); WaitForInsufficientFundsNotification(); const brave_rewards::RewardsNotificationService::RewardsNotificationsMap& notifications = rewards_service_->GetAllNotifications(); if (notifications.empty()) { FAIL() << "Should see Insufficient Funds notification"; + return; } + bool notification_shown = false; for (const auto& notification : notifications) { if (notification.second.type_ == @@ -2186,7 +2186,6 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, } EXPECT_TRUE(notification_shown); - // Stop observing the Rewards service rewards_service_->RemoveObserver(this); } @@ -2540,3 +2539,65 @@ IN_PROC_BROWSER_TEST_F( // Stop observing the Rewards service rewards_service_->RemoveObserver(this); } + +IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, + RecurringAndPartialAutoContribution) { + // Observe the Rewards service + rewards_service_->AddObserver(this); + + // Enable Rewards + EnableRewards(); + + // Claim grant using panel (30 BAT) + const bool use_panel = true; + ClaimGrant(use_panel); + + // Visit verified publisher + const bool verified = true; + VisitPublisher("duckduckgo.com", verified); + VisitPublisher("brave.com", !verified); + + // Tip publisher + rewards_service_->OnTip("duckduckgo.com", 25, true); + + // Trigger contribution process + rewards_service()->StartMonthlyContributionForTest(); + + // Wait for reconciliation to complete + WaitForTipReconcileCompleted(); + ASSERT_EQ(tip_reconcile_status_, ledger::Result::LEDGER_OK); + + // Wait for reconciliation to complete successfully + WaitForACReconcileCompleted(); + ASSERT_EQ(ac_reconcile_status_, ledger::Result::LEDGER_OK); + + // Make sure that balance is updated correctly + { + content::EvalJsResult js_result = EvalJs( + contents(), + "const delay = t => new Promise(resolve => setTimeout(resolve, t));" + "delay(1000).then(() => " + " " + "document.querySelector(\"[data-test-id='balance']\").innerText);", + content::EXECUTE_SCRIPT_DEFAULT_OPTIONS, + content::ISOLATED_WORLD_ID_CONTENT_END); + EXPECT_NE(js_result.ExtractString().find(GetBalance() + " BAT"), + std::string::npos); + } + + // Check that summary table shows the appropriate contribution + { + content::EvalJsResult js_result = EvalJs( + contents(), + "const delay = t => new Promise(resolve => setTimeout(resolve, t));" + "delay(0).then(() => " + " document.querySelector(\"[color='contribute']\").innerText);", + content::EXECUTE_SCRIPT_DEFAULT_OPTIONS, + content::ISOLATED_WORLD_ID_CONTENT_END); + EXPECT_NE(js_result.ExtractString().find("-5.0BAT"), + std::string::npos); + } + + // Stop observing the Rewards service + rewards_service_->RemoveObserver(this); +} diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index a63be6197f26..987e69601149 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -2770,7 +2770,18 @@ void RewardsServiceImpl::MaybeShowNotificationAddFunds() { void RewardsServiceImpl::MaybeShowNotificationAddFundsForTesting( base::OnceCallback callback) { - bat_ledger_->HasSufficientBalanceToReconcile(std::move(callback)); + bat_ledger_->HasSufficientBalanceToReconcile( + base::BindOnce( + &RewardsServiceImpl::OnMaybeShowNotificationAddFundsForTesting, + AsWeakPtr(), + std::move(callback))); +} + +void RewardsServiceImpl::OnMaybeShowNotificationAddFundsForTesting( + base::OnceCallback callback, + const bool sufficient) { + ShowNotificationAddFunds(sufficient); + std::move(callback).Run(sufficient); } bool RewardsServiceImpl::ShouldShowNotificationAddFunds() const { @@ -2986,10 +2997,6 @@ void RewardsServiceImpl::StartMonthlyContributionForTest() { bat_ledger_->StartMonthlyContribution(); } -void RewardsServiceImpl::CheckInsufficientFundsForTesting() { - MaybeShowNotificationAddFunds(); -} - void RewardsServiceImpl::GetProduction(const GetProductionCallback& callback) { bat_ledger_service_->GetProduction(callback); } diff --git a/components/brave_rewards/browser/rewards_service_impl.h b/components/brave_rewards/browser/rewards_service_impl.h index 4324a6416ad7..bd9ab61ab2fa 100644 --- a/components/brave_rewards/browser/rewards_service_impl.h +++ b/components/brave_rewards/browser/rewards_service_impl.h @@ -290,7 +290,6 @@ class RewardsServiceImpl : public RewardsService, // Testing methods void SetLedgerEnvForTesting(); void StartMonthlyContributionForTest(); - void CheckInsufficientFundsForTesting(); void MaybeShowNotificationAddFundsForTesting( base::OnceCallback callback); @@ -432,6 +431,10 @@ class RewardsServiceImpl : public RewardsService, bool ShouldShowNotificationAddFunds() const; void ShowNotificationAddFunds(bool sufficient); + void OnMaybeShowNotificationAddFundsForTesting( + base::OnceCallback callback, + const bool result); + void MaybeShowNotificationTipsPaid(); void ShowNotificationTipsPaid(bool ac_enabled); diff --git a/components/brave_rewards/resources/page/components/contributeBox.tsx b/components/brave_rewards/resources/page/components/contributeBox.tsx index 47af3cf3a5c3..8d7521549840 100644 --- a/components/brave_rewards/resources/page/components/contributeBox.tsx +++ b/components/brave_rewards/resources/page/components/contributeBox.tsx @@ -205,7 +205,7 @@ class ContributeBox extends React.Component { multiple={true} onChange={this.onCheckSettingChange} > -
{getLocale('contributionNonVerified')}
+
{getLocale('contributionShowNonVerified')}
{getLocale('contributionVideos')}
@@ -270,15 +270,15 @@ class ContributeBox extends React.Component { floating={true} onChange={this.onSelectSettingChange.bind(this, 'contributionMonthly')} value={parseFloat((contributionMonthly.toString() || '0')).toFixed(1)} + showAllContents={true} > { monthlyList.map((choice: MonthlyChoice) => { - return
- -
+ return ( +
+ {getLocale('contributionUpTo')} +
+ ) }) } @@ -289,10 +289,7 @@ class ContributeBox extends React.Component { - {getLocale('total')}   + { return ( <> - - {getLocale('rewardsContributeText1')} {numSites} {getLocale('sites')}. - Ads Earn tokens by viewing ads in Brave. Ads presented are based on your interests, as inferred from your browsing behavior. No personal data or browsing history ever leaves your browser. Auto-Contribute - An automatic way to support publishers and content creators. Set a monthly payment and browse normally. The sites you visit receive your contributions automatically, based on your attention as measured by Brave. + An automatic way to support publishers and content creators. Set a monthly payment and browse normally. The Brave Verified sites you visit will receive your contributions automatically, based on your attention as measured by Brave. Estimated pending rewards Next payment date Ad notifications received this month @@ -250,7 +250,7 @@ Minimum page time before logging a visit Minimum visits for publisher relevancy What should be allowed? - Allow contribution to non-verified sites + Only show verified sites in Auto-Contribute list Allow contribution to videos 1 visit 5 visits @@ -258,6 +258,7 @@ 5 seconds 8 seconds 1 minute + Up to Enable content-level tips on these sites YouTube Reddit @@ -490,7 +491,6 @@ Auto-Contribute Attention Attention - You’re currently supporting without your consent. Today, Brave welcomes you to the new internet. One where your time is valued, your personal data is kept private, and you actually get paid for your attention. @@ -578,12 +578,12 @@ No pending contributions… Remove All - Excluded Sites + Sites Excluded Restore this site You've excluded sites from Auto-Contribute. Show All - Supported Sites + Sites viewed Brave Ads Rewards! Your rewards grant from Brave Ads is on its way. diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.cc index ea65e3855b6b..4671e6960a7d 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.cc @@ -71,87 +71,47 @@ void Contribution::HasSufficientBalance( } void Contribution::OnSufficientBalanceWallet( - ledger::Result result, + const ledger::Result result, ledger::BalancePtr properties, ledger::HasSufficientBalanceToReconcileCallback callback) { - if (result == ledger::Result::LEDGER_OK && properties) { - auto filter = ledger_->CreateActivityFilter( - std::string(), - ledger::ExcludeFilter::FILTER_ALL_EXCEPT_EXCLUDED, - true, - ledger_->GetReconcileStamp(), - ledger_->GetPublisherAllowNonVerified(), - ledger_->GetPublisherMinVisits()); - ledger_->GetActivityInfoList( - 0, - 0, - std::move(filter), - std::bind(&Contribution::GetVerifiedAutoAmount, - this, - _1, - _2, - properties->total, - callback)); - } -} - -void Contribution::GetVerifiedAutoAmount( - const ledger::PublisherInfoList& publisher_list, - uint32_t record, - double balance, - ledger::HasSufficientBalanceToReconcileCallback callback) { - double ac_amount = ledger_->GetContributionAmount(); - double total_reconcile_amount(GetAmountFromVerifiedAuto( - publisher_list, ac_amount)); - if (balance < total_reconcile_amount && !publisher_list.empty()) { - callback(false); + if (result != ledger::Result::LEDGER_OK || !properties) { return; } - ledger_->GetRecurringTips( - std::bind(&Contribution::GetVerifiedRecurringAmount, - this, - _1, - _2, - balance, - total_reconcile_amount, - callback)); -} -double Contribution::GetAmountFromVerifiedAuto( - const ledger::PublisherInfoList& publisher_list, - double ac_amount) { - double verified_bat = 0.0; - for (const auto& publisher : publisher_list) { - const auto add = ledger_->IsPublisherConnectedOrVerified(publisher->status); - if (add) { - verified_bat += (publisher->weight / 100.0) * ac_amount; - } - } - return verified_bat; + auto tips_callback = + std::bind(&Contribution::OnHasSufficientBalance, + this, + _1, + _2, + properties->total, + callback); + + ledger_->GetRecurringTips(tips_callback); } -void Contribution::GetVerifiedRecurringAmount( +void Contribution::OnHasSufficientBalance( const ledger::PublisherInfoList& publisher_list, - uint32_t record, - double balance, - double total_reconcile_amount, + const uint32_t record, + const double balance, ledger::HasSufficientBalanceToReconcileCallback callback) { if (publisher_list.empty()) { callback(true); return; } - total_reconcile_amount += GetAmountFromVerifiedRecurring(publisher_list); - callback(balance >= total_reconcile_amount); + + const auto total = GetTotalFromRecurringVerified(publisher_list); + callback(balance >= total); } // static -double Contribution::GetAmountFromVerifiedRecurring( +double Contribution::GetTotalFromRecurringVerified( const ledger::PublisherInfoList& publisher_list) { double total_recurring_amount = 0.0; for (const auto& publisher : publisher_list) { if (publisher->id.empty()) { continue; } + if (publisher->status == ledger::PublisherStatus::VERIFIED) { total_recurring_amount += publisher->weight; } @@ -159,61 +119,6 @@ double Contribution::GetAmountFromVerifiedRecurring( return total_recurring_amount; } - - -ledger::PublisherInfoList Contribution::GetVerifiedListAuto( - const ledger::PublisherInfoList& list, - double* budget) { - ledger::PublisherInfoList verified; - ledger::PublisherInfoList non_verified_temp; - ledger::PendingContributionList non_verified; - - double verified_total = 0.0; - double ac_amount = ledger_->GetContributionAmount(); - - for (const auto& publisher : list) { - if (publisher->percent == 0) { - continue; - } - - const auto add = ledger_->IsPublisherConnectedOrVerified(publisher->status); - if (add) { - verified.push_back(publisher->Clone()); - verified_total += publisher->weight; - } else { - non_verified_temp.push_back(publisher->Clone()); - } - } - - // verified budget - *budget += (verified_total / 100) * ac_amount; - - // verified publishers - for (auto& publisher : verified) { - publisher->weight = (publisher->weight / verified_total) * 100; - publisher->percent = static_cast(publisher->weight); - } - - // non-verified publishers - for (const auto& publisher : non_verified_temp) { - auto contribution = ledger::PendingContribution::New(); - contribution->amount = (publisher->weight / 100) * ac_amount; - contribution->publisher_key = publisher->id; - contribution->viewing_id = ""; - contribution->type = ledger::RewardsType::AUTO_CONTRIBUTE; - - non_verified.push_back(std::move(contribution)); - } - - if (non_verified.size() > 0) { - ledger_->SaveUnverifiedContribution( - std::move(non_verified), - [](const ledger::Result _){}); - } - - return verified; -} - ledger::PublisherInfoList Contribution::GetVerifiedListRecurring( const ledger::PublisherInfoList& list, double* budget) { @@ -251,14 +156,15 @@ ledger::PublisherInfoList Contribution::GetVerifiedListRecurring( void Contribution::PrepareACList( ledger::PublisherInfoList list, uint32_t next_record) { - double budget = 0.0; ledger::PublisherInfoList normalized_list; braveledger_bat_helper::PublisherList new_list; ledger_->NormalizeContributeWinners(&normalized_list, &list, 0); - auto verified_list = GetVerifiedListAuto(normalized_list, &budget); + for (const auto &publisher : normalized_list) { + if (publisher->percent == 0) { + continue; + } - for (const auto &publisher : verified_list) { braveledger_bat_helper::PUBLISHER_ST new_publisher; new_publisher.id_ = publisher->id; new_publisher.percent_ = publisher->percent; @@ -273,7 +179,7 @@ void Contribution::PrepareACList( InitReconcile(ledger::RewardsType::AUTO_CONTRIBUTE, new_list, {}, - budget); + ledger_->GetContributionAmount()); } void Contribution::PrepareRecurringList( @@ -281,6 +187,13 @@ void Contribution::PrepareRecurringList( uint32_t next_record) { double budget = 0.0; + if (list.empty()) { + StartAutoContribute(); + return; + } else { + SetTimer(&delay_ac_timer_id, 30); + } + auto verified_list = GetVerifiedListRecurring(list, &budget); braveledger_bat_helper::Directions directions; @@ -315,8 +228,6 @@ void Contribution::StartMonthlyContribution() { this, _1, _2)); - - SetTimer(&delay_ac_timer_id, 10); } bool Contribution::ShouldStartAutoContribute() { @@ -339,7 +250,7 @@ void Contribution::StartAutoContribute() { ledger::ExcludeFilter::FILTER_ALL_EXCEPT_EXCLUDED, true, current_reconcile_stamp, - ledger_->GetPublisherAllowNonVerified(), + false, ledger_->GetPublisherMinVisits()); ledger_->GetActivityInfoList( 0, @@ -747,10 +658,10 @@ bool Contribution::HaveReconcileEnoughFunds( const ledger::RewardsType type, double* fee, double budget, - double balance, + const double balance, const braveledger_bat_helper::Directions& directions) { if (type == ledger::RewardsType::AUTO_CONTRIBUTE) { - if (budget > balance) { + if (balance == 0) { BLOG(ledger_, ledger::LogLevel::LOG_WARNING) << "You do not have enough funds for auto contribution"; phase_one_->Complete(ledger::Result::NOT_ENOUGH_FUNDS, @@ -759,21 +670,18 @@ bool Contribution::HaveReconcileEnoughFunds( return false; } + if (budget > balance) { + budget = balance; + } + *fee = budget; return true; } if (type == ledger::RewardsType::RECURRING_TIP) { - double ac_amount = ledger_->GetContributionAmount(); - - // don't use ac amount if ac is disabled - if (!ShouldStartAutoContribute()) { - ac_amount = 0; - } - - if (budget + ac_amount > balance) { + if (budget > balance) { BLOG(ledger_, ledger::LogLevel::LOG_WARNING) << - "You do not have enough funds to do recurring and auto contribution"; + "You do not have enough funds to do monthly contribution"; phase_one_->Complete(ledger::Result::NOT_ENOUGH_FUNDS, "", ledger::RewardsType::AUTO_CONTRIBUTE); diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.h b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.h index 0d22ae7a0c37..b560bc3af22d 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.h @@ -189,12 +189,6 @@ class Contribution { ledger::DoDirectTipCallback callback); private: - // AUTO CONTRIBUTE: from the list gets only verified publishers and - // save unverified to the db - ledger::PublisherInfoList GetVerifiedListAuto( - const ledger::PublisherInfoList& all, - double* budget); - // RECURRING TIPS: from the list gets only verified publishers and // save unverified to the db ledger::PublisherInfoList GetVerifiedListRecurring( @@ -223,24 +217,13 @@ class Contribution { void DoRetry(const std::string& viewing_id); - void GetVerifiedAutoAmount( - const ledger::PublisherInfoList& publisher_list, - uint32_t record, - double balance, - ledger::HasSufficientBalanceToReconcileCallback callback); - - void GetVerifiedRecurringAmount( + void OnHasSufficientBalance( const ledger::PublisherInfoList& publisher_list, - uint32_t record, - double balance, - double budget, + const uint32_t record, + const double balance, ledger::HasSufficientBalanceToReconcileCallback callback); - double GetAmountFromVerifiedAuto( - const ledger::PublisherInfoList& publisher_list, - double ac_amount); - - static double GetAmountFromVerifiedRecurring( + static double GetTotalFromRecurringVerified( const ledger::PublisherInfoList& publisher_list); void OnSufficientBalanceWallet( @@ -265,7 +248,7 @@ class Contribution { const ledger::RewardsType type, double* fee, double budget, - double balance, + const double balance, const braveledger_bat_helper::Directions& directions); bool IsListEmpty( @@ -314,7 +297,7 @@ class Contribution { // For testing purposes friend class ContributionTest; FRIEND_TEST_ALL_PREFIXES(ContributionTest, GetAmountFromVerifiedAuto); - FRIEND_TEST_ALL_PREFIXES(ContributionTest, GetAmountFromVerifiedRecurring); + FRIEND_TEST_ALL_PREFIXES(ContributionTest, GetTotalFromRecurringVerified); }; } // namespace braveledger_contribution diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_unittest.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_unittest.cc index 86ec2aa47a0c..6d2558bf5f0e 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_unittest.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_unittest.cc @@ -40,35 +40,35 @@ class ContributionTest : public testing::Test { } }; -TEST_F(ContributionTest, GetAmountFromVerifiedRecurring) { +TEST_F(ContributionTest, GetTotalFromRecurringVerified) { ledger::PublisherInfoList publisher_info_list; GetPublishersForRecurring(&publisher_info_list, 5, {1, 5, 10}, 2); double amount = - Contribution::GetAmountFromVerifiedRecurring(publisher_info_list); + Contribution::GetTotalFromRecurringVerified(publisher_info_list); EXPECT_EQ(amount, 6); publisher_info_list.clear(); GetPublishersForRecurring(&publisher_info_list, 7, {1, 5, 10}, 5); amount = - Contribution::GetAmountFromVerifiedRecurring(publisher_info_list); + Contribution::GetTotalFromRecurringVerified(publisher_info_list); EXPECT_EQ(amount, 22); publisher_info_list.clear(); GetPublishersForRecurring(&publisher_info_list, 10, {5, 10, 20}, 7); amount = - Contribution::GetAmountFromVerifiedRecurring(publisher_info_list); + Contribution::GetTotalFromRecurringVerified(publisher_info_list); EXPECT_EQ(amount, 75); publisher_info_list.clear(); GetPublishersForRecurring(&publisher_info_list, 10, {10, 20, 50}, 9); amount = - Contribution::GetAmountFromVerifiedRecurring(publisher_info_list); + Contribution::GetTotalFromRecurringVerified(publisher_info_list); EXPECT_EQ(amount, 240); publisher_info_list.clear(); GetPublishersForRecurring(&publisher_info_list, 5, {1, 5, 10, 20, 50}, 5); amount = - Contribution::GetAmountFromVerifiedRecurring(publisher_info_list); + Contribution::GetTotalFromRecurringVerified(publisher_info_list); EXPECT_EQ(amount, 86); }