diff --git a/vendor/bat-native-ledger/src/bat_contribution.cc b/vendor/bat-native-ledger/src/bat_contribution.cc index c64d6a51a43e..33db320b09e5 100644 --- a/vendor/bat-native-ledger/src/bat_contribution.cc +++ b/vendor/bat-native-ledger/src/bat_contribution.cc @@ -99,13 +99,36 @@ void BatContribution::ReconcilePublisherList( StartReconcile(ledger_->GenerateGUID(), category, new_list); } +void BatContribution::ResetReconcileStamp() { + ledger_->ResetReconcileStamp(); + SetReconcileTimer(); +} + void BatContribution::OnTimerReconcile() { + if (!ledger_->GetRewardsMainEnabled()) { + ResetReconcileStamp(); + return; + } + ledger_->GetRecurringDonations( std::bind(&BatContribution::ReconcilePublisherList, this, ledger::PUBLISHER_CATEGORY::RECURRING_DONATION, _1, _2)); } +bool BatContribution::ShouldStartAutoContribute() { + if (!ledger_->GetRewardsMainEnabled()) { + return false; + } + + return ledger_->GetAutoContribute(); +} + void BatContribution::StartAutoContribute() { + if (!ShouldStartAutoContribute()) { + ResetReconcileStamp(); + return; + } + uint64_t current_reconcile_stamp = ledger_->GetReconcileStamp(); ledger::PublisherInfoFilter filter = ledger_->CreatePublisherFilter( "", @@ -644,8 +667,7 @@ void BatContribution::OnReconcileComplete(ledger::Result result, const std::string& probi) { // Start the timer again if it wasn't a direct donation if (category == ledger::PUBLISHER_CATEGORY::AUTO_CONTRIBUTE) { - ledger_->ResetReconcileStamp(); - SetReconcileTimer(); + ResetReconcileStamp(); } // Trigger auto contribute after recurring donation diff --git a/vendor/bat-native-ledger/src/bat_contribution.h b/vendor/bat-native-ledger/src/bat_contribution.h index 4619604c688e..a816554cf49f 100644 --- a/vendor/bat-native-ledger/src/bat_contribution.h +++ b/vendor/bat-native-ledger/src/bat_contribution.h @@ -139,10 +139,15 @@ class BatContribution { const ledger::PublisherInfoList& list, uint32_t next_record); + // Resets reconcile stamps + void ResetReconcileStamp(); + // Fetches recurring donations that will be then used for the contribution. // This is called from global timer in impl. void OnTimerReconcile(); + bool ShouldStartAutoContribute(); + // Triggers contribution process for auto contribute table void StartAutoContribute();