Skip to content

Commit

Permalink
New Tab Page WebUI: Fix rewards widget thinks ads are off when reward…
Browse files Browse the repository at this point in the history
…s are re-enabled

Fix brave/brave-browser#7807
  • Loading branch information
petemill committed Jan 22, 2020
1 parent 0cc1ecd commit 893a353
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 21 deletions.
10 changes: 3 additions & 7 deletions components/brave_new_tab_ui/actions/new_tab_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,15 @@ export const setInitialData = (initialData: InitialData) =>

export const createWallet = () => action(types.CREATE_WALLET, {})

export const onEnabledMain = (enabledMain: boolean) => action(types.ON_ENABLED_MAIN, {
enabledMain
export const onEnabledMain = (enabledMain: boolean, enabledAds?: boolean) => action(types.ON_ENABLED_MAIN, {
enabledMain,
enabledAds
})

export const onAdsEnabled = (enabled: boolean) => action(types.ON_ADS_ENABLED, {
enabled
})

export const onRewardsSettingSave = (key: string, value: any) => action(types.ON_REWARDS_SETTING_SAVE, {
key,
value
})

export const onWalletInitialized = (result: NewTab.RewardsResult) => action(types.ON_WALLET_INITIALIZED, {
result
})
Expand Down
4 changes: 3 additions & 1 deletion components/brave_new_tab_ui/apiEventsToStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ chrome.braveRewards.onWalletInitialized.addListener((result: any | NewTab.Reward
})

chrome.braveRewards.onEnabledMain.addListener((enabledMain: boolean) => {
getActions().onEnabledMain(enabledMain)
chrome.braveRewards.getAdsEnabled((enabledAds: boolean) => {
getActions().onEnabledMain(enabledMain, enabledAds)
})
})

chrome.braveRewards.onAdsEnabled.addListener((enabled: boolean) => {
Expand Down
1 change: 0 additions & 1 deletion components/brave_new_tab_ui/constants/new_tab_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const enum types {
ON_ADS_ENABLED = '@@newtab/ON_ADS_ENABLED',
ON_ADS_ESTIMATED_EARNINGS = '@@newtab/ON_ADS_ESTIMATED_EARNINGS',
ON_ENABLED_MAIN = '@@newtab/ON_ENABLED_MAIN',
ON_REWARDS_SETTING_SAVE = '@@newtab_panel/ON_SETTING_SAVE',
ON_WALLET_INITIALIZED = '@@newtab/ON_WALLET_INITIALIZED',
ON_BALANCE_REPORT = '@@newtab/ON_BALANCE_REPORT',
ON_PROMOTIONS = '@@newtab/ON_PROMOTIONS',
Expand Down
2 changes: 1 addition & 1 deletion components/brave_new_tab_ui/containers/newTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class NewTabPage extends React.Component<Props, State> {
}

enableRewards = () => {
this.props.actions.onRewardsSettingSave('enabledMain', '1')
chrome.braveRewards.saveSetting('enabledMain', '1')
}

createWallet = () => {
Expand Down
14 changes: 3 additions & 11 deletions components/brave_new_tab_ui/reducers/new_tab_reducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ export const newTabReducer: Reducer<NewTab.State | undefined> = (state: NewTab.S
case types.ON_ENABLED_MAIN:
state = { ...state }
state.rewardsState.enabledMain = payload.enabledMain
if (payload.enabledAds !== undefined) {
state.rewardsState.enabledAds = payload.enabledAds
}
break

case types.ON_WALLET_INITIALIZED: {
Expand Down Expand Up @@ -302,17 +305,6 @@ export const newTabReducer: Reducer<NewTab.State | undefined> = (state: NewTab.S
break
}

case types.ON_REWARDS_SETTING_SAVE:
const key = action.payload.key
const value = action.payload.value

if (key) {
state = { ...state }
state.rewardsState[key] = !!value
chrome.braveRewards.saveSetting(key, value)
}
break

case types.ON_ADS_ENABLED:
state = { ...state }
state.rewardsState.enabledAds = payload.enabled
Expand Down

0 comments on commit 893a353

Please sign in to comment.