diff --git a/app/components/braveShields/braveShields.tsx b/app/components/braveShields/braveShields.tsx index b5a6266..49dca00 100644 --- a/app/components/braveShields/braveShields.tsx +++ b/app/components/braveShields/braveShields.tsx @@ -27,12 +27,7 @@ export default class BraveShields extends React.Component { + get enabledContent () { + return ( + + {getTotalResourcesBlocked(this.props.tabData)} + + + ) + } + + get disabledContent () { + return ( + + + {getMessage('disabledMessage')} + + ) + } + onToggleShields = (event: React.ChangeEvent) => { const { origin } = this.props.tabData - if (!isHttpOrHttps(origin)) { + if (!isHttpOrHttps(origin) || !event.target) { return } const shieldsOption: BlockOptions = event.target.checked ? 'allow' : 'block' @@ -55,30 +73,12 @@ export default class BraveShieldsHeader extends React.PureComponent - { - enabled - ? {getMessage('enabledMessage')} - : null - } + {enabled ? {getMessage('enabledMessage')} : null} - { - enabled - ? ( - - {getTotalResourcesBlocked(this.props.tabData)} - - - ) - : ( - - - {getMessage('disabledMessage')} - - ) - } + {enabled ? this.enabledContent : this.disabledContent} ) diff --git a/app/components/braveShields/interfaceControls.tsx b/app/components/braveShields/interfaceControls.tsx index 86d6837..836fd1e 100644 --- a/app/components/braveShields/interfaceControls.tsx +++ b/app/components/braveShields/interfaceControls.tsx @@ -25,10 +25,10 @@ export default class InterfaceControls extends React.PureComponent { } onChangeBlockAds = (event: React.ChangeEvent) => { - if (typeof event.target === 'undefined') { + if (!event.target) { return } - const shoudEnableAdsTracks = event.target.checked ? 'allow' : 'block' + const shoudEnableAdsTracks: BlockOptions = event.target.checked ? 'allow' : 'block' this.props.blockAdsTrackers(shoudEnableAdsTracks) } diff --git a/app/components/braveShields/privacyControls.tsx b/app/components/braveShields/privacyControls.tsx index 2d656c0..81fcc8a 100644 --- a/app/components/braveShields/privacyControls.tsx +++ b/app/components/braveShields/privacyControls.tsx @@ -23,21 +23,21 @@ interface Props { export default class PrivacyControls extends React.PureComponent { onChangeCookiesProtection = (event: React.ChangeEvent) => { - if (typeof event.target === 'undefined') { + if (!event.target) { return } this.props.blockCookies(event.target.value) } onChangeJavaScriptProtection = (event: React.ChangeEvent) => { - if (typeof event.target === 'undefined') { + if (!event.target) { return } this.props.blockJavaScript(event.target.value) } onChangeFingerprintingProtection = (event: React.ChangeEvent) => { - if (typeof event.target === 'undefined') { + if (!event.target) { return } this.props.blockFingerprinting(event.target.value) diff --git a/app/helpers/shieldsUtils.ts b/app/helpers/shieldsUtils.ts index bdde095..cd8977d 100644 --- a/app/helpers/shieldsUtils.ts +++ b/app/helpers/shieldsUtils.ts @@ -5,7 +5,7 @@ import { Tab } from '../types/state/shieldsPannelState' export const getTotalResourcesBlocked = (tabData: Partial) => { - if (typeof tabData === 'undefined') { + if (!tabData) { return 0 } return ( diff --git a/app/types/other/blockTypes.ts b/app/types/other/blockTypes.ts index 8254a98..d4bc0ad 100644 --- a/app/types/other/blockTypes.ts +++ b/app/types/other/blockTypes.ts @@ -6,4 +6,4 @@ export type BlockTypes = 'ads' | 'trackers' | 'httpUpgradableResources' | 'javas export type BlockOptions = 'allow' | 'block' export type BlockFPOptions = 'allow' | 'block' | 'block_third_party' export type BlockCookiesOptions = 'allow' | 'block' | 'block_third_party' -export type BlockJSOptions = 'allow' | 'block' | 'block_third_party' \ No newline at end of file +export type BlockJSOptions = 'allow' | 'block' | 'block_third_party'