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

Fixes cache for publisher panel (uplift to 0.64.x) #2298

Merged
merged 1 commit into from
Apr 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, a
const id = getWindowId(tab.windowId)
const publishers: Record<string, RewardsExtension.Publisher> = state.publishers
const publisher = publishers[id]
const validKey = publisher && publisher.publisher_key && publisher.publisher_key.length > 0

if (!publisher || (publisher && publisher.tabUrl !== tab.url)) {
if (!publisher || (publisher && (publisher.tabUrl !== tab.url || !validKey))) {
chrome.braveRewards.getPublisherData(
tab.windowId,
tab.url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ describe('rewards panel reducer', () => {
state.rewardsPanelData.publishers = {
id_1: {
tabUrl: 'https://clifton.io',
name: 'Clifton'
name: 'Clifton',
publisher_key: 'clifton.io'
}
}

Expand All @@ -71,7 +72,8 @@ describe('rewards panel reducer', () => {
publishers: {
id_1: {
tabUrl: 'https://clifton.io',
name: 'Clifton'
name: 'Clifton',
publisher_key: 'clifton.io'
}
}
}
Expand Down Expand Up @@ -120,8 +122,9 @@ describe('rewards panel reducer', () => {
// imitates ON_PUBLISHER_DATA
state.rewardsPanelData.publishers = {
id_1: {
tabUrl: 'clifton.io',
name: 'Clifton'
tabUrl: 'https://clifton.io',
name: 'Clifton',
publisher_key: 'clifton.io'
}
}

Expand Down Expand Up @@ -179,6 +182,45 @@ describe('rewards panel reducer', () => {

expect(state.rewardsPanelData).toEqual(expectedState)
})

it('publisher is empty', () => {
const initState: Rewards.State = {
...defaultState,
walletCreated: true,
enabledMain: true,
publishers: {
id_1: {
tabUrl: 'clifton.io',
random: 'I need to vanish'
}
}
}

const expectedState: Rewards.State = {
...defaultState,
walletCreated: true,
enabledMain: true,
publishers: {
id_1: {
tabUrl: 'https://clifton.io'
}
}
}

let state = reducers({ rewardsPanelData: initState }, {
type: types.ON_TAB_RETRIEVED,
payload: {
tab: {
url: 'https://clifton.io',
incognito: false,
active: true,
windowId: 1
}
}
})

expect(state.rewardsPanelData).toEqual(expectedState)
})
})
})

Expand Down