mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +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:
parent
9e8f922c10
commit
3244449ab9
@ -292,12 +292,6 @@ export function isValidAddressHead (address) {
|
|||||||
return addressLengthIsLessThanFull && addressIsHex
|
return addressLengthIsLessThanFull && addressIsHex
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getOriginFromUrl (url) {
|
|
||||||
url = new URL(url)
|
|
||||||
const origin = url.hostname
|
|
||||||
return origin
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getAccountByAddress (accounts = [], targetAddress) {
|
export function getAccountByAddress (accounts = [], targetAddress) {
|
||||||
return accounts.find(({ address }) => address === targetAddress)
|
return accounts.find(({ address }) => address === targetAddress)
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,10 @@ import {
|
|||||||
getSelectedAddress,
|
getSelectedAddress,
|
||||||
} from '../../selectors'
|
} from '../../selectors'
|
||||||
import { DEFAULT_ROUTE } from '../../helpers/constants/routes'
|
import { DEFAULT_ROUTE } from '../../helpers/constants/routes'
|
||||||
import { getOriginFromUrl } from '../../helpers/utils/util'
|
|
||||||
|
|
||||||
const mapStateToProps = (state) => {
|
const mapStateToProps = (state) => {
|
||||||
const { openMetaMaskTabs } = state.appState
|
const { openMetaMaskTabs } = state.appState
|
||||||
const { title, url, id } = state.activeTab
|
const { title, id } = state.activeTab
|
||||||
const connectedDomains = getConnectedDomainsForSelectedAddress(state)
|
const connectedDomains = getConnectedDomainsForSelectedAddress(state)
|
||||||
const originOfCurrentTab = getOriginOfCurrentTab(state)
|
const originOfCurrentTab = getOriginOfCurrentTab(state)
|
||||||
const permittedAccountsByOrigin = getPermittedAccountsByOrigin(state)
|
const permittedAccountsByOrigin = getPermittedAccountsByOrigin(state)
|
||||||
@ -30,10 +29,10 @@ const mapStateToProps = (state) => {
|
|||||||
]?.length
|
]?.length
|
||||||
|
|
||||||
let tabToConnect
|
let tabToConnect
|
||||||
if (url && currentTabHasNoAccounts && !openMetaMaskTabs[id]) {
|
if (originOfCurrentTab && currentTabHasNoAccounts && !openMetaMaskTabs[id]) {
|
||||||
tabToConnect = {
|
tabToConnect = {
|
||||||
title,
|
title,
|
||||||
origin: getOriginFromUrl(url),
|
origin: originOfCurrentTab,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import { createSelector } from 'reselect'
|
|||||||
import {
|
import {
|
||||||
shortenAddress,
|
shortenAddress,
|
||||||
checksumAddress,
|
checksumAddress,
|
||||||
getOriginFromUrl,
|
|
||||||
getAccountByAddress,
|
getAccountByAddress,
|
||||||
} from '../helpers/utils/util'
|
} from '../helpers/utils/util'
|
||||||
import {
|
import {
|
||||||
@ -375,8 +374,7 @@ export function hasPermissionRequests (state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getOriginOfCurrentTab (state) {
|
export function getOriginOfCurrentTab (state) {
|
||||||
const { activeTab } = state
|
return state.activeTab?.origin
|
||||||
return activeTab && activeTab.url && getOriginFromUrl(activeTab.url)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLastConnectedInfo (state) {
|
export function getLastConnectedInfo (state) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user