1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 14:15:06 +01:00
metamask-extension/ui/components/app/snaps/snap-avatar/snap-avatar.js
Frederik Bolding 789779f4d5
[FLASK] Rework Snaps headers and footers (#19442)
* Add new snap header and footer to snap install

* Add new snap header and footer to snap result and snap update

* Fix loading state

* Fix lint

* Add required scrolling

* Adjust avatar component

* Apply new headers and footers to snaps confirmations

* Rename previous SnapAuthorship component to SnapAuthorshipExpanded

* Fix lint

* Fix font weight

* Fix fencing

* Fix a test

* Fix lint after rebase

* Fix E2E

* Fix locale lint

* Fix another E2E

* Fix test ID

* Address PR comments

* Better scroll button centering

* Address design comments

* Fix unit test

* Fix E2Es
2023-06-07 15:18:49 +02:00

85 lines
2.0 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { useSelector } from 'react-redux';
import {
TextColor,
IconColor,
AlignItems,
DISPLAY,
JustifyContent,
Size,
BackgroundColor,
} from '../../../../helpers/constants/design-system';
import { getSnapName } from '../../../../helpers/utils/util';
import {
AvatarFavicon,
BadgeWrapper,
BadgeWrapperPosition,
AvatarIcon,
AvatarBase,
IconName,
IconSize,
} from '../../../component-library';
import { getTargetSubjectMetadata } from '../../../../selectors';
const SnapAvatar = ({ snapId, className }) => {
const subjectMetadata = useSelector((state) =>
getTargetSubjectMetadata(state, snapId),
);
const friendlyName = snapId && getSnapName(snapId, subjectMetadata);
const iconUrl = subjectMetadata?.iconUrl;
const fallbackIcon = friendlyName && friendlyName[0] ? friendlyName[0] : '?';
return (
<BadgeWrapper
className={classnames('snap-avatar', className)}
badge={
<AvatarIcon
iconName={IconName.Snaps}
size={IconSize.Sm}
backgroundColor={IconColor.infoDefault}
borderColor={BackgroundColor.backgroundDefault}
borderWidth={2}
iconProps={{
size: IconSize.Sm,
color: IconColor.infoInverse,
}}
/>
}
position={BadgeWrapperPosition.bottomRight}
>
{iconUrl ? (
<AvatarFavicon size={Size.LG} src={iconUrl} name={friendlyName} />
) : (
<AvatarBase
size={Size.LG}
display={DISPLAY.FLEX}
alignItems={AlignItems.center}
justifyContent={JustifyContent.center}
color={TextColor.textAlternative}
style={{ borderWidth: '0px' }}
>
{fallbackIcon}
</AvatarBase>
)}
</BadgeWrapper>
);
};
SnapAvatar.propTypes = {
/**
* The id of the snap
*/
snapId: PropTypes.string,
/**
* The className of the SnapAvatar
*/
className: PropTypes.string,
};
export default SnapAvatar;