Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensuring contribution does not process if rewards or a-c is off (0.59) #1215

Merged
merged 1 commit into from
Jan 8, 2019
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
26 changes: 24 additions & 2 deletions vendor/bat-native-ledger/src/bat_contribution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,17 @@ 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,
Expand All @@ -106,7 +116,20 @@ void BatContribution::OnTimerReconcile() {
std::placeholders::_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(
"",
Expand Down Expand Up @@ -673,8 +696,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
Expand Down
5 changes: 5 additions & 0 deletions vendor/bat-native-ledger/src/bat_contribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,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();

Expand Down