Skip to content

Commit

Permalink
Merge pull request #5900 from brave/ac-retry
Browse files Browse the repository at this point in the history
Do not retry if rewards is off or AC is off
  • Loading branch information
NejcZdovc authored Jun 19, 2020
2 parents 67add5d + 35a8eb9 commit 4dda50f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 2 deletions.
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

0 comments on commit 4dda50f

Please sign in to comment.