Skip to content
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

Hide AC options in the panel if AC if off #1526

Merged
merged 1 commit into from
Jan 31, 2019
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
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