1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Remove site origin on snap install (#14752)

* Remove site origin on snap install

* Fix linting + storybook

* Update local snap icon

* Fix storybook build
This commit is contained in:
Frederik Bolding 2022-05-25 18:19:02 +02:00 committed by GitHub
parent 8fcbebc546
commit 5b8a69c721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 38 deletions

View File

@ -9,7 +9,17 @@ import {
TYPOGRAPHY, TYPOGRAPHY,
} from '../../../../helpers/constants/design-system'; } from '../../../../helpers/constants/design-system';
const SnapsAuthorshipPill = ({ packageName, className, url }) => { const snapIdPrefixes = ['npm:', 'local:'];
const SnapsAuthorshipPill = ({ snapId, className }) => {
// @todo Use getSnapPrefix from snaps-skunkworks when possible
const snapPrefix = snapIdPrefixes.find((prefix) => snapId.startsWith(prefix));
const packageName = snapId.replace(snapPrefix, '');
const isNPM = snapPrefix === 'npm:';
const url = isNPM
? `https://www.npmjs.com/package/${packageName}`
: packageName;
const icon = isNPM ? 'fab fa-npm fa-lg' : 'fas fa-code';
return ( return (
<a <a
href={url} href={url}
@ -20,7 +30,7 @@ const SnapsAuthorshipPill = ({ packageName, className, url }) => {
<Chip <Chip
leftIcon={ leftIcon={
<Box paddingLeft={2}> <Box paddingLeft={2}>
<i className="fab fa-npm fa-lg snaps-authorship-icon" /> <i className={`${icon} snaps-authorship-icon`} />
</Box> </Box>
} }
backgroundColor={COLORS.BACKGROUND_DEFAULT} backgroundColor={COLORS.BACKGROUND_DEFAULT}
@ -40,17 +50,13 @@ const SnapsAuthorshipPill = ({ packageName, className, url }) => {
SnapsAuthorshipPill.propTypes = { SnapsAuthorshipPill.propTypes = {
/** /**
* NPM package name of the snap * The id of the snap
*/ */
packageName: PropTypes.string, snapId: PropTypes.string,
/** /**
* The className of the SnapsAuthorshipPill * The className of the SnapsAuthorshipPill
*/ */
className: PropTypes.string, className: PropTypes.string,
/**
* The url of the snap's package
*/
url: PropTypes.string,
}; };
export default SnapsAuthorshipPill; export default SnapsAuthorshipPill;

View File

@ -6,10 +6,7 @@ export default {
id: __filename, id: __filename,
component: SnapsAuthorshipPill, component: SnapsAuthorshipPill,
argTypes: { argTypes: {
packageName: { snapId: {
control: 'text',
},
url: {
control: 'text', control: 'text',
}, },
}, },
@ -20,6 +17,5 @@ export const DefaultStory = (args) => <SnapsAuthorshipPill {...args} />;
DefaultStory.storyName = 'Default'; DefaultStory.storyName = 'Default';
DefaultStory.args = { DefaultStory.args = {
packageName: 'npm-package-name', snapId: 'npm:@metamask/test-snap-bip44',
url: 'https://www.npmjs.com/package/@airswap/protocols',
}; };

View File

@ -7,6 +7,7 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
margin-bottom: 16px;
} }
&__title { &__title {
@ -14,7 +15,6 @@
text-align: center; text-align: center;
color: var(--color-text-default); color: var(--color-text-default);
margin-top: 16px;
font-weight: bold; font-weight: bold;
} }

View File

@ -31,8 +31,8 @@ export default class PermissionsConnectHeader extends Component {
boxProps: PropTypes.shape({ ...Box.propTypes }), boxProps: PropTypes.shape({ ...Box.propTypes }),
headerText: PropTypes.string, headerText: PropTypes.string,
///: BEGIN:ONLY_INCLUDE_IN(flask) ///: BEGIN:ONLY_INCLUDE_IN(flask)
npmPackageName: PropTypes.string,
snapVersion: PropTypes.string, snapVersion: PropTypes.string,
isSnapInstall: PropTypes.bool,
///: END:ONLY_INCLUDE_IN ///: END:ONLY_INCLUDE_IN
}; };
@ -44,7 +44,20 @@ export default class PermissionsConnectHeader extends Component {
}; };
renderHeaderIcon() { renderHeaderIcon() {
const { iconUrl, iconName, siteOrigin } = this.props; const {
iconUrl,
iconName,
siteOrigin,
///: BEGIN:ONLY_INCLUDE_IN(flask)
isSnapInstall,
///: END:ONLY_INCLUDE_IN
} = this.props;
///: BEGIN:ONLY_INCLUDE_IN(flask)
if (isSnapInstall) {
return null;
}
///: END:ONLY_INCLUDE_IN
return ( return (
<div className="permissions-connect-header__icon"> <div className="permissions-connect-header__icon">
@ -64,12 +77,12 @@ export default class PermissionsConnectHeader extends Component {
headerTitle, headerTitle,
headerText, headerText,
///: BEGIN:ONLY_INCLUDE_IN(flask) ///: BEGIN:ONLY_INCLUDE_IN(flask)
npmPackageName, siteOrigin,
snapVersion, snapVersion,
isSnapInstall,
///: END:ONLY_INCLUDE_IN ///: END:ONLY_INCLUDE_IN
} = this.props; } = this.props;
///: BEGIN:ONLY_INCLUDE_IN(flask) ///: BEGIN:ONLY_INCLUDE_IN(flask)
const npmPackageUrl = `https://www.npmjs.com/package/${npmPackageName}`;
const { t } = this.context; const { t } = this.context;
///: END:ONLY_INCLUDE_IN ///: END:ONLY_INCLUDE_IN
return ( return (
@ -83,12 +96,7 @@ export default class PermissionsConnectHeader extends Component {
<div className="permissions-connect-header__title">{headerTitle}</div> <div className="permissions-connect-header__title">{headerTitle}</div>
{ {
///: BEGIN:ONLY_INCLUDE_IN(flask) ///: BEGIN:ONLY_INCLUDE_IN(flask)
npmPackageName ? ( isSnapInstall && <SnapsAuthorshipPill snapId={siteOrigin} />
<SnapsAuthorshipPill
packageName={npmPackageName}
url={npmPackageUrl}
/>
) : null
///: END:ONLY_INCLUDE_IN ///: END:ONLY_INCLUDE_IN
} }
{ {

View File

@ -37,13 +37,6 @@ export default function SnapInstall({
approveSnapInstall, approveSnapInstall,
]); ]);
const npmId = useMemo(() => {
if (!targetSubjectMetadata.origin.startsWith('npm:')) {
return undefined;
}
return targetSubjectMetadata.origin.substring(4);
}, [targetSubjectMetadata]);
const shouldShowWarning = useMemo( const shouldShowWarning = useMemo(
() => () =>
Boolean( Boolean(
@ -74,7 +67,7 @@ export default function SnapInstall({
headerTitle={t('snapInstall')} headerTitle={t('snapInstall')}
headerText={null} // TODO(ritave): Add header text when snaps support description headerText={null} // TODO(ritave): Add header text when snaps support description
siteOrigin={targetSubjectMetadata.origin} siteOrigin={targetSubjectMetadata.origin}
npmPackageName={npmId} isSnapInstall
snapVersion={targetSubjectMetadata.version} snapVersion={targetSubjectMetadata.version}
boxProps={{ alignItems: ALIGN_ITEMS.CENTER }} boxProps={{ alignItems: ALIGN_ITEMS.CENTER }}
/> />

View File

@ -47,7 +47,6 @@ function ViewSnap() {
} }
}, [history, snap]); }, [history, snap]);
const authorshipPillUrl = `https://npmjs.com/package/${snap?.manifest.source.location.npm.packageName}`;
const connectedSubjects = useSelector((state) => const connectedSubjects = useSelector((state) =>
getSubjectsWithPermission(state, snap?.permissionName), getSubjectsWithPermission(state, snap?.permissionName),
); );
@ -87,10 +86,7 @@ function ViewSnap() {
</Typography> </Typography>
<Box className="view-snap__pill-toggle-container"> <Box className="view-snap__pill-toggle-container">
<Box className="view-snap__pill-container" paddingLeft={2}> <Box className="view-snap__pill-container" paddingLeft={2}>
<SnapsAuthorshipPill <SnapsAuthorshipPill snapId={snap.id} />
packageName={snap.id}
url={authorshipPillUrl}
/>
</Box> </Box>
<Box paddingLeft={4} className="view-snap__toggle-container"> <Box paddingLeft={4} className="view-snap__toggle-container">
<Tooltip interactive position="bottom" html={t('snapsToggle')}> <Tooltip interactive position="bottom" html={t('snapsToggle')}>