Skip to content

Commit

Permalink
Remove unnecessary get environment type parameter (MetaMask#7891)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Gudahtt authored and yqrashawn committed Feb 10, 2020
1 parent 76cc958 commit d0977f2
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 60 deletions.
2 changes: 1 addition & 1 deletion app/scripts/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/phishing-detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion app/scripts/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 1 addition & 4 deletions ui/app/components/app/account-menu/account-menu.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 3 additions & 12 deletions ui/app/components/app/modals/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,7 @@ const MODALS = {
contents: <HideTokenConfirmationModal />,
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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
3 changes: 1 addition & 2 deletions ui/app/ducks/metamask/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}

Expand Down
3 changes: 1 addition & 2 deletions ui/app/pages/home/home.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 5 additions & 15 deletions ui/app/pages/permissions-connect/permissions-connect.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand Down
3 changes: 1 addition & 2 deletions ui/app/pages/settings/settings.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ui/app/pages/unlock-page/unlock-page.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
3 changes: 1 addition & 2 deletions ui/lib/webcam-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit d0977f2

Please sign in to comment.