-
Notifications
You must be signed in to change notification settings - Fork 896
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds different logo for verified publishers
Resolves brave/brave-browser#4043
- Loading branch information
Showing
12 changed files
with
266 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,16 +18,14 @@ transpile_web_ui("brave_rewards_panel") { | |
"background/reducers/grant_panel_reducer.ts", | ||
"background/reducers/index.ts", | ||
"background/reducers/rewards_panel_reducer.ts", | ||
"background/browserAction.ts", | ||
"background/storage.ts", | ||
"background/store.ts", | ||
"brave_rewards_panel.html", | ||
"brave_rewards_panel.tsx", | ||
"components/app.tsx", | ||
"components/panel.tsx", | ||
"constants/rewards_panel_types.ts", | ||
"img/rewards-off.png", | ||
"img/[email protected]", | ||
"img/[email protected]", | ||
"img/rewards-on.png", | ||
"img/[email protected]", | ||
"img/[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,14 @@ | |
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import rewardsPanelActions from './background/actions/rewardsPanelActions' | ||
|
||
import './background/store' | ||
import './background/events/rewardsEvents' | ||
import './background/events/tabEvents' | ||
import batIconOn18Url from './img/rewards-on.png' | ||
import batIconOn36Url from './img/[email protected]' | ||
import batIconOn54Url from './img/[email protected]' | ||
// TODO: display 'off' icon at appropriate time | ||
// import batIconOff18Url from './img/rewards-off.png' | ||
// import batIconOff36Url from './img/[email protected]' | ||
// import batIconOff54Url from './img/[email protected]' | ||
|
||
const iconOn = { | ||
path: { | ||
|
@@ -21,17 +19,20 @@ const iconOn = { | |
} | ||
} | ||
|
||
// const iconOff = { | ||
// path: { | ||
// 18: batIconOff18Url, | ||
// 36: batIconOff36Url, | ||
// 54: batIconOff54Url | ||
// } | ||
// } | ||
|
||
chrome.browserAction.setBadgeBackgroundColor({ color: '#FB542B' }) | ||
chrome.browserAction.setIcon(iconOn) | ||
|
||
// We need to set initial state for all active tabs in all windows | ||
chrome.tabs.query({ | ||
highlighted: true | ||
}, (tabs) => { | ||
if (!tabs || !tabs.length) { | ||
return | ||
} | ||
|
||
rewardsPanelActions.init(tabs) | ||
}) | ||
|
||
chrome.runtime.onInstalled.addListener(function (details) { | ||
if (details.reason === 'install') { | ||
const initialNotificationDismissed = 'false' | ||
|
41 changes: 41 additions & 0 deletions
41
components/brave_rewards/resources/extension/brave_rewards/background/browserAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* Copyright (c) 2019 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
export const setBadgeText = (state?: RewardsExtension.State, verified: boolean = false, tabId: number = -1) => { | ||
let text = '' | ||
|
||
if (!state) { | ||
return | ||
} | ||
|
||
if (state.notifications && !verified) { | ||
const count = Object.keys(state.notifications).length | ||
if (count > 0) { | ||
text = count.toString() | ||
} | ||
} | ||
|
||
let data: chrome.browserAction.BadgeTextDetails = { | ||
text | ||
} | ||
|
||
if (tabId !== -1) { | ||
data.tabId = tabId | ||
chrome.browserAction.setBadgeBackgroundColor({ | ||
color: verified ? '#4C54D2' : '#FB542B', | ||
tabId | ||
}) | ||
|
||
if (verified) { | ||
data.text = '✓️' | ||
} | ||
} else { | ||
chrome.browserAction.setBadgeBackgroundColor({ | ||
color: '#FB542B' | ||
}) | ||
} | ||
|
||
chrome.browserAction.setBadgeText(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-627 Bytes
components/brave_rewards/resources/extension/brave_rewards/img/rewards-off.png
Binary file not shown.
Binary file removed
BIN
-1.26 KB
components/brave_rewards/resources/extension/brave_rewards/img/[email protected]
Binary file not shown.
Binary file removed
BIN
-1.91 KB
components/brave_rewards/resources/extension/brave_rewards/img/[email protected]
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
components/test/brave_rewards/extension/brave_rewards/background/browserAction_test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* global describe, it */ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { | ||
setBadgeText | ||
} from '../../../../../brave_rewards/resources/extension/brave_rewards/background/browserAction' | ||
|
||
describe('Rewards Panel extension - Browser Action', () => { | ||
describe('setBadgeText', () => { | ||
let spyText: jest.SpyInstance | ||
let spyColor: jest.SpyInstance | ||
|
||
beforeEach(() => { | ||
spyText = jest.spyOn(chrome.browserAction, 'setBadgeText') | ||
spyColor = jest.spyOn(chrome.browserAction, 'setBadgeBackgroundColor') | ||
}) | ||
|
||
afterEach(() => { | ||
spyText.mockRestore() | ||
spyColor.mockRestore() | ||
}) | ||
|
||
it('publisher is not verified, no pending notifications', () => { | ||
const state: RewardsExtension.State = { | ||
notifications: {} | ||
} | ||
|
||
setBadgeText(state) | ||
|
||
expect(spyText).toHaveBeenCalled() | ||
expect(spyText.mock.calls[0][0]).toEqual({ | ||
text: '' | ||
}) | ||
}) | ||
|
||
it('publisher is not verified, pending notifications', () => { | ||
const state: RewardsExtension.State = { | ||
notifications: { | ||
'1': { | ||
id: 'test' | ||
} | ||
} | ||
} | ||
|
||
setBadgeText(state) | ||
|
||
expect(spyText).toHaveBeenCalled() | ||
expect(spyText.mock.calls[0][0]).toEqual({ | ||
text: '1' | ||
}) | ||
}) | ||
|
||
it('publisher is verified, no pending notifications', () => { | ||
const state: RewardsExtension.State = { | ||
notifications: {} | ||
} | ||
|
||
setBadgeText(state, true, 1) | ||
|
||
expect(spyText).toHaveBeenCalled() | ||
const data = spyText.mock.calls[0][0] | ||
expect(data.tabId).toEqual(1) | ||
expect(data.text).toEqual('✓️') | ||
|
||
expect(spyColor).toHaveBeenCalled() | ||
expect(spyColor.mock.calls[0][0]).toEqual({ | ||
color: '#4C54D2', | ||
tabId: 1 | ||
}) | ||
}) | ||
|
||
it('publisher is verified, pending notifications', () => { | ||
const state: RewardsExtension.State = { | ||
notifications: { | ||
'1': { | ||
id: 'test' | ||
} | ||
} | ||
} | ||
|
||
setBadgeText(state, true, 1) | ||
|
||
expect(spyText).toHaveBeenCalled() | ||
const data = spyText.mock.calls[0][0] | ||
expect(data.tabId).toEqual(1) | ||
expect(data.text).toEqual('✓️') | ||
|
||
expect(spyColor).toHaveBeenCalled() | ||
expect(spyColor.mock.calls[0][0]).toEqual({ | ||
color: '#4C54D2', | ||
tabId: 1 | ||
}) | ||
}) | ||
|
||
it('publisher is not verified with tabId, pending notifications', () => { | ||
const state: RewardsExtension.State = { | ||
notifications: { | ||
'1': { | ||
id: 'test' | ||
} | ||
} | ||
} | ||
|
||
setBadgeText(state, false, 1) | ||
|
||
expect(spyText).toHaveBeenCalled() | ||
expect(spyText.mock.calls[0][0]).toEqual({ | ||
text: '1', | ||
tabId: 1 | ||
}) | ||
|
||
expect(spyColor).toHaveBeenCalled() | ||
expect(spyColor.mock.calls[0][0]).toEqual({ | ||
color: '#FB542B', | ||
tabId: 1 | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters