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 verified change (uplift to 0.70.x) #3697

Merged
merged 1 commit into from
Oct 16, 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
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 @@ -250,14 +250,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 @@ -456,7 +457,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 @@ -2045,7 +2045,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest,
}

IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest,
InsufficientNotificationForVerifiedsZeroAmountZeroPublishers) {
InsufficientNotificationForZeroAmountZeroPublishers) {
rewards_service_->GetNotificationService()->AddObserver(this);
EnableRewards();
CheckInsufficientFundsForTesting();
Expand All @@ -2055,7 +2055,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 @@ -2072,13 +2074,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 @@ -2095,7 +2094,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 @@ -2112,32 +2113,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 @@ -2154,31 +2154,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 @@ -2190,7 +2190,6 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest,
}
EXPECT_TRUE(notification_shown);


// Stop observing the Rewards service
rewards_service_->RemoveObserver(this);
}
Expand Down Expand Up @@ -2544,3 +2543,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 @@ -2559,7 +2559,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 @@ -2775,10 +2786,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 @@ -283,7 +283,6 @@ class RewardsServiceImpl : public RewardsService,
// Testing methods
void SetLedgerEnvForTesting();
void StartMonthlyContributionForTest();
void CheckInsufficientFundsForTesting();
void MaybeShowNotificationAddFundsForTesting(
base::OnceCallback<void(bool)> callback);

Expand Down Expand Up @@ -426,6 +425,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
19 changes: 8 additions & 11 deletions components/brave_rewards/resources/ui/components/contributeBox.tsx
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
10 changes: 5 additions & 5 deletions components/resources/brave_components_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
<message name="IDS_BRAVE_REWARDS_LOCAL_ADS_TITLE" desc="">Ads</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_ADS_DESC" desc="">Earn tokens by viewing ads in Brave. Ads presented are based on your interests, as inferred from your browsing behavior. No personal data or browsing history ever leaves your browser.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_CONTR_TITLE" desc="">Auto-Contribute</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_CONTR_DESC" desc="">An automatic way to support publishers and content creators. Set a monthly payment and browse normally. The sites you visit receive your contributions automatically, based on your attention as measured by Brave.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_CONTR_DESC" desc="">An automatic way to support publishers and content creators. Set a monthly payment and browse normally. The Brave Verified sites you visit will receive your contributions automatically, based on your attention as measured by Brave.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_ADS_CURRENT_EARNINGS" desc="">Estimated pending rewards</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_ADS_PAYMENT_DATE" desc="">Next payment date</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_ADS_NOTIFICATIONS_RECEIVED" desc="">Ad notifications received this month</message>
Expand Down Expand Up @@ -240,14 +240,15 @@
<message name="IDS_BRAVE_REWARDS_LOCAL_CONTR_MIN_TIME" desc="">Minimum page time before logging a visit</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_CONTR_MIN_VISITS" desc="">Minimum visits for publisher relevancy</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_CONTR_ALLOWED" desc="">What should be allowed?</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_CONTR_ALLOW_NON_VERIFIED" desc="">Allow contribution to non-verified sites</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_CONTR_SHOW_NON_VERIFIED" desc="">Only show verified sites in Auto-Contribute list</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_CONTR_ALLOW_VIDEOS" desc="">Allow contribution to videos</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_CONTR_VISIT_1" desc="">1 visit</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_CONTR_VISIT_5" desc="">5 visits</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_CONTR_VISIT_10" desc="">10 visits</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_CONTR_TIME_5" desc="">5 seconds</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_CONTR_TIME_8" desc="">8 seconds</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_CONTR_TIME_60" desc="">1 minute</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_CONTR_UP_TO" desc="">Up to</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_DONAT_ABILITY" desc="">Enable content-level tips on these sites</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_DONAT_ABILITY_YT" desc="">YouTube</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_DONAT_ABILITY_REDT" desc="">Reddit</message>
Expand Down Expand Up @@ -469,7 +470,6 @@
<message name="IDS_BRAVE_UI_REWARDS_CONTRIBUTE" desc="">Auto-Contribute</message>
<message name="IDS_BRAVE_UI_REWARDS_CONTRIBUTE_ATTENTION" desc="">Attention</message>
<message name="IDS_BRAVE_UI_REWARDS_CONTRIBUTE_ATTENTION_SCORE" desc="">Attention</message>
<message name="IDS_BRAVE_UI_REWARDS_CONTRIBUTE_TEXT1" desc="">You’re currently supporting</message>
<message name="IDS_BRAVE_UI_REWARDS_OFF_TEXT2" desc="">without your consent.</message>
<message name="IDS_BRAVE_UI_REWARDS_OFF_TEXT3" desc="">Today, Brave welcomes you to the new internet.</message>
<message name="IDS_BRAVE_UI_REWARDS_OFF_TEXT4" desc="">One where your time is valued, your personal data is kept private, and you actually get paid for your attention.</message>
Expand Down Expand Up @@ -556,12 +556,12 @@
<message name="IDS_BRAVE_UI_PENDING_CONTRIBUTION_EMPTY" desc="Text for empty pending table">No pending contributions…</message>
<message name="IDS_BRAVE_UI_PENDING_CONTRIBUTION_REMOVE_ALL" desc="Text for remove all button">Remove All</message>

<message name="IDS_BRAVE_UI_EXCLUDED_SITES_TEXT" desc="">Excluded Sites</message>
<message name="IDS_BRAVE_UI_EXCLUDED_SITES_TEXT" desc="">Sites Excluded</message>
<message name="IDS_BRAVE_UI_RESTORE_SITE" desc="">Restore this site</message>
<message name="IDS_BRAVE_UI_REWARDS_EXCLUDED_TEXT_1" desc="">You've excluded</message>
<message name="IDS_BRAVE_UI_REWARDS_EXCLUDED_TEXT_2" desc="">sites from Auto-Contribute.</message>
<message name="IDS_BRAVE_UI_SHOW_ALL" desc="">Show All</message>
<message name="IDS_BRAVE_UI_SUPPORTED_SITES" desc="">Supported Sites</message>
<message name="IDS_BRAVE_UI_SUPPORTED_SITES" desc="">Sites viewed</message>

<message name="IDS_BRAVE_UI_GRANT_FINISH_TITLE_ADS" desc="Title on final grant screen for Ads">Brave Ads Rewards!</message>
<message name="IDS_BRAVE_UI_GRANT_FINISH_TEXT_ADS" desc="Text on final grant screen for UGP">Your rewards grant from Brave Ads is on its way.</message>
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
"@types/storybook__react": "^4.0.2",
"awesome-typescript-loader": "^5.2.1",
"babel-loader": "^8.0.6",
"brave-ui": "github:brave/brave-ui#61e9799c6ad6c0bf46f3a4a0c63dc83a33650618",
"brave-ui": "github:brave/brave-ui#13403edac7becda7b6285c1e983547ee31ab9511",
"css-loader": "^2.1.1",
"csstype": "^2.5.5",
"deep-freeze-node": "^1.1.3",
Expand Down
Loading