1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 20:05:27 +02:00
metamask-extension/ui/components/app/flask/snaps-authorship-pill/snaps-authorship-pill.js
Hassan Malik a7179a6b88
[FLASK] Add update snap UI (#15143)
* added snap-update folder

* addded update route, snap update component, updated permissions connect components

* added actions and selectors

* updated permissions selectors and updated permissions connect container to have update snap logic

* updated translations, added selector, updated request object

* updated translations, added update snap permission list component

* more fixes

* added CSS, redid some HTML

* lint fixes

* Add missing grantPermissions action

* updated button padding

* fixes

* removed prop type

* fix Update & Install wrapping

* made changes for forthcoming snap controller PR

* removed ununsed imports

* updated css

* re-added padding rule and removed unused translation messages

* addressed comments

* add subtext for new permissions

* lint fix

* removed unused translations

* some more changes

* fix e2e tests

* lint fix

* added in delay for e2e tests

* Revert "added in delay for e2e tests"

This reverts commit 095962a2c0c9de0b0b343d3134bb0787044dd8ce.

* fixed routing logic

Co-authored-by: Frederik Bolding <frederik.bolding@gmail.com>
Co-authored-by: Guillaume Roux <guillaumeroux123@gmail.com>
2022-08-03 12:02:44 -04:00

97 lines
2.7 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import Chip from '../../../ui/chip';
import Box from '../../../ui/box';
import Typography from '../../../ui/typography';
import {
COLORS,
TYPOGRAPHY,
TEXT_ALIGN,
} from '../../../../helpers/constants/design-system';
import { useI18nContext } from '../../../../hooks/useI18nContext';
const snapIdPrefixes = ['npm:', 'local:'];
const SnapsAuthorshipPill = ({ snapId, version, className }) => {
// @todo Use getSnapPrefix from snaps-skunkworks when possible
// We're using optional chaining with snapId, because with the current implementation
// of snap update in the snap controller, we do not have reference to snapId when an
// update request is rejected because the reference comes from the request itself and not subject metadata
// like it is done with snap install
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';
const t = useI18nContext();
return (
<a
href={url}
target="_blank"
rel="noopener noreferrer"
className={classnames(className, `snaps-authorship-pill`)}
>
<Chip
leftIcon={
<Box paddingLeft={2}>
<i className={`${icon} snaps-authorship-icon`} />
</Box>
}
rightIcon={
version && (
<Box
className="snaps-authorship-version"
backgroundColor={COLORS.PRIMARY_DEFAULT}
paddingLeft={2}
paddingRight={2}
>
<Typography
color={COLORS.PRIMARY_INVERSE}
variant={TYPOGRAPHY.H7}
align={TEXT_ALIGN.CENTER}
tag="span"
className="version"
>
{t('shorthandVersion', [version])}
</Typography>
</Box>
)
}
backgroundColor={COLORS.BACKGROUND_DEFAULT}
>
<Typography
className="chip__label"
variant={TYPOGRAPHY.H7}
tag="span"
color={COLORS.TEXT_ALTERNATIVE}
title={packageName}
>
{packageName}
</Typography>
</Chip>
</a>
);
};
SnapsAuthorshipPill.propTypes = {
/**
* The id of the snap
*/
snapId: PropTypes.string,
/**
* The version of the snap
*/
version: PropTypes.string,
/**
* The className of the SnapsAuthorshipPill
*/
className: PropTypes.string,
};
export default SnapsAuthorshipPill;