Skip to content

Commit

Permalink
Fixes cache for publisher panel
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Apr 19, 2019
1 parent 930efa7 commit 7d01a06
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,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

0 comments on commit 7d01a06

Please sign in to comment.