Skip to content

Auto-Contribute list only contains included publishers #475

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

Merged
merged 1 commit into from
Oct 2, 2018
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: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ deps = {
"vendor/boto": "https://github.com/boto/boto@f7574aa6cc2c819430c1f05e9a1a1a666ef8169b",
"vendor/python-patch": "https://github.com/svn2github/python-patch@a336a458016ced89aba90dfc3f4c8222ae3b1403",
"vendor/sparkle": "https://github.com/brave/Sparkle.git@c0759cce415d7c0feae45005c8a013b1898711f0",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@f0a310ddc3729588119264b5354be089452f2a52",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@ca5d4b6d1a39c7e8e2fb149bbd62f9e71631eba6",
"vendor/bat-native-rapidjson": "https://github.com/brave-intl/bat-native-rapidjson.git@86aafe2ef89835ae71c9ed7c2527e3bb3000930e",
"vendor/bip39wally-core-native": "https://github.com/brave-intl/bip39wally-core-native.git@9b119931c702d55be994117eb505d56310720b1d",
"vendor/bat-native-anonize": "https://github.com/brave-intl/bat-native-anonize.git@0559543f458a949b83b58035273ef7f8f1a1b111",
Expand Down
8 changes: 8 additions & 0 deletions browser/ui/webui/brave_rewards_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class RewardsDOMHandler : public WebUIMessageHandler,
unsigned int result,
brave_rewards::Grant grant) override;
void OnContentSiteUpdated(brave_rewards::RewardsService* rewards_service) override;
void OnExcludedSitesChanged(brave_rewards::RewardsService* rewards_service) override;

brave_rewards::RewardsService* rewards_service_; // NOT OWNED

Expand Down Expand Up @@ -373,6 +374,13 @@ void RewardsDOMHandler::OnContentSiteUpdated(brave_rewards::RewardsService* rewa
rewards_service_->GetContentSiteList(0, 0, base::Bind(&RewardsDOMHandler::OnGetContentSiteList, base::Unretained(this)));
}

void RewardsDOMHandler::OnExcludedSitesChanged(brave_rewards::RewardsService* rewards_service) {
if (rewards_service_ && web_ui()->CanCallJavascript()) {
int num = (int)rewards_service_->GetNumExcludedSites();
web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.numExcludedSites", base::Value(num));
}
}

void RewardsDOMHandler::SaveSetting(const base::ListValue* args) {
if (rewards_service_) {
std::string key;
Expand Down
6 changes: 6 additions & 0 deletions components/brave_rewards/browser/publisher_info_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ std::string PublisherInfoDatabase::BuildClauses(int start,
if (filter.min_duration > 0)
clauses += " AND ai.duration >= ?";

if (filter.excluded != ledger::PUBLISHER_EXCLUDE::ALL)
clauses += " AND pi.excluded = ?";

for (const auto& it : filter.order_by) {
clauses += " ORDER BY " + it.first;
clauses += (it.second ? " ASC" : " DESC");
Expand Down Expand Up @@ -458,6 +461,9 @@ void PublisherInfoDatabase::BindFilter(sql::Statement& statement,

if (filter.min_duration > 0)
statement.BindInt(column++, filter.min_duration);

if (filter.excluded != ledger::PUBLISHER_EXCLUDE::ALL)
statement.BindInt(column++, filter.excluded);
}

// static
Expand Down
1 change: 1 addition & 0 deletions components/brave_rewards/browser/rewards_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class RewardsService : public KeyedService {
virtual void GetGrantCaptcha() = 0;
virtual void SolveGrantCaptcha(const std::string& solution) const = 0;
virtual std::string GetWalletPassphrase() const = 0;
virtual unsigned int GetNumExcludedSites() const = 0;
virtual void RecoverWallet(const std::string passPhrase) const = 0;
virtual void ExcludePublisher(const std::string publisherKey) const = 0;
virtual void RestorePublishers() = 0;
Expand Down
9 changes: 9 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,10 @@ std::string RewardsServiceImpl::GetWalletPassphrase() const {
return ledger_->GetWalletPassphrase();
}

unsigned int RewardsServiceImpl::GetNumExcludedSites() const {
return ledger_->GetNumExcludedSites();
}

void RewardsServiceImpl::RecoverWallet(const std::string passPhrase) const {
return ledger_->RecoverWallet(passPhrase);
}
Expand Down Expand Up @@ -1115,6 +1119,11 @@ void RewardsServiceImpl::GetPublisherActivityFromUrl(uint64_t windowId, const st
GetPublisherYear(now));
}

void RewardsServiceImpl::OnExcludedSitesChanged() {
for (auto& observer : observers_)
observer.OnExcludedSitesChanged(this);
}

void RewardsServiceImpl::OnPublisherActivity(ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> info,
uint64_t windowId) {
Expand Down
2 changes: 2 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class RewardsServiceImpl : public RewardsService,
void GetGrantCaptcha() override;
void SolveGrantCaptcha(const std::string& solution) const override;
std::string GetWalletPassphrase() const override;
unsigned int GetNumExcludedSites() const override;
void RecoverWallet(const std::string passPhrase) const override;
void GetContentSiteList(uint32_t start,
uint32_t limit,
Expand Down Expand Up @@ -194,6 +195,7 @@ class RewardsServiceImpl : public RewardsService,
void OnPublisherActivity(ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> info,
uint64_t windowId) override;
void OnExcludedSitesChanged() override;

// URLFetcherDelegate impl
void OnURLFetchComplete(const net::URLFetcher* source) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class RewardsServiceObserver : public base::CheckedObserver {
unsigned int result,
brave_rewards::Grant grant) {};
virtual void OnContentSiteUpdated(RewardsService* rewards_service) {};
virtual void OnExcludedSitesChanged(RewardsService* rewards_service) {};
};

} // namespace brave_rewards
Expand Down
4 changes: 4 additions & 0 deletions components/brave_rewards/ui/actions/rewards_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ export const onWalletExists = (exists: boolean) => action(types.ON_WALLET_EXISTS
})

export const restorePublishers = () => action(types.ON_RESTORE_PUBLISHERS)

export const onNumExcludedSites = (num: string) => action(types.ON_NUM_EXCLUDED_SITES, {
num
})
5 changes: 5 additions & 0 deletions components/brave_rewards/ui/brave_rewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ window.cr.define('brave_rewards', function () {
getActions().onContributeList(list)
}

function numExcludedSites (num: string) {
getActions().onNumExcludedSites(num)
}

function balanceReports (reports: Record<string, Rewards.Report>) {
getActions().onBalanceReports(reports)
}
Expand All @@ -114,6 +118,7 @@ window.cr.define('brave_rewards', function () {
reconcileStamp,
addresses,
contributeList,
numExcludedSites,
balanceReports,
walletExists
}
Expand Down
15 changes: 3 additions & 12 deletions components/brave_rewards/ui/components/contributeBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ class ContributeBox extends React.Component<Props, State> {
}
}

getIncludedPublishers = (list: Rewards.Publisher[]) => {
if (!list) {
return []
}

return list.filter((item: Rewards.Publisher) => item.excluded !== 1)
}

getContributeRows = (list: Rewards.Publisher[]) => {
return list.map((item: Rewards.Publisher) => {
let name = item.name
Expand Down Expand Up @@ -183,16 +175,15 @@ class ContributeBox extends React.Component<Props, State> {
contributionMonthly,
enabledContribute,
reconcileStamp,
numExcludedSites,
autoContributeList
} = this.props.rewardsData
const includedPublishers = this.getIncludedPublishers(autoContributeList)
const toggleOn = !(firstLoad !== false || !enabledMain)
const monthlyList: MonthlyChoice[] = utils.generateContributionMonthly(walletInfo.choices, walletInfo.rates)
const contributeRows = this.getContributeRows(includedPublishers)
const contributeRows = this.getContributeRows(autoContributeList)
const topRows = contributeRows.slice(0, 5)
const numRows = includedPublishers && includedPublishers.length
const numRows = contributeRows && contributeRows.length
const allSites = !(numRows > 5)
const numExcludedSites = autoContributeList.length - includedPublishers.length

return (
<Box
Expand Down
3 changes: 2 additions & 1 deletion components/brave_rewards/ui/constants/rewards_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ export const enum types {
ON_EXCLUDE_PUBLISHER = '@@rewards/ON_EXCLUDE_PUBLISHER',
ON_RESTORE_PUBLISHERS = '@@rewards/ON_RESTORE_PUBLISHERS',
CHECK_WALLET_EXISTENCE = '@@rewards/CHECK_WALLET_EXISTENCE',
ON_WALLET_EXISTS = '@@rewards/ON_WALLET_EXISTS'
ON_WALLET_EXISTS = '@@rewards/ON_WALLET_EXISTS',
ON_NUM_EXCLUDED_SITES = '@@rewards/ON_NUM_EXCLUDED_SITES'
}
6 changes: 6 additions & 0 deletions components/brave_rewards/ui/reducers/publishers_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ const publishersReducer: Reducer<Rewards.State | undefined> = (state: Rewards.St
state.firstLoad = false
state.autoContributeList = action.payload.list
break
case types.ON_NUM_EXCLUDED_SITES:
state = { ...state }
if (action.payload.num != null) {
state.numExcludedSites = parseInt(action.payload.num, 10)
}
break
case types.ON_EXCLUDE_PUBLISHER:
if (!action.payload.publisherKey) {
break
Expand Down
1 change: 1 addition & 0 deletions components/brave_rewards/ui/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const defaultState: Rewards.State = {
contributionVideos: true,
donationAbilityYT: true,
donationAbilityTwitter: true,
numExcludedSites: 0,
walletInfo: {
balance: 0,
choices: [5.0, 7.5, 10.0, 17.5, 25.0, 50.0, 75.0, 100.0],
Expand Down
9 changes: 7 additions & 2 deletions components/definitions/rewards.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ declare namespace Rewards {
contributionVideos: boolean
donationAbilityYT: boolean
donationAbilityTwitter: boolean
numExcludedSites: number
walletInfo: WalletProperties
connectedWallet: boolean
recoveryKey: string
Expand Down Expand Up @@ -83,13 +84,17 @@ declare namespace Rewards {
expiryTime: number
}

export type Excluded = 0 | 1 | 2
export enum Status {
DEFAULT = 0,
EXCLUDED = 1,
INCLUDED = 2
}

export interface Publisher {
publisherKey: string
percentage: number
verified: boolean
excluded: Excluded
excluded: Status
url: string
name: string
provider: string
Expand Down