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

Do not retry if rewards is off or AC is off #5900

Merged
merged 1 commit into from
Jun 19, 2020
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
2 changes: 2 additions & 0 deletions browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,8 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "contributionStepReserve", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_RESERVE }, // NOLINT
{ "contributionStepExternalTransaction", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_EXTERNAL_TRANSACTION }, // NOLINT
{ "contributionStepCreds", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_CREDS }, // NOLINT
{ "contributionStepRewardsOff", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_REWARDS_OFF }, // NOLINT
{ "contributionStepAutoContributeOff", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_AUTO_CONTRIBUTE_OFF }, // NOLINT
{ "rewardsNotEnabled", IDS_BRAVE_REWARDS_INTERNALS_REWARDS_NOT_ENABLED }, // NOLINT
{ "rewardsTypeAuto", IDS_BRAVE_REWARDS_INTERNALS_REWARDS_TYPE_AUTO }, // NOLINT
{ "rewardsTypeOneTimeTip", IDS_BRAVE_REWARDS_INTERNALS_REWARDS_TYPE_ONE_TIME_TIP }, // NOLINT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ const getProcessorString = (processor: number) => {

const getContributionStepString = (step: number) => {
switch (step) {
case -6:
return getLocale('contributionStepAutoContributeOff')
case -5:
return getLocale('contributionStepRewardsOff')
case -4:
return getLocale('contributionAutoContributeTableEmpty')
return getLocale('contributionStepAutoContributeTableEmpty')
case -3:
return getLocale('contributionStepNotEnoughFunds')
case -2:
Expand Down
2 changes: 2 additions & 0 deletions components/resources/brave_components_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@
<message name="IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_RESERVE" desc="">Reserve</message>
<message name="IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_EXTERNAL_TRANSACTION" desc="">External transaction</message>
<message name="IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_CREDS" desc="">Creds</message>
<message name="IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_REWARDS_OFF" desc="">Rewards was turned off</message>
<message name="IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_AUTO_CONTRIBUTE_OFF" desc="">Auto-contribute was turned off</message>
<message name="IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_TYPE" desc="Contribution type">Type:</message>
<message name="IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTIONS" desc="">Contributions</message>
<message name="IDS_BRAVE_REWARDS_INTERNALS_DOWNLOAD_BUTTON" desc="">Download full log</message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
module ledger.mojom;

enum ContributionStep {
STEP_AC_OFF = -6,
STEP_REWARDS_OFF = -5,
STEP_AC_TABLE_EMPTY = -4,
STEP_NOT_ENOUGH_FUNDS = -3,
STEP_FAILED = -2,
Expand Down Expand Up @@ -240,7 +242,9 @@ enum Result {
RETRY_SHORT = 30,
RETRY_LONG = 31,
CONTINUE = 32,
IN_PROGRESS= 33
IN_PROGRESS= 33,
REWARDS_OFF = 34,
AC_OFF = 35
};

enum PublisherStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "bat/ledger/internal/contribution/contribution_unblinded.h"
#include "bat/ledger/internal/contribution/contribution_util.h"
#include "bat/ledger/internal/contribution/unverified.h"
#include "bat/ledger/internal/state/state_util.h"
#include "bat/ledger/internal/uphold/uphold.h"
#include "bat/ledger/internal/wallet/balance.h"
#include "bat/ledger/internal/ledger_impl.h"
Expand All @@ -48,6 +49,12 @@ ledger::ContributionStep ConvertResultIntoContributionStep(
case ledger::Result::NOT_ENOUGH_FUNDS: {
return ledger::ContributionStep::STEP_NOT_ENOUGH_FUNDS;
}
case ledger::Result::REWARDS_OFF: {
return ledger::ContributionStep::STEP_REWARDS_OFF;
}
case ledger::Result::AC_OFF: {
return ledger::ContributionStep::STEP_AC_OFF;
}
default: {
return ledger::ContributionStep::STEP_FAILED;
}
Expand Down Expand Up @@ -755,6 +762,23 @@ void Contribution::Retry(
return;
}

if (!braveledger_state::GetRewardsMainEnabled(ledger_)) {
BLOG(1, "Rewards is disabled, completing contribution");
ledger_->ContributionCompleted(
ledger::Result::REWARDS_OFF,
std::move(contribution));
return;
}

if (contribution->type == ledger::RewardsType::AUTO_CONTRIBUTE &&
!braveledger_state::GetAutoContributeEnabled(ledger_)) {
BLOG(1, "AC is disabled, completing contribution");
ledger_->ContributionCompleted(
ledger::Result::AC_OFF,
std::move(contribution));
return;
}

BLOG(1, "Retrying contribution (" << contribution->contribution_id
<< ") on step " << contribution->step);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ void ContributionSKU::OnOrder(
callback);
return;
}
case ledger::ContributionStep::STEP_REWARDS_OFF:
case ledger::ContributionStep::STEP_AC_OFF:
case ledger::ContributionStep::STEP_AC_TABLE_EMPTY:
case ledger::ContributionStep::STEP_NOT_ENOUGH_FUNDS:
case ledger::ContributionStep::STEP_FAILED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ void Unblinded::Retry(
get_callback);
return;
}
case ledger::ContributionStep::STEP_REWARDS_OFF:
case ledger::ContributionStep::STEP_AC_OFF:
case ledger::ContributionStep::STEP_AC_TABLE_EMPTY:
case ledger::ContributionStep::STEP_CREDS:
case ledger::ContributionStep::STEP_EXTERNAL_TRANSACTION:
Expand Down