1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00

Use activeTab.origin where possible (#8617)

This changeset updates the `getOriginOfCurrentTab` selector and the container
for the ConnectedSites page to use `activeTab.origin` instead of parsing the
URL. The `activeTab` URL is parsed in `queryCurrentActiveTab` before the UI is
launched and any subsequent parsing of the URL is unnecessary.

See `queryCurrentActiveTab` in `ui.js:86` [1].

  [1]:e7bb0876f5/app/scripts/ui.js (L86-L118)
This commit is contained in:
Whymarrh Whitby 2020-05-18 20:04:51 -02:30 committed by GitHub
parent 9e8f922c10
commit 3244449ab9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 13 deletions

View File

@ -292,12 +292,6 @@ export function isValidAddressHead (address) {
return addressLengthIsLessThanFull && addressIsHex
}
export function getOriginFromUrl (url) {
url = new URL(url)
const origin = url.hostname
return origin
}
export function getAccountByAddress (accounts = [], targetAddress) {
return accounts.find(({ address }) => address === targetAddress)
}

View File

@ -15,11 +15,10 @@ import {
getSelectedAddress,
} from '../../selectors'
import { DEFAULT_ROUTE } from '../../helpers/constants/routes'
import { getOriginFromUrl } from '../../helpers/utils/util'
const mapStateToProps = (state) => {
const { openMetaMaskTabs } = state.appState
const { title, url, id } = state.activeTab
const { title, id } = state.activeTab
const connectedDomains = getConnectedDomainsForSelectedAddress(state)
const originOfCurrentTab = getOriginOfCurrentTab(state)
const permittedAccountsByOrigin = getPermittedAccountsByOrigin(state)
@ -30,10 +29,10 @@ const mapStateToProps = (state) => {
]?.length
let tabToConnect
if (url && currentTabHasNoAccounts && !openMetaMaskTabs[id]) {
if (originOfCurrentTab && currentTabHasNoAccounts && !openMetaMaskTabs[id]) {
tabToConnect = {
title,
origin: getOriginFromUrl(url),
origin: originOfCurrentTab,
}
}

View File

@ -4,7 +4,6 @@ import { createSelector } from 'reselect'
import {
shortenAddress,
checksumAddress,
getOriginFromUrl,
getAccountByAddress,
} from '../helpers/utils/util'
import {
@ -375,8 +374,7 @@ export function hasPermissionRequests (state) {
}
export function getOriginOfCurrentTab (state) {
const { activeTab } = state
return activeTab && activeTab.url && getOriginFromUrl(activeTab.url)
return state.activeTab?.origin
}
export function getLastConnectedInfo (state) {