Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
wip - debugging

wip -

wip -

wip - include_switch

linting

clean up debugging

Brackets for reducer switch case

clean up debug lines

linting for CI
  • Loading branch information
Jason Sadler authored and NejcZdovc committed Oct 23, 2018
1 parent ca89164 commit 9c465b6
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 3 deletions.
19 changes: 19 additions & 0 deletions browser/extensions/api/brave_rewards_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ ExtensionFunction::ResponseAction BraveRewardsDonateToSiteFunction::Run() {
BraveRewardsGetPublisherDataFunction::~BraveRewardsGetPublisherDataFunction() {
}

BraveRewardsIncludeInAutoContributionFunction::
~BraveRewardsIncludeInAutoContributionFunction() {
}

ExtensionFunction::ResponseAction
BraveRewardsIncludeInAutoContributionFunction::Run() {

std::unique_ptr<brave_rewards::IncludeInAutoContribution::Params> params(
brave_rewards::IncludeInAutoContribution::Params::Create(*args_));
Profile* profile = Profile::FromBrowserContext(browser_context());
RewardsService* rewards_service_ =
RewardsServiceFactory::GetForProfile(profile);
if (rewards_service_) {
rewards_service_->SetContributionAutoInclude(
params->publisher_key, params->excluded);
}
return RespondNow(NoArguments());
}

ExtensionFunction::ResponseAction BraveRewardsGetPublisherDataFunction::Run() {
std::unique_ptr<brave_rewards::GetPublisherData::Params> params(
brave_rewards::GetPublisherData::Params::Create(*args_));
Expand Down
11 changes: 11 additions & 0 deletions browser/extensions/api/brave_rewards_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ class BraveRewardsGetCurrentReportFunction : public UIThreadExtensionFunction {
ResponseAction Run() override;
};

class BraveRewardsIncludeInAutoContributionFunction :
public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("braveRewards.includeInAutoContribution", UNKNOWN)

protected:
~BraveRewardsIncludeInAutoContributionFunction() override;

ResponseAction Run() override;
};

} // namespace api
} // namespace extensions

Expand Down
2 changes: 1 addition & 1 deletion common/extensions/api/brave_rewards.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,4 @@
}
]
}
]
]
2 changes: 2 additions & 0 deletions components/brave_rewards/browser/rewards_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class RewardsService : public KeyedService {
virtual void RemoveRecurring(const std::string& publisher_key) = 0;
virtual void UpdateRecurringDonationsList() = 0;
virtual void UpdateTipsList() = 0;
virtual void SetContributionAutoInclude(
std::string publisher_key, bool excluded) = 0;

void AddObserver(RewardsServiceObserver* observer);
void RemoveObserver(RewardsServiceObserver* observer);
Expand Down
6 changes: 6 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1573,4 +1573,10 @@ void RewardsServiceImpl::OnRemoveRecurring(const std::string& publisher_key,
AsWeakPtr(), callback));
}

void RewardsServiceImpl::SetContributionAutoInclude(std::string publisher_key,
bool excluded) {
ledger_->SetPublisherExclude(publisher_key, excluded ?
ledger::PUBLISHER_EXCLUDE::EXCLUDED : ledger::PUBLISHER_EXCLUDE::INCLUDED);
}

} // namespace brave_rewards
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 @@ -110,6 +110,8 @@ class RewardsServiceImpl : public RewardsService,
void RemoveRecurring(const std::string& publisher_key) override;
void UpdateRecurringDonationsList() override;
void UpdateTipsList() override;
void SetContributionAutoInclude(
std::string publisher_key, bool excluded) override;

private:
friend void RunIOTaskCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ export const onNotificationDeleted = (id: number, type: number, timestamp: numbe
export const deleteNotification = (id: number) => action(types.DELETE_NOTIFICATION, {
id
})

export const includeInAutoContribution = (publisherKey: string, excluded: boolean) => action(types.INCLUDE_IN_AUTO_CONTRIBUTION, {
publisherKey,
excluded
})
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, a
setBadgeText(state)
break
}
case types.INCLUDE_IN_AUTO_CONTRIBUTION:
{
let publisherKey = payload.publisherKey
let excluded = payload.excluded
chrome.braveRewards.includeInAutoContribution(publisherKey, excluded)
break
}
}

if (state !== startingState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ export class Panel extends React.Component<Props, State> {
console.log('doNothing click')
}

switchAutoContribute = () => {
const publisher: RewardsExtension.Publisher | undefined = this.getPublisher()
const publisherKey = publisher && publisher.publisher_key
const excluded = publisher && publisher.excluded
if (publisherKey && publisherKey.length > 0 && excluded !== undefined) {
this.props.actions.includeInAutoContribution(publisherKey, !excluded)
}
}

getPublisher = () => {
let windowId = this.props.windowId.toString()

Expand Down Expand Up @@ -251,7 +260,7 @@ export class Panel extends React.Component<Props, State> {
onToggleTips={this.doNothing}
donationAction={this.showDonateToSiteDetail}
onAmountChange={this.doNothing}
onIncludeInAuto={this.doNothing}
onIncludeInAuto={this.switchAutoContribute}
/>
: null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export const enum types {
ON_CURRENT_REPORT = '@@rewards_panel/ON_CURRENT_REPORT',
ON_NOTIFICATION_ADDED = '@@rewards_panel/ON_NOTIFICATION_ADDED',
ON_NOTIFICATION_DELETED = '@@rewards_panel/ON_NOTIFICATION_DELETED',
DELETE_NOTIFICATION = '@@rewards_panel/DELETE_NOTIFICATION'
DELETE_NOTIFICATION = '@@rewards_panel/DELETE_NOTIFICATION',
INCLUDE_IN_AUTO_CONTRIBUTION = '@@rewards_panel/INCLUDE_IN_AUTO_CONTRIBUTION'
}
1 change: 1 addition & 0 deletions components/definitions/chromel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ declare namespace chrome.braveRewards {
const onCurrentReport: {
addListener: (callback: (properties: RewardsExtension.Report) => void) => void
}
const includeInAutoContribution: (publisherKey: string, excluded: boolean) => {}
}

declare namespace chrome.rewardsNotifications {
Expand Down

0 comments on commit 9c465b6

Please sign in to comment.