From dd911ba5bda7cb18111b11e763cf72b8312fe08a Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 24 Jan 2020 15:12:58 -0400 Subject: [PATCH] Remove unnecessary get environment type parameter (#7891) * Remove unnecessary `getEnvironmentType` parameter The default value of the first parameter is `window.location.href`, so there is no need to pass it in explicitly. * Remove junk parameter from `getEnvironmentType` invocation `getEnvironmentType` doesn't need to be passed any parameter, as the default value is `window.location.href` which is generally what is wanted. In this case, the variable `location.href` was always `undefined` anyway. This particular `location` variable is from React Router, and does not have an `href` property. * Fix comment for `getEnvironmentType` One of the possible return values was referred to by the wrong name. --- app/scripts/lib/util.js | 2 +- app/scripts/phishing-detect.js | 2 +- app/scripts/ui.js | 2 +- .../account-menu/account-menu.component.js | 5 +---- ui/app/components/app/modals/modal.js | 15 +++----------- .../signature-request-original.component.js | 8 ++------ .../signature-request.component.js | 4 +--- .../transaction-list-item.component.js | 3 +-- ui/app/ducks/metamask/metamask.js | 3 +-- .../confirm-transaction-base.component.js | 8 ++------ ui/app/pages/home/home.container.js | 3 +-- .../permissions-connect.component.js | 20 +++++-------------- ui/app/pages/settings/settings.container.js | 3 +-- .../unlock-page/unlock-page.container.js | 2 +- ui/lib/webcam-utils.js | 3 +-- 15 files changed, 23 insertions(+), 60 deletions(-) diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js index 39d95be2726d..6b883211e080 100644 --- a/app/scripts/lib/util.js +++ b/app/scripts/lib/util.js @@ -18,7 +18,7 @@ import { /** * Used to determine the window type through which the app is being viewed. * - 'popup' refers to the extension opened through the browser app icon (in top right corner in chrome and firefox) - * - 'responsive' refers to the main browser window + * - 'fullscreen' refers to the main browser window * - 'notification' refers to the popup that appears in its own window when taking action outside of metamask * - 'background' refers to the background page * diff --git a/app/scripts/phishing-detect.js b/app/scripts/phishing-detect.js index 2abd06867ff2..f94454f4452e 100644 --- a/app/scripts/phishing-detect.js +++ b/app/scripts/phishing-detect.js @@ -10,7 +10,7 @@ import ExtensionPlatform from './platforms/extension' document.addEventListener('DOMContentLoaded', start) function start () { - const windowType = getEnvironmentType(window.location.href) + const windowType = getEnvironmentType() const hash = window.location.hash.substring(1) const suspect = querystring.parse(hash) diff --git a/app/scripts/ui.js b/app/scripts/ui.js index f22020a5d838..d980402d07de 100644 --- a/app/scripts/ui.js +++ b/app/scripts/ui.js @@ -48,7 +48,7 @@ async function start () { } // identify window type (popup, notification) - const windowType = getEnvironmentType(window.location.href) + const windowType = getEnvironmentType() global.METAMASK_UI_TYPE = windowType closePopupIfOpen(windowType) diff --git a/ui/app/components/app/account-menu/account-menu.component.js b/ui/app/components/app/account-menu/account-menu.component.js index cea59fb807b1..f11b73cafded 100644 --- a/ui/app/components/app/account-menu/account-menu.component.js +++ b/ui/app/components/app/account-menu/account-menu.component.js @@ -389,10 +389,7 @@ export default class AccountMenu extends Component { name: 'Clicked Connect Hardware', }, }) - if ( - getEnvironmentType(window.location.href) === - ENVIRONMENT_TYPE_POPUP - ) { + if (getEnvironmentType() === ENVIRONMENT_TYPE_POPUP) { global.platform.openExtensionInBrowser(CONNECT_HARDWARE_ROUTE) } else { history.push(CONNECT_HARDWARE_ROUTE) diff --git a/ui/app/components/app/modals/modal.js b/ui/app/components/app/modals/modal.js index afc7995049f4..4252795fb2d7 100644 --- a/ui/app/components/app/modals/modal.js +++ b/ui/app/components/app/modals/modal.js @@ -236,10 +236,7 @@ const MODALS = { contents: , mobileModalStyle: { width: '95%', - top: - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP - ? '52vh' - : '36.5vh', + top: getEnvironmentType() === ENVIRONMENT_TYPE_POPUP ? '52vh' : '36.5vh', }, laptopModalStyle: { width: '449px', @@ -273,10 +270,7 @@ const MODALS = { ), mobileModalStyle: { width: '95%', - top: - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP - ? '52vh' - : '36.5vh', + top: getEnvironmentType() === ENVIRONMENT_TYPE_POPUP ? '52vh' : '36.5vh', }, laptopModalStyle: { width: '449px', @@ -290,10 +284,7 @@ const MODALS = { ), mobileModalStyle: { width: '95%', - top: - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP - ? '52vh' - : '36.5vh', + top: getEnvironmentType() === ENVIRONMENT_TYPE_POPUP ? '52vh' : '36.5vh', }, laptopModalStyle: { width: '449px', diff --git a/ui/app/components/app/signature-request-original/signature-request-original.component.js b/ui/app/components/app/signature-request-original/signature-request-original.component.js index 4a217b23e62a..930559fc23fb 100644 --- a/ui/app/components/app/signature-request-original/signature-request-original.component.js +++ b/ui/app/components/app/signature-request-original/signature-request-original.component.js @@ -35,9 +35,7 @@ export default class SignatureRequestOriginal extends Component { } componentDidMount = () => { - if ( - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION - ) { + if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) { window.addEventListener('beforeunload', this._beforeUnload) } } @@ -61,9 +59,7 @@ export default class SignatureRequestOriginal extends Component { } _removeBeforeUnload = () => { - if ( - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION - ) { + if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) { window.removeEventListener('beforeunload', this._beforeUnload) } } diff --git a/ui/app/components/app/signature-request/signature-request.component.js b/ui/app/components/app/signature-request/signature-request.component.js index c536527e3a17..15d439a79d0f 100644 --- a/ui/app/components/app/signature-request/signature-request.component.js +++ b/ui/app/components/app/signature-request/signature-request.component.js @@ -29,9 +29,7 @@ export default class SignatureRequest extends PureComponent { componentDidMount () { const { clearConfirmTransaction, cancel } = this.props const { metricsEvent } = this.context - if ( - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION - ) { + if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) { window.addEventListener('beforeunload', event => { metricsEvent({ eventOpts: { diff --git a/ui/app/components/app/transaction-list-item/transaction-list-item.component.js b/ui/app/components/app/transaction-list-item/transaction-list-item.component.js index 99f2c2d0719c..1dfbca5a022f 100644 --- a/ui/app/components/app/transaction-list-item/transaction-list-item.component.js +++ b/ui/app/components/app/transaction-list-item/transaction-list-item.component.js @@ -202,8 +202,7 @@ export default class TransactionListItem extends PureComponent { txParams.to : txParams.to - const isFullScreen = - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_FULLSCREEN + const isFullScreen = getEnvironmentType() === ENVIRONMENT_TYPE_FULLSCREEN const showEstimatedTime = transactionTimeFeatureActive && transaction.id === firstPendingTransactionId && diff --git a/ui/app/ducks/metamask/metamask.js b/ui/app/ducks/metamask/metamask.js index eb7d7e05ad6b..31968db4d173 100644 --- a/ui/app/ducks/metamask/metamask.js +++ b/ui/app/ducks/metamask/metamask.js @@ -15,8 +15,7 @@ function reduceMetamask (state, action) { isInitialized: false, isUnlocked: false, isAccountMenuOpen: false, - isPopup: - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP, + isPopup: getEnvironmentType() === ENVIRONMENT_TYPE_POPUP, rpcTarget: 'https://rawtestrpc.metamask.io/', identities: {}, unapprovedTxs: {}, diff --git a/ui/app/pages/confirm-transaction-base/confirm-transaction-base.component.js b/ui/app/pages/confirm-transaction-base/confirm-transaction-base.component.js index e13f97e7a971..d63e32432848 100644 --- a/ui/app/pages/confirm-transaction-base/confirm-transaction-base.component.js +++ b/ui/app/pages/confirm-transaction-base/confirm-transaction-base.component.js @@ -634,9 +634,7 @@ export default class ConfirmTransactionBase extends Component { } _removeBeforeUnload = () => { - if ( - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION - ) { + if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) { window.removeEventListener('beforeunload', this._beforeUnload) } } @@ -660,9 +658,7 @@ export default class ConfirmTransactionBase extends Component { }, }) - if ( - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION - ) { + if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) { window.addEventListener('beforeunload', this._beforeUnload) } diff --git a/ui/app/pages/home/home.container.js b/ui/app/pages/home/home.container.js index 96296357c53e..facc2e4b4b26 100644 --- a/ui/app/pages/home/home.container.js +++ b/ui/app/pages/home/home.container.js @@ -31,8 +31,7 @@ const mapStateToProps = state => { const accountBalance = getCurrentEthBalance(state) const { forgottenPassword, threeBoxLastUpdated } = appState - const isPopup = - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP + const isPopup = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP const firstPermissionsRequest = getFirstPermissionRequest(state) const firstPermissionsRequestId = firstPermissionsRequest && firstPermissionsRequest.metadata diff --git a/ui/app/pages/permissions-connect/permissions-connect.component.js b/ui/app/pages/permissions-connect/permissions-connect.component.js index ed02ad6176d9..7b08865eb8b9 100644 --- a/ui/app/pages/permissions-connect/permissions-connect.component.js +++ b/ui/app/pages/permissions-connect/permissions-connect.component.js @@ -62,9 +62,7 @@ export default class PermissionConnect extends Component { } removeBeforeUnload = () => { - if ( - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_FULLSCREEN - ) { + if (getEnvironmentType() === ENVIRONMENT_TYPE_FULLSCREEN) { window.removeEventListener('beforeunload', this.beforeUnload) } } @@ -107,9 +105,7 @@ export default class PermissionConnect extends Component { }) this.removeBeforeUnload() - if ( - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_FULLSCREEN - ) { + if (getEnvironmentType() === ENVIRONMENT_TYPE_FULLSCREEN) { setTimeout(async () => { const currentTab = await global.platform.currentTab() try { @@ -120,13 +116,9 @@ export default class PermissionConnect extends Component { global.platform.closeTab(currentTab.id) } }, 2000) - } else if ( - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION - ) { + } else if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) { history.push(DEFAULT_ROUTE) - } else if ( - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP - ) { + } else if (getEnvironmentType() === ENVIRONMENT_TYPE_POPUP) { history.push(CONNECTED_ROUTE) } } @@ -145,9 +137,7 @@ export default class PermissionConnect extends Component { return history.push(DEFAULT_ROUTE) } - if ( - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_FULLSCREEN - ) { + if (getEnvironmentType() === ENVIRONMENT_TYPE_FULLSCREEN) { window.addEventListener('beforeunload', this.beforeUnload) } } diff --git a/ui/app/pages/settings/settings.container.js b/ui/app/pages/settings/settings.container.js index c4e385f0349b..7e3b40e5b1a3 100644 --- a/ui/app/pages/settings/settings.container.js +++ b/ui/app/pages/settings/settings.container.js @@ -49,8 +49,7 @@ const mapStateToProps = (state, ownProps) => { pathname.match(CONTACT_MY_ACCOUNTS_EDIT_ROUTE) ) - const isPopupView = - getEnvironmentType(location.href) === ENVIRONMENT_TYPE_POPUP + const isPopupView = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP const pathnameI18nKey = ROUTES_TO_I18N_KEYS[pathname] let backRoute diff --git a/ui/app/pages/unlock-page/unlock-page.container.js b/ui/app/pages/unlock-page/unlock-page.container.js index 173e12b7e64c..4889f4365a51 100644 --- a/ui/app/pages/unlock-page/unlock-page.container.js +++ b/ui/app/pages/unlock-page/unlock-page.container.js @@ -48,7 +48,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => { markPasswordForgotten() history.push(RESTORE_VAULT_ROUTE) - if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP) { + if (getEnvironmentType() === ENVIRONMENT_TYPE_POPUP) { global.platform.openExtensionInBrowser(RESTORE_VAULT_ROUTE) } } diff --git a/ui/lib/webcam-utils.js b/ui/lib/webcam-utils.js index 2e9b5c2a09e3..7ee2fb5d17a9 100644 --- a/ui/lib/webcam-utils.js +++ b/ui/lib/webcam-utils.js @@ -9,8 +9,7 @@ import { getEnvironmentType, getPlatform } from '../../app/scripts/lib/util' class WebcamUtils { static async checkStatus () { - const isPopup = - getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP + const isPopup = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP const isFirefoxOrBrave = getPlatform() === (PLATFORM_FIREFOX || PLATFORM_BRAVE)