From d79bf8db2eeb938a1887f7d0c723113339a01fa2 Mon Sep 17 00:00:00 2001 From: Erik Marks Date: Tue, 16 Jun 2020 10:15:53 -0700 Subject: [PATCH 1/2] fix getTargetDomainMetadata selector --- ui/app/selectors/selectors.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ui/app/selectors/selectors.js b/ui/app/selectors/selectors.js index 87f4ef64b..5fcb5088e 100644 --- a/ui/app/selectors/selectors.js +++ b/ui/app/selectors/selectors.js @@ -292,6 +292,11 @@ export function getTargetDomainMetadata (state, request, defaultOrigin) { const { metadata: requestMetadata = {} } = request || {} const origin = requestMetadata.origin || defaultOrigin + + if (!origin) { + return null + } + const hostname = (new URL(origin).hostname) const targetDomainMetadata = (domainMetadata[origin] || { name: hostname, icon: null }) targetDomainMetadata.origin = origin From 28cf7280671cc9f8cda3bd0d6de36b5162079fee Mon Sep 17 00:00:00 2001 From: Erik Marks Date: Tue, 16 Jun 2020 11:34:08 -0700 Subject: [PATCH 2/2] delete targetDomainMetadata selector --- .../permission-page-container.container.js | 9 ++------- .../permissions-connect.component.js | 3 +-- .../permissions-connect.container.js | 13 ++++++++++--- ui/app/selectors/selectors.js | 17 ----------------- 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/ui/app/components/app/permission-page-container/permission-page-container.container.js b/ui/app/components/app/permission-page-container/permission-page-container.container.js index 4a2229c85..4a2b7c660 100644 --- a/ui/app/components/app/permission-page-container/permission-page-container.container.js +++ b/ui/app/components/app/permission-page-container/permission-page-container.container.js @@ -1,19 +1,14 @@ import { connect } from 'react-redux' import PermissionPageContainer from './permission-page-container.component' -import { - getTargetDomainMetadata, - getMetaMaskIdentities, -} from '../../../selectors' +import { getMetaMaskIdentities } from '../../../selectors' const mapStateToProps = (state, ownProps) => { - const { request, cachedOrigin, selectedIdentities } = ownProps - const targetDomainMetadata = getTargetDomainMetadata(state, request, cachedOrigin) + const { selectedIdentities } = ownProps const allIdentities = getMetaMaskIdentities(state) const allIdentitiesSelected = Object.keys(selectedIdentities).length === Object.keys(allIdentities).length && selectedIdentities.length > 1 return { - targetDomainMetadata, allIdentitiesSelected, } } diff --git a/ui/app/pages/permissions-connect/permissions-connect.component.js b/ui/app/pages/permissions-connect/permissions-connect.component.js index e145ded4f..068d846dd 100644 --- a/ui/app/pages/permissions-connect/permissions-connect.component.js +++ b/ui/app/pages/permissions-connect/permissions-connect.component.js @@ -206,7 +206,6 @@ export default class PermissionConnect extends Component { const { selectedAccountAddresses, permissionsApproved, - origin, redirecting, targetDomainMetadata, } = this.state @@ -257,7 +256,7 @@ export default class PermissionConnect extends Component { }} rejectPermissionsRequest={(requestId) => this.cancelPermissionsRequest(requestId)} selectedIdentities={accounts.filter((account) => selectedAccountAddresses.has(account.address))} - cachedOrigin={origin} + targetDomainMetadata={targetDomainMetadata} /> )} /> diff --git a/ui/app/pages/permissions-connect/permissions-connect.container.js b/ui/app/pages/permissions-connect/permissions-connect.container.js index 7f30a64ab..31a727cb5 100644 --- a/ui/app/pages/permissions-connect/permissions-connect.container.js +++ b/ui/app/pages/permissions-connect/permissions-connect.container.js @@ -6,7 +6,7 @@ import { getNativeCurrency, getAccountsWithLabels, getLastConnectedInfo, - getTargetDomainMetadata, + getDomainMetadata, getSelectedAddress, } from '../../selectors' @@ -42,6 +42,15 @@ const mapStateToProps = (state, ownProps) => { const { origin } = metadata const nativeCurrency = getNativeCurrency(state) + const domainMetadata = getDomainMetadata(state) + const targetDomainMetadata = origin + ? domainMetadata[origin] || { + origin, + name: (new URL(origin)).hostname, + icon: null, + } + : null + const accountsWithLabels = getAccountsWithLabels(state) const lastConnectedInfo = getLastConnectedInfo(state) || {} @@ -63,8 +72,6 @@ const mapStateToProps = (state, ownProps) => { throw new Error('Incorrect path for permissions-connect component') } - const targetDomainMetadata = getTargetDomainMetadata(state, permissionsRequest, origin) - return { permissionsRequest, permissionsRequestId, diff --git a/ui/app/selectors/selectors.js b/ui/app/selectors/selectors.js index 5fcb5088e..b5b4cb204 100644 --- a/ui/app/selectors/selectors.js +++ b/ui/app/selectors/selectors.js @@ -287,23 +287,6 @@ export function getDomainMetadata (state) { return state.metamask.domainMetadata } -export function getTargetDomainMetadata (state, request, defaultOrigin) { - const domainMetadata = getDomainMetadata(state) - - const { metadata: requestMetadata = {} } = request || {} - const origin = requestMetadata.origin || defaultOrigin - - if (!origin) { - return null - } - - const hostname = (new URL(origin).hostname) - const targetDomainMetadata = (domainMetadata[origin] || { name: hostname, icon: null }) - targetDomainMetadata.origin = origin - - return targetDomainMetadata -} - export const getBackgroundMetaMetricState = (state) => { return { network: getCurrentNetworkId(state),