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

AC contribution change #3564

Merged
merged 1 commit into from
Oct 10, 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
5 changes: 2 additions & 3 deletions .storybook/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const locale: Record<string, string> = {
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:',
Expand Down Expand Up @@ -185,7 +185,6 @@ const locale: Record<string, string> = {
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.',
Expand Down Expand Up @@ -233,7 +232,7 @@ const locale: Record<string, string> = {
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',
masparrow marked this conversation as resolved.
Show resolved Hide resolved
thankYou: 'Thank You!',
termsOfService: 'Terms of Service',
optOutTooltip: 'You will no longer receive\nads from this category',
Expand Down
4 changes: 2 additions & 2 deletions browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,15 @@ 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 },
{ "contributionVisit10", IDS_BRAVE_REWARDS_LOCAL_CONTR_VISIT_10 },
{ "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 },
Expand Down Expand Up @@ -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 },
Expand Down
109 changes: 85 additions & 24 deletions components/brave_rewards/browser/rewards_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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_ ==
Expand All @@ -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;
Expand All @@ -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_ ==
Expand All @@ -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_ ==
Expand All @@ -2150,31 +2150,31 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest,
}

IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest,
InsufficientNotificationForVerifiedsInsufficientAmount) {
InsufficientNotificationForVerifiedInsufficientAmount) {
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);
}
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_ ==
Expand All @@ -2186,7 +2186,6 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest,
}
EXPECT_TRUE(notification_shown);


// Stop observing the Rewards service
rewards_service_->RemoveObserver(this);
}
Expand Down Expand Up @@ -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);
}
17 changes: 12 additions & 5 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2770,7 +2770,18 @@ void RewardsServiceImpl::MaybeShowNotificationAddFunds() {

void RewardsServiceImpl::MaybeShowNotificationAddFundsForTesting(
base::OnceCallback<void(bool)> callback) {
bat_ledger_->HasSufficientBalanceToReconcile(std::move(callback));
bat_ledger_->HasSufficientBalanceToReconcile(
base::BindOnce(
&RewardsServiceImpl::OnMaybeShowNotificationAddFundsForTesting,
AsWeakPtr(),
std::move(callback)));
}

void RewardsServiceImpl::OnMaybeShowNotificationAddFundsForTesting(
base::OnceCallback<void(bool)> callback,
const bool sufficient) {
ShowNotificationAddFunds(sufficient);
std::move(callback).Run(sufficient);
}

bool RewardsServiceImpl::ShouldShowNotificationAddFunds() const {
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ class RewardsServiceImpl : public RewardsService,
// Testing methods
void SetLedgerEnvForTesting();
void StartMonthlyContributionForTest();
void CheckInsufficientFundsForTesting();
void MaybeShowNotificationAddFundsForTesting(
base::OnceCallback<void(bool)> callback);

Expand Down Expand Up @@ -432,6 +431,10 @@ class RewardsServiceImpl : public RewardsService,
bool ShouldShowNotificationAddFunds() const;
void ShowNotificationAddFunds(bool sufficient);

void OnMaybeShowNotificationAddFundsForTesting(
base::OnceCallback<void(bool)> callback,
const bool result);

void MaybeShowNotificationTipsPaid();
void ShowNotificationTipsPaid(bool ac_enabled);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class ContributeBox extends React.Component<Props, State> {
multiple={true}
onChange={this.onCheckSettingChange}
>
<div data-key='contributionNonVerified'>{getLocale('contributionNonVerified')}</div>
<div data-key='contributionNonVerified'>{getLocale('contributionShowNonVerified')}</div>
<div data-key='contributionVideos'>{getLocale('contributionVideos')}</div>
</Checkbox>
</ControlWrapper>
Expand Down Expand Up @@ -270,15 +270,15 @@ class ContributeBox extends React.Component<Props, State> {
floating={true}
onChange={this.onSelectSettingChange.bind(this, 'contributionMonthly')}
value={parseFloat((contributionMonthly.toString() || '0')).toFixed(1)}
showAllContents={true}
>
{
monthlyList.map((choice: MonthlyChoice) => {
return <div key={`choice-${choice.tokens}`} data-value={choice.tokens.toString()}>
<Tokens
value={choice.tokens}
converted={choice.converted}
/>
</div>
return (
<div key={`choice-${choice.tokens}`} data-value={choice.tokens.toString()}>
{getLocale('contributionUpTo')} <Tokens value={choice.tokens} converted={choice.converted} />
</div>
)
})
}
</Select>
Expand All @@ -289,10 +289,7 @@ class ContributeBox extends React.Component<Props, State> {
</NextContribution>
</List>
<List title={getLocale('contributionSites')}>
{getLocale('total')} &nbsp;<Tokens
value={numRows.toString()}
hideText={true}
/>
<Tokens value={numRows.toString()} hideText={true} />
</List>
<TableContribute
header={[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ export default class ModalContribute extends React.PureComponent<Props, {}> {

return (
<>
<StyledContent>
{getLocale('rewardsContributeText1')} <StyledNum>{numSites}</StyledNum> {getLocale('sites')}.
</StyledContent>
<TableContribute
header={this.headers}
rows={rows}
Expand Down
Loading