Skip to content

Commit

Permalink
Fixes panel not clearing after a switch
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Oct 24, 2018
1 parent 97a1081 commit e88e385
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 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@201a814e36dec9e4eca7c9c7a7f5c8d0f1f5be16",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@9a4d0e00d78343de8863d60657727ae4eb5d6321",
"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@adeff3254bb90ccdc9699040d5a4e1cd6b8393b7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ function setBadgeText (state: RewardsExtension.State): void {
})
}

const getWindowId = (id: number) => {
return `id_${id}`
}

const getNotificationId = (id: number) => {
return `n_${id}`
}

export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, action: any) => {
if (state === undefined) {
state = storage.load()
Expand Down Expand Up @@ -59,14 +67,22 @@ export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, a
break
}

state = { ...state }
chrome.braveRewards.getPublisherData(tab.windowId, tab.url, tab.favIconUrl || '')
const id = getWindowId(tab.windowId)
let publishers: Record<string, RewardsExtension.Publisher> = state.publishers
if (publishers[id]) {
delete publishers[id]
}
state = {
...state,
publishers
}
break
case types.ON_PUBLISHER_DATA:
{
const publisher = payload.publisher
let publishers: Record<string, RewardsExtension.Publisher> = state.publishers
const id = `id_${payload.windowId}`
const id = getWindowId(payload.windowId)

if (publisher && !publisher.publisher_key) {
delete publishers[id]
Expand Down Expand Up @@ -104,7 +120,7 @@ export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, a
return
}

const id = `n_${payload.id}`
const id = getNotificationId(payload.id)
let notifications: Record<number, RewardsExtension.Notification> = state.notifications

if (!notifications) {
Expand Down Expand Up @@ -142,7 +158,7 @@ export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, a
return
}

const id = `n_${payload.id}`
const id = getNotificationId(payload.id)
let notifications: Record<number, RewardsExtension.Notification> = state.notifications
delete notifications[id]

Expand Down

0 comments on commit e88e385

Please sign in to comment.