From c03b6dd19b516f032b6ae4974f6ffe8cf134bf3e Mon Sep 17 00:00:00 2001 From: Erik Marks <25517051+rekmarks@users.noreply.github.com> Date: Mon, 13 Dec 2021 12:10:20 -0800 Subject: [PATCH] Subject metadata cleanup (#13090) This PR fixes some subject metadata-related issues that were missed in #13026. --- .../approval-screens/token-approval.js | 6 +++--- .storybook/test-data.js | 12 ++++++------ app/scripts/metamask-controller.js | 1 + .../permission-page-container-content.component.js | 5 +++-- .../permission-page-container.component.js | 5 +++-- ui/hooks/useOriginMetadata.js | 2 +- .../permissions-connect.container.js | 3 ++- .../redirect/permissions-redirect.component.js | 1 + 8 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.storybook/initial-states/approval-screens/token-approval.js b/.storybook/initial-states/approval-screens/token-approval.js index 66203abb3..08aa375d7 100644 --- a/.storybook/initial-states/approval-screens/token-approval.js +++ b/.storybook/initial-states/approval-screens/token-approval.js @@ -48,9 +48,9 @@ export const currentNetworkTxListSample = { export const subjectMetadata = { "https://metamask.github.io": { + "origin": "https://metamask.github.io", "name": "E2E Test Dapp", - "icon": "https://metamask.github.io/test-dapp/metamask-fox.svg", - "lastUpdated": 1620723443380, - "host": "metamask.github.io" + "iconUrl": "https://metamask.github.io/test-dapp/metamask-fox.svg", + "subjectType": "website" } } \ No newline at end of file diff --git a/.storybook/test-data.js b/.storybook/test-data.js index bd9cc6672..3f732bc90 100644 --- a/.storybook/test-data.js +++ b/.storybook/test-data.js @@ -1175,15 +1175,15 @@ const state = { subjectMetadata: { 'https://metamask.github.io': { name: 'E2E Test Dapp', - icon: 'https://metamask.github.io/test-dapp/metamask-fox.svg', - lastUpdated: 1620723443380, - host: 'metamask.github.io', + origin: 'https://metamask.github.io', + iconUrl: 'https://metamask.github.io/test-dapp/metamask-fox.svg', + subjectType: 'website', }, 'https://app.uniswap.org': { name: 'Uniswap', - icon: './UNI.png', - lastUpdated: 1620723443380, - host: 'app.uniswap.org', + origin: 'https://app.uniswap.org', + iconUrl: './UNI.png', + subjectType: 'website', }, }, threeBoxSyncingAllowed: false, diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index fff60481a..fdfc59c28 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -2634,6 +2634,7 @@ export default class MetamaskController extends EventEmitter { subjectType = SUBJECT_TYPES.EXTENSION; this.subjectMetadataController.addSubjectMetadata(origin, { extensionId: sender.id, + subjectType: SUBJECT_TYPES.EXTENSION, }); } diff --git a/ui/components/app/permission-page-container/permission-page-container-content/permission-page-container-content.component.js b/ui/components/app/permission-page-container/permission-page-container-content/permission-page-container-content.component.js index f51ae3124..a7d155e95 100644 --- a/ui/components/app/permission-page-container/permission-page-container-content/permission-page-container-content.component.js +++ b/ui/components/app/permission-page-container/permission-page-container-content/permission-page-container-content.component.js @@ -7,10 +7,11 @@ import PermissionsConnectPermissionList from '../../permissions-connect-permissi export default class PermissionPageContainerContent extends PureComponent { static propTypes = { subjectMetadata: PropTypes.shape({ - extensionId: PropTypes.string, - iconUrl: PropTypes.string, name: PropTypes.string.isRequired, origin: PropTypes.string.isRequired, + subjectType: PropTypes.string.isRequired, + extensionId: PropTypes.string, + iconUrl: PropTypes.string, }), selectedPermissions: PropTypes.object.isRequired, selectedIdentities: PropTypes.array, diff --git a/ui/components/app/permission-page-container/permission-page-container.component.js b/ui/components/app/permission-page-container/permission-page-container.component.js index a1b1a79ed..fee70f720 100644 --- a/ui/components/app/permission-page-container/permission-page-container.component.js +++ b/ui/components/app/permission-page-container/permission-page-container.component.js @@ -14,10 +14,11 @@ export default class PermissionPageContainer extends Component { request: PropTypes.object, requestMetadata: PropTypes.object, targetSubjectMetadata: PropTypes.shape({ - extensionId: PropTypes.string, - icon: PropTypes.string, name: PropTypes.string.isRequired, origin: PropTypes.string.isRequired, + subjectType: PropTypes.string.isRequired, + extensionId: PropTypes.string, + iconUrl: PropTypes.string, }), }; diff --git a/ui/hooks/useOriginMetadata.js b/ui/hooks/useOriginMetadata.js index fa5d6ace7..bdec991b9 100644 --- a/ui/hooks/useOriginMetadata.js +++ b/ui/hooks/useOriginMetadata.js @@ -21,8 +21,8 @@ export function useOriginMetadata(origin) { if (!origin) { return null; } - const url = new URL(origin); + const url = new URL(origin); const minimumOriginMetadata = { host: url.host, hostname: url.hostname, diff --git a/ui/pages/permissions-connect/permissions-connect.container.js b/ui/pages/permissions-connect/permissions-connect.container.js index 215995afa..0d1350c5a 100644 --- a/ui/pages/permissions-connect/permissions-connect.container.js +++ b/ui/pages/permissions-connect/permissions-connect.container.js @@ -50,9 +50,10 @@ const mapStateToProps = (state, ownProps) => { } else { const targetUrl = new URL(origin); targetSubjectMetadata = { - host: targetUrl.host, name: targetUrl.hostname, origin, + iconUrl: null, + extensionId: null, }; } } diff --git a/ui/pages/permissions-connect/redirect/permissions-redirect.component.js b/ui/pages/permissions-connect/redirect/permissions-redirect.component.js index 7d61ed84a..c433e3674 100644 --- a/ui/pages/permissions-connect/redirect/permissions-redirect.component.js +++ b/ui/pages/permissions-connect/redirect/permissions-redirect.component.js @@ -50,6 +50,7 @@ PermissionsRedirect.propTypes = { subjectMetadata: PropTypes.shape({ extensionId: PropTypes.string, iconUrl: PropTypes.string, + subjectType: PropTypes.string, name: PropTypes.string.isRequired, origin: PropTypes.string.isRequired, }),