diff --git a/components/brave_rewards/browser/publisher_info_database.cc b/components/brave_rewards/browser/publisher_info_database.cc index ecee566af18a..67017c300fb3 100644 --- a/components/brave_rewards/browser/publisher_info_database.cc +++ b/components/brave_rewards/browser/publisher_info_database.cc @@ -276,7 +276,7 @@ bool PublisherInfoDatabase::InsertOrUpdatePublisherInfo( "UPDATE publisher_info SET favIcon = ? " "WHERE publisher_id = ?")); - if (favicon == ledger::_clear_favicon) { + if (favicon == ledger::kClearFavicon) { favicon.clear(); } diff --git a/components/brave_rewards/browser/publisher_info_database_unittest.cc b/components/brave_rewards/browser/publisher_info_database_unittest.cc index d9adbb707237..d2fdec2ba796 100644 --- a/components/brave_rewards/browser/publisher_info_database_unittest.cc +++ b/components/brave_rewards/browser/publisher_info_database_unittest.cc @@ -214,7 +214,7 @@ TEST_F(PublisherInfoDatabaseTest, InsertOrUpdatePublisherInfo) { /** * If favicon is marked as clear, clear it */ - info.favicon_url = ledger::_clear_favicon; + info.favicon_url = ledger::kClearFavicon; success = publisher_info_database_->InsertOrUpdatePublisherInfo(info); EXPECT_TRUE(success); diff --git a/components/brave_rewards/resources/extension/brave_rewards/actions/rewards_panel_actions.ts b/components/brave_rewards/resources/extension/brave_rewards/actions/rewards_panel_actions.ts index 4271871d0136..f2f0136294af 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/actions/rewards_panel_actions.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/actions/rewards_panel_actions.ts @@ -17,10 +17,11 @@ export const onTabId = (tabId: number | undefined) => action(types.ON_TAB_ID, { tabId }) -export const onTabRetrieved = (tab: chrome.tabs.Tab, publisherBlob: string) => action(types.ON_TAB_RETRIEVED, { - tab, - publisherBlob -}) +export const onTabRetrieved = (tab: chrome.tabs.Tab, publisherBlob: string = 'ignore') => + action(types.ON_TAB_RETRIEVED, { + tab, + publisherBlob + }) export const onPublisherData = (windowId: number, publisher: RewardsExtension.Publisher) => action(types.ON_PUBLISHER_DATA, { windowId, diff --git a/components/brave_rewards/resources/extension/brave_rewards/background/api/tabs_api.ts b/components/brave_rewards/resources/extension/brave_rewards/background/api/tabs_api.ts index 9f3ea1af17ae..68e0e67cb330 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/background/api/tabs_api.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/background/api/tabs_api.ts @@ -5,5 +5,5 @@ export const getTabData = (tabId: number) => chrome.tabs.get(tabId, (tab: chrome.tabs.Tab) => { const rewardsPanelActions = require('../actions/rewardsPanelActions').default - rewardsPanelActions.onTabRetrieved(tab, '') + rewardsPanelActions.onTabRetrieved(tab) }) diff --git a/components/brave_rewards/resources/extension/brave_rewards/background/events/tabEvents.ts b/components/brave_rewards/resources/extension/brave_rewards/background/events/tabEvents.ts index 34f38b3b970d..a9d9ae883d54 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/background/events/tabEvents.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/background/events/tabEvents.ts @@ -5,7 +5,7 @@ import rewardsPanelActions from '../actions/rewardsPanelActions' chrome.tabs.onUpdated.addListener((tabId: number, changeInfo: chrome.tabs.TabChangeInfo, tab: chrome.tabs.Tab) => { - rewardsPanelActions.onTabRetrieved(tab, '') + rewardsPanelActions.onTabRetrieved(tab) }) chrome.tabs.onActivated.addListener((activeInfo: chrome.tabs.TabActiveInfo) => { diff --git a/components/brave_rewards/resources/extension/brave_rewards/background/reducers/rewards_panel_reducer.ts b/components/brave_rewards/resources/extension/brave_rewards/background/reducers/rewards_panel_reducer.ts index 1d50fe057b9b..1601dfda237a 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/background/reducers/rewards_panel_reducer.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/background/reducers/rewards_panel_reducer.ts @@ -82,7 +82,7 @@ export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, a const publishers: Record = state.publishers const publisher = publishers[id] - if (!publisher || (publisher && publisher.tabUrl !== tab.url)) { + if (!publisher || (publisher && (publisher.tabUrl !== tab.url || !publisher.publisher_key))) { chrome.braveRewards.getPublisherData( tab.windowId, tab.url, diff --git a/components/brave_rewards/resources/extension/brave_rewards/components/app.tsx b/components/brave_rewards/resources/extension/brave_rewards/components/app.tsx index 329fae0b4a35..b5289910c17d 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/components/app.tsx +++ b/components/brave_rewards/resources/extension/brave_rewards/components/app.tsx @@ -62,7 +62,7 @@ export class RewardsPanel extends React.Component { if (!tabs || !tabs.length) { return } - const pollTwitchPage = (tab: chrome.tabs.Tab, tabId: number, publisherBlob: string) => { + const pollTwitchPage = (tab: chrome.tabs.Tab, tabId: number) => { // use an interval here to monitor when the DOM has finished // generating. clear after the data is present. // Check every second no more than 'limit' times @@ -80,10 +80,9 @@ export class RewardsPanel extends React.Component { code: 'document.body.outerHTML' }, function (result: string[]) { if (result[0].includes(markupMatch) && !result[0].includes(notYetRetrievedMatch)) { - publisherBlob = result[0] clearInterval(interval) const rewardsPanelActions = require('../background/actions/rewardsPanelActions').default - rewardsPanelActions.onTabRetrieved(tab, publisherBlob) + rewardsPanelActions.onTabRetrieved(tab, result[0]) } else { chrome.storage.local.get(['rewards_panel_open'], function (result) { if (result['rewards_panel_open'] === 'false') { @@ -97,7 +96,7 @@ export class RewardsPanel extends React.Component { clearInterval(interval) const rewardsPanelActions = require('../background/actions/rewardsPanelActions').default - rewardsPanelActions.onTabRetrieved(tab, publisherBlob) + rewardsPanelActions.onTabRetrieved(tab, '') } } }) @@ -106,15 +105,14 @@ export class RewardsPanel extends React.Component { } const pollData = (tab: chrome.tabs.Tab, tabId: number, url: URL) => { - let publisherBlob = '' if (url && url.href.startsWith('https://www.twitch.tv/')) { chrome.storage.local.get(['rewards_panel_open'], function (result) { if (result['rewards_panel_open'] === 'true') { - pollTwitchPage(tab, tabId, publisherBlob) + pollTwitchPage(tab, tabId) } }) } else { - this.props.actions.onTabRetrieved(tab, publisherBlob) + this.props.actions.onTabRetrieved(tab, '') } } let tab = tabs[0] @@ -123,10 +121,10 @@ export class RewardsPanel extends React.Component { if (url && url.host.endsWith('.twitch.tv')) { pollData(tab, tab.id, url) } else { - this.props.actions.onTabRetrieved(tab, '') + this.props.actions.onTabRetrieved(tab) } } else { - this.props.actions.onTabRetrieved(tab, '') + this.props.actions.onTabRetrieved(tab) } }) } diff --git a/components/test/brave_rewards/extension/brave_rewards/background/reducers/rewards_panel_reducer_test.ts b/components/test/brave_rewards/extension/brave_rewards/background/reducers/rewards_panel_reducer_test.ts index 1b513ac3e93c..ec9ef86fa8cc 100644 --- a/components/test/brave_rewards/extension/brave_rewards/background/reducers/rewards_panel_reducer_test.ts +++ b/components/test/brave_rewards/extension/brave_rewards/background/reducers/rewards_panel_reducer_test.ts @@ -54,6 +54,7 @@ describe('rewards panel reducer', () => { state.rewardsPanelData.publishers = { id_1: { tabUrl: 'https://clifton.io', + publisher_key: 'clifton.io', name: 'Clifton' } } @@ -65,6 +66,7 @@ describe('rewards panel reducer', () => { publishers: { id_1: { tabUrl: 'https://clifton.io', + publisher_key: 'clifton.io', name: 'Clifton' } } @@ -78,6 +80,61 @@ describe('rewards panel reducer', () => { expect(state.rewardsPanelData).toEqual(expectedState2) }) + it('url is the same, but publisher was not saved correctly', () => { + const initState: Rewards.State = { ...defaultState, walletCreated: true } + const payload = { + tab: { + url: 'https://clifton.io', + incognito: false, + active: true, + windowId: 1 + } + } + + // first visit + const expectedState1: Rewards.State = { + ...defaultState, + walletCreated: true, + publishers: { + id_1: { + tabUrl: 'https://clifton.io' + } + } + } + + let state = reducers({ rewardsPanelData: initState }, { + type: types.ON_TAB_RETRIEVED, + payload + }) + + expect(state.rewardsPanelData).toEqual(expectedState1) + + // imitates ON_PUBLISHER_DATA + state.rewardsPanelData.publishers = { + id_1: { + tabUrl: 'https://clifton.io' + } + } + + // second visit + const expectedState2: Rewards.State = { + ...defaultState, + walletCreated: true, + publishers: { + id_1: { + tabUrl: 'https://clifton.io' + } + } + } + + state = reducers(state, { + type: types.ON_TAB_RETRIEVED, + payload + }) + + expect(state.rewardsPanelData).toEqual(expectedState2) + }) + it('url is not the same', () => { const initState: Rewards.State = { ...defaultState, walletCreated: true } @@ -110,6 +167,7 @@ describe('rewards panel reducer', () => { state.rewardsPanelData.publishers = { id_1: { tabUrl: 'clifton.io', + publisher_key: 'clifton.io', name: 'Clifton' } } diff --git a/vendor/bat-native-ledger/include/bat/ledger/publisher_info.h b/vendor/bat-native-ledger/include/bat/ledger/publisher_info.h index c2480de6d3d7..d27306d381ff 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/publisher_info.h +++ b/vendor/bat-native-ledger/include/bat/ledger/publisher_info.h @@ -15,7 +15,8 @@ namespace ledger { -const char _clear_favicon[] = "clear"; +const char kClearFavicon[] = "clear"; +const char kIgnorePublisherBlob[] = "ignore"; LEDGER_EXPORT enum REWARDS_CATEGORY { AUTO_CONTRIBUTE = 1 << 1, // 2 diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/bat_get_media.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/bat_get_media.cc index 65313062983d..a98b17a706c2 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/bat_get_media.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/bat_get_media.cc @@ -926,6 +926,10 @@ void BatGetMedia::processTwitchMediaPanel( const ledger::VisitData& visit_data, const std::string& providerType, const std::string& publisher_blob) { + if (publisher_blob == ledger::kIgnorePublisherBlob) { + return; + } + if (!publisher_blob.empty()) { std::string media_id = getTwitchMediaIdFromUrl(visit_data, publisher_blob); std::transform(media_id.begin(), @@ -966,10 +970,6 @@ std::string BatGetMedia::getTwitchMediaIdFromUrl( extractData(visit_data.url, "twitch.tv/", "/"); if (visit_data.url.find("twitch.tv/videos/") != std::string::npos) { mediaId = extractData(publisher_blob, - "favicon_url = fav_icon; } } else { - publisher_info->favicon_url = ledger::_clear_favicon; + publisher_info->favicon_url = ledger::kClearFavicon; } publisher_info->name = visit_data.name;