Skip to content

Commit

Permalink
Merge pull request #420 from ryanml/remove-sites
Browse files Browse the repository at this point in the history
Adding option to remove sites from auto-contribute
  • Loading branch information
Jason Sadler committed Sep 11, 2018
1 parent 4622902 commit d8716b0
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 7 deletions.
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@daece89994e1a9857fb55d4fd2bcea108e146334",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@e8015a75518cecb85cc5eaa37b9d27bada8c45e5",
"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@6f5817c5a4dcabb49e22b578ecae4993159e6481",
Expand Down
13 changes: 13 additions & 0 deletions browser/ui/webui/brave_rewards_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class RewardsDOMHandler : public WebUIMessageHandler,
void SaveSetting(const base::ListValue* args);
void OnGetContentSiteList(std::unique_ptr<brave_rewards::ContentSiteList>, uint32_t record);
void GetBalanceReports(const base::ListValue* args);
void ExcludePublisher(const base::ListValue* args);

// RewardsServiceObserver implementation
void OnWalletInitialized(brave_rewards::RewardsService* rewards_service,
Expand Down Expand Up @@ -117,6 +118,9 @@ void RewardsDOMHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback("getBalanceReports",
base::BindRepeating(&RewardsDOMHandler::GetBalanceReports,
base::Unretained(this)));
web_ui()->RegisterMessageCallback("excludePublisher",
base::BindRepeating(&RewardsDOMHandler::ExcludePublisher,
base::Unretained(this)));
}

void RewardsDOMHandler::Init() {
Expand Down Expand Up @@ -391,6 +395,14 @@ void RewardsDOMHandler::SaveSetting(const base::ListValue* args) {
}
}

void RewardsDOMHandler::ExcludePublisher(const base::ListValue *args) {
if (rewards_service_) {
std::string publisherKey;
args->GetString(0, &publisherKey);
rewards_service_->ExcludePublisher(publisherKey);
}
}

void RewardsDOMHandler::OnGetContentSiteList(std::unique_ptr<brave_rewards::ContentSiteList> list, uint32_t record) {
if (web_ui()->CanCallJavascript()) {
auto publishers = std::make_unique<base::ListValue>();
Expand All @@ -399,6 +411,7 @@ void RewardsDOMHandler::OnGetContentSiteList(std::unique_ptr<brave_rewards::Cont
publisher->SetDouble("percentage", item.percentage);
publisher->SetString("publisherKey", item.id);
publisher->SetBoolean("verified", item.verified);
publisher->SetInteger("excluded", item.excluded);
publisher->SetString("name", item.name);
publisher->SetString("provider", item.provider);
publisher->SetString("url", item.url);
Expand Down
4 changes: 3 additions & 1 deletion components/brave_rewards/browser/content_site.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ namespace brave_rewards {
ContentSite::ContentSite(const std::string& site_id) :
id(site_id),
percentage(0),
verified(false) {
verified(false),
excluded(0) {
}

ContentSite::~ContentSite() {}

ContentSite::ContentSite(const ContentSite &properties) {
percentage = properties.percentage;
verified = properties.verified;
excluded = properties.excluded;
name = properties.name;
favicon_url = properties.favicon_url;
url = properties.url;
Expand Down
1 change: 1 addition & 0 deletions components/brave_rewards/browser/content_site.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct ContentSite {
std::string id;
double percentage;
bool verified;
int excluded;
std::string name;
std::string favicon_url;
std::string url;
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 @@ -47,6 +47,7 @@ class RewardsService : public KeyedService {
virtual void SolveGrantCaptcha(const std::string& solution) const = 0;
virtual std::string GetWalletPassphrase() const = 0;
virtual void RecoverWallet(const std::string passPhrase) const = 0;
virtual void ExcludePublisher(const std::string publisherKey) const = 0;
virtual void OnLoad(SessionID tab_id, const GURL& gurl) = 0;
virtual void OnUnload(SessionID tab_id) = 0;
virtual void OnShow(SessionID tab_id) = 0;
Expand Down
5 changes: 5 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ ContentSite PublisherInfoToContentSite(
ContentSite content_site(publisher_info.id);
content_site.percentage = publisher_info.percent;
content_site.verified = publisher_info.verified;
content_site.excluded = publisher_info.excluded;
content_site.name = publisher_info.name;
content_site.url = publisher_info.url;
content_site.provider = publisher_info.provider;
Expand Down Expand Up @@ -406,6 +407,10 @@ base::PostTaskAndReplyWithResult(file_task_runner_.get(), FROM_HERE,
AsWeakPtr()));
}

void RewardsServiceImpl::ExcludePublisher(const std::string publisherKey) const {
ledger_->SetPublisherExclude(publisherKey, ledger::PUBLISHER_EXCLUDE::EXCLUDED);
}

void RewardsServiceImpl::OnMediaPublisherInfoSaved(bool success) {
if (!success) {
VLOG(1) << "Error in OnMediaPublisherInfoSaved";
Expand Down
1 change: 1 addition & 0 deletions components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class RewardsServiceImpl : public RewardsService,
const std::string& media_key,
ledger::PublisherInfoCallback callback) override;
void SaveMediaPublisherInfo(const std::string& media_key, const std::string& publisher_id) override;
void ExcludePublisher(const std::string publisherKey) const override;
std::map<std::string, brave_rewards::BalanceReport> GetAllBalanceReports() override;

private:
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 @@ -91,3 +91,7 @@ export const onContributeList = (list: Rewards.Publisher[]) => action(types.ON_C
export const onBalanceReports = (reports: Record<string, Rewards.Report>) => action(types.ON_BALANCE_REPORTS, {
reports
})

export const excludePublisher = (publisherKey: string) => action(types.ON_EXCLUDE_PUBLISHER, {
publisherKey
})
13 changes: 9 additions & 4 deletions components/brave_rewards/ui/components/contributeBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ class ContributeBox extends React.Component<Props, State> {
}
}

getContributeRows = (list: Rewards.Publisher[]) => {
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
if (item.provider) {
Expand All @@ -59,7 +63,7 @@ class ContributeBox extends React.Component<Props, State> {
},
url: item.url,
attention: item.percentage,
onRemove: () => { console.log('remove publisher') }
onRemove: () => { this.actions.excludePublisher(item.name) }
}
})
}
Expand Down Expand Up @@ -177,11 +181,12 @@ class ContributeBox extends React.Component<Props, State> {
reconcileStamp,
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(autoContributeList)
const contributeRows = this.getContributeRows(includedPublishers)
const topRows = contributeRows.slice(0, 5)
const numRows = autoContributeList && autoContributeList.length
const numRows = includedPublishers && includedPublishers.length
const allSites = !(numRows > 5)

return (
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 @@ -29,5 +29,6 @@ export const enum types {
ON_ADDRESSES = '@@rewards/ON_ADDRESSES',
ON_QR_GENERATED = '@@rewards/ON_QR_GENERATED',
ON_CONTRIBUTE_LIST = '@@rewards/ON_CONTRIBUTE_LIST',
ON_BALANCE_REPORTS = '@@rewards/ON_BALANCE_REPORTS'
ON_BALANCE_REPORTS = '@@rewards/ON_BALANCE_REPORTS',
ON_EXCLUDE_PUBLISHER = '@@rewards/ON_EXCLUDE_PUBLISHER'
}
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_EXCLUDE_PUBLISHER:
if (!action.payload.publisherKey) {
break
}
chrome.send('excludePublisher', [action.payload.publisherKey])
break
}

return state
Expand Down
3 changes: 3 additions & 0 deletions components/definitions/rewards.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ declare namespace Rewards {
expiryTime: number
}

export type Excluded = 0 | 1 | 2

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

0 comments on commit d8716b0

Please sign in to comment.