Skip to content

Commit

Permalink
Merge pull request #1526 from brave/panel-ac-61
Browse files Browse the repository at this point in the history
Hide AC options in the panel if AC if off
  • Loading branch information
NejcZdovc authored Jan 31, 2019
2 parents b898f8d + 7f0be87 commit 3de131a
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 6 deletions.
24 changes: 24 additions & 0 deletions browser/extensions/api/brave_rewards_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,29 @@ ExtensionFunction::ResponseAction BraveRewardsSaveAdsSettingFunction::Run() {
return RespondNow(NoArguments());
}

BraveRewardsGetACEnabledFunction::
~BraveRewardsGetACEnabledFunction() {
}

ExtensionFunction::ResponseAction
BraveRewardsGetACEnabledFunction::Run() {
Profile* profile = Profile::FromBrowserContext(browser_context());
RewardsService* rewards_service_ =
RewardsServiceFactory::GetForProfile(profile);

if (!rewards_service_) {
return RespondNow(Error("Rewards service is not initialized"));
}

rewards_service_->GetAutoContribute(base::Bind(
&BraveRewardsGetACEnabledFunction::OnGetACEnabled,
this));
return RespondLater();
}

void BraveRewardsGetACEnabledFunction::OnGetACEnabled(bool enabled) {
Respond(OneArgument(std::make_unique<base::Value>(enabled)));
}

} // namespace api
} // namespace extensions
13 changes: 13 additions & 0 deletions browser/extensions/api/brave_rewards_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ class BraveRewardsSaveAdsSettingFunction : public UIThreadExtensionFunction {
ResponseAction Run() override;
};

class BraveRewardsGetACEnabledFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("braveRewards.getACEnabled", UNKNOWN)

protected:
~BraveRewardsGetACEnabledFunction() override;

ResponseAction Run() override;

private:
void OnGetACEnabled(bool enabled);
};

} // namespace api
} // namespace extensions

Expand Down
17 changes: 17 additions & 0 deletions common/extensions/api/brave_rewards.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,23 @@
}
]
},
{
"name": "getACEnabled",
"type": "function",
"description": "Gets whether auto contribute is enabled",
"parameters": [
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "enabled",
"type": "boolean"
}
]
}
]
},
{
"name": "saveAdsSetting",
"type": "function",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ export const OnPendingContributionsTotal = (amount: number) => action(types.ON_P
export const onEnabledMain = (enabledMain: boolean) => action(types.ON_ENABLED_MAIN, {
enabledMain
})

export const onEnabledAC = (enabled: boolean) => action(types.ON_ENABLED_AC, {
enabled
})
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, a
state.enabledMain = payload.enabledMain
break
}
case types.ON_ENABLED_AC:
{
if (payload.enabled == null) {
break
}
state.enabledAC = payload.enabled
break
}
}

return state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const defaultState: RewardsExtension.State = {
notifications: {},
currentNotification: undefined,
pendingContributionTotal: 0,
enabledMain: false
enabledMain: false,
enabledAC: false
}

const cleanData = (state: RewardsExtension.State) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export class RewardsPanel extends React.Component<Props, State> {
chrome.braveRewards.getRewardsMainEnabled(((enabled: boolean) => {
this.props.actions.onEnabledMain(enabled)
}))
chrome.braveRewards.getACEnabled(((enabled: boolean) => {
this.props.actions.onEnabledAC(enabled)
}))
}

componentDidUpdate (prevProps: Props, prevState: State) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class Panel extends React.Component<Props, State> {
}

render () {
const { grant, pendingContributionTotal } = this.props.rewardsPanelData
const { grant, pendingContributionTotal, enabledAC } = this.props.rewardsPanelData
const { balance, rates, grants } = this.props.rewardsPanelData.walletProperties
const publisher: RewardsExtension.Publisher | undefined = this.getPublisher()
const converted = utils.convertBalance(balance.toString(), rates)
Expand Down Expand Up @@ -357,6 +357,7 @@ export class Panel extends React.Component<Props, State> {
onAmountChange={this.doNothing}
onIncludeInAuto={this.switchAutoContribute}
showUnVerified={!publisher.verified}
acEnabled={enabledAC}
moreLink={'https://brave.com/faq-rewards/#unclaimed-funds'}
/>
: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export const enum types {
ON_GRANT_DELETE = '@@rewards_panel/ON_GRANT_DELETE',
ON_GRANT_FINISH = '@@rewards_panel/ON_GRANT_FINISH',
ON_PENDING_CONTRIBUTIONS_TOTAL = '@@rewards_panel/ON_PENDING_CONTRIBUTIONS_TOTAL',
ON_ENABLED_MAIN = '@@rewards_panel/ON_ENABLED_MAIN'
ON_ENABLED_MAIN = '@@rewards_panel/ON_ENABLED_MAIN',
ON_ENABLED_AC = '@@rewards_panel/ON_ENABLED_AC'
}

// Note: This declaration must match the RewardsNotificationType enum in
Expand Down
1 change: 1 addition & 0 deletions components/definitions/chromel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ declare namespace chrome.braveRewards {
const onWalletFailed: {
addListener: (callback: () => void) => void
}
const getACEnabled: (callback: (enabled: boolean) => void) => {}
}

declare namespace chrome.rewardsNotifications {
Expand Down
1 change: 1 addition & 0 deletions components/definitions/rewardsExtensions.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
declare namespace RewardsExtension {
interface State {
currentNotification?: string
enabledAC: boolean
enabledMain: boolean
notifications: Record<number, Notification>
publishers: Record<string, Publisher>
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 @@ -273,7 +273,7 @@
"@types/react-dom": "^16.0.7",
"@types/react-redux": "6.0.4",
"awesome-typescript-loader": "^5.2.0",
"brave-ui": "github:brave/brave-ui#c46dbea2ad970f5b01c66a87a588379b2871e298",
"brave-ui": "github:brave/brave-ui#844d6b067596f6863f834a8de4921333e832cad0",
"css-loader": "^0.28.9",
"csstype": "^2.5.5",
"emptykit.css": "^1.0.1",
Expand Down

0 comments on commit 3de131a

Please sign in to comment.