mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
f946c030b5
* added wrapper around account list to prevent storybook from collapsing the list * updated translation files * added snap-connect page * refactored account list out of the choose account component * fixed width * removed unnecessary scss from choose-account component, fixed props in choose account story * removed snaps-connect page, added comments to ChooseAccount * updated choose account subtitle text, updated styling for title & subtitle, removed redundant account list story * updated component name, updated paths * fixed linter errors * added comments * removed unused message * removed selectAccounts key from all locales * updated class name for account list header, updated allAreSelected function to use length checks * Revert "removed unused message" This reverts commit 32771bc83c08f120825ef75f0741f3034e7dbecb. * Revert "removed selectAccounts key from all locales" This reverts commit ccfa4a860f9a75693d893d7c404384e719de297e. * updated locale messages to use selectAccounts key * removed stray import * updated scss * updated translation key * removed chooseAccounts key from en locale * removed optional chaining * changes * updated subjectMetadata * updated subject types * update useOriginMetadata function to include unknown subject type * updated permission connect header props, removed host and added subjectType to targetSubjectMetadata * added subjectType to targetSubjectMetadata * removed console.log * changed prop name to iconUrl
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
import { useSelector } from 'react-redux';
|
|
import { getSubjectMetadata } from '../selectors';
|
|
import { SUBJECT_TYPES } from '../../shared/constants/app';
|
|
|
|
/**
|
|
* @typedef {Object} OriginMetadata
|
|
* @property {string} hostname - The hostname of the origin (host + port)
|
|
* @property {string} origin - The original origin string itself
|
|
* @property {string} [iconUrl] - The origin's site icon URL, if available
|
|
* @property {string} [name] - The registered name of the origin if available
|
|
*/
|
|
|
|
/**
|
|
* Gets origin metadata from redux and formats it appropriately.
|
|
* @param {string} origin - The fully formed url of the site interacting with
|
|
* MetaMask
|
|
* @returns {OriginMetadata | null} - The origin metadata available for the
|
|
* current origin
|
|
*/
|
|
export function useOriginMetadata(origin) {
|
|
const subjectMetadata = useSelector(getSubjectMetadata);
|
|
if (!origin) {
|
|
return null;
|
|
}
|
|
|
|
const url = new URL(origin);
|
|
const minimumOriginMetadata = {
|
|
host: url.host,
|
|
hostname: url.hostname,
|
|
origin,
|
|
subjectType: SUBJECT_TYPES.UNKNOWN,
|
|
};
|
|
|
|
if (subjectMetadata?.[origin]) {
|
|
return {
|
|
...minimumOriginMetadata,
|
|
...subjectMetadata[origin],
|
|
};
|
|
}
|
|
return minimumOriginMetadata;
|
|
}
|