Skip to content

Commit

Permalink
AC verified change
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Oct 3, 2019
1 parent 495d1a9 commit 9036f88
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 175 deletions.
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',
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 @@ -245,14 +245,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
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
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 @@ -245,14 +245,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 @@ -477,7 +478,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 @@ -564,12 +564,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
Original file line number Diff line number Diff line change
Expand Up @@ -71,150 +71,54 @@ void Contribution::HasSufficientBalance(
}

void Contribution::OnSufficientBalanceWallet(
ledger::Result result,
const ledger::Result result,
ledger::BalancePtr properties,
ledger::HasSufficientBalanceToReconcileCallback callback) {
if (result == ledger::Result::LEDGER_OK && properties) {
auto filter = ledger_->CreateActivityFilter(
std::string(),
ledger::ExcludeFilter::FILTER_ALL_EXCEPT_EXCLUDED,
true,
ledger_->GetReconcileStamp(),
ledger_->GetPublisherAllowNonVerified(),
ledger_->GetPublisherMinVisits());
ledger_->GetActivityInfoList(
0,
0,
std::move(filter),
std::bind(&Contribution::GetVerifiedAutoAmount,
this,
_1,
_2,
properties->total,
callback));
}
}

void Contribution::GetVerifiedAutoAmount(
const ledger::PublisherInfoList& publisher_list,
uint32_t record,
double balance,
ledger::HasSufficientBalanceToReconcileCallback callback) {
double ac_amount = ledger_->GetContributionAmount();
double total_reconcile_amount(GetAmountFromVerifiedAuto(
publisher_list, ac_amount));
if (balance < total_reconcile_amount && !publisher_list.empty()) {
callback(false);
if (result != ledger::Result::LEDGER_OK || properties) {
return;
}
ledger_->GetRecurringTips(
std::bind(&Contribution::GetVerifiedRecurringAmount,
this,
_1,
_2,
balance,
total_reconcile_amount,
callback));
}

double Contribution::GetAmountFromVerifiedAuto(
const ledger::PublisherInfoList& publisher_list,
double ac_amount) {
double verified_bat = 0.0;
for (const auto& publisher : publisher_list) {
const auto add = ledger_->IsPublisherConnectedOrVerified(publisher->status);
if (add) {
verified_bat += (publisher->weight / 100.0) * ac_amount;
}
}
return verified_bat;
auto tips_callback =
std::bind(&Contribution::OnHasSufficientBalance,
this,
_1,
_2,
properties->total,
callback);

ledger_->GetRecurringTips(tips_callback);
}

void Contribution::GetVerifiedRecurringAmount(
void Contribution::OnHasSufficientBalance(
const ledger::PublisherInfoList& publisher_list,
uint32_t record,
double balance,
double total_reconcile_amount,
const uint32_t record,
const double balance,
ledger::HasSufficientBalanceToReconcileCallback callback) {
if (publisher_list.empty()) {
callback(true);
return;
}
total_reconcile_amount += GetAmountFromVerifiedRecurring(publisher_list);
callback(balance >= total_reconcile_amount);

const auto total = GetTotalFromRecurringVerified(publisher_list);
callback(balance >= total);
}

// static
double Contribution::GetAmountFromVerifiedRecurring(
double Contribution::GetTotalFromRecurringVerified(
const ledger::PublisherInfoList& publisher_list) {
double total_recurring_amount = 0.0;
for (const auto& publisher : publisher_list) {
if (publisher->id.empty()) {
continue;
}

if (publisher->status == ledger::PublisherStatus::VERIFIED) {
total_recurring_amount += publisher->weight;
}
}
return total_recurring_amount;
}



ledger::PublisherInfoList Contribution::GetVerifiedListAuto(
const ledger::PublisherInfoList& list,
double* budget) {
ledger::PublisherInfoList verified;
ledger::PublisherInfoList non_verified_temp;
ledger::PendingContributionList non_verified;

double verified_total = 0.0;
double ac_amount = ledger_->GetContributionAmount();

for (const auto& publisher : list) {
if (publisher->percent == 0) {
continue;
}

const auto add = ledger_->IsPublisherConnectedOrVerified(publisher->status);
if (add) {
verified.push_back(publisher->Clone());
verified_total += publisher->weight;
} else {
non_verified_temp.push_back(publisher->Clone());
}
}

// verified budget
*budget += (verified_total / 100) * ac_amount;

// verified publishers
for (auto& publisher : verified) {
publisher->weight = (publisher->weight / verified_total) * 100;
publisher->percent = static_cast<uint32_t>(publisher->weight);
}

// non-verified publishers
for (const auto& publisher : non_verified_temp) {
auto contribution = ledger::PendingContribution::New();
contribution->amount = (publisher->weight / 100) * ac_amount;
contribution->publisher_key = publisher->id;
contribution->viewing_id = "";
contribution->category = ledger::RewardsCategory::AUTO_CONTRIBUTE;


non_verified.push_back(std::move(contribution));
}

if (non_verified.size() > 0) {
ledger_->SaveUnverifiedContribution(
std::move(non_verified),
[](const ledger::Result _){});
}

return verified;
}

ledger::PublisherInfoList Contribution::GetVerifiedListRecurring(
const ledger::PublisherInfoList& list,
double* budget) {
Expand Down Expand Up @@ -252,14 +156,15 @@ ledger::PublisherInfoList Contribution::GetVerifiedListRecurring(
void Contribution::PrepareACList(
ledger::PublisherInfoList list,
uint32_t next_record) {
double budget = 0.0;
ledger::PublisherInfoList normalized_list;
braveledger_bat_helper::PublisherList new_list;

ledger_->NormalizeContributeWinners(&normalized_list, &list, 0);
auto verified_list = GetVerifiedListAuto(normalized_list, &budget);
for (const auto &publisher : normalized_list) {
if (publisher->percent == 0) {
continue;
}

for (const auto &publisher : verified_list) {
braveledger_bat_helper::PUBLISHER_ST new_publisher;
new_publisher.id_ = publisher->id;
new_publisher.percent_ = publisher->percent;
Expand All @@ -274,7 +179,7 @@ void Contribution::PrepareACList(
InitReconcile(ledger::RewardsCategory::AUTO_CONTRIBUTE,
new_list,
{},
budget);
ledger_->GetContributionAmount());
}

void Contribution::PrepareRecurringList(
Expand Down Expand Up @@ -340,7 +245,7 @@ void Contribution::StartAutoContribute() {
ledger::ExcludeFilter::FILTER_ALL_EXCEPT_EXCLUDED,
true,
current_reconcile_stamp,
ledger_->GetPublisherAllowNonVerified(),
false,
ledger_->GetPublisherMinVisits());
ledger_->GetActivityInfoList(
0,
Expand Down Expand Up @@ -751,7 +656,7 @@ bool Contribution::HaveReconcileEnoughFunds(
double balance,
const braveledger_bat_helper::Directions& directions) {
if (category == ledger::RewardsCategory::AUTO_CONTRIBUTE) {
if (budget > balance) {
if (balance == 0) {
BLOG(ledger_, ledger::LogLevel::LOG_WARNING) <<
"You do not have enough funds for auto contribution";
phase_one_->Complete(ledger::Result::NOT_ENOUGH_FUNDS,
Expand All @@ -765,16 +670,9 @@ bool Contribution::HaveReconcileEnoughFunds(
}

if (category == ledger::RewardsCategory::RECURRING_TIP) {
double ac_amount = ledger_->GetContributionAmount();

// don't use ac amount if ac is disabled
if (!ShouldStartAutoContribute()) {
ac_amount = 0;
}

if (budget + ac_amount > balance) {
if (budget > balance) {
BLOG(ledger_, ledger::LogLevel::LOG_WARNING) <<
"You do not have enough funds to do recurring and auto contribution";
"You do not have enough funds to do monthly contribution";
phase_one_->Complete(ledger::Result::NOT_ENOUGH_FUNDS,
"",
ledger::RewardsCategory::AUTO_CONTRIBUTE);
Expand Down
Loading

0 comments on commit 9036f88

Please sign in to comment.