mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-27 04:46:10 +01:00
065c499753
* update ButtonIcon to TS lint updates fix lint issues add ref fix as prop test updates * box and icon updates for support * Update ui/components/component-library/text-field/README.mdx Co-authored-by: George Marshall <george.marshall@consensys.net> * fix disabled * update types for as * update readme * fix storybook * george changes to button icon * revert headerbase * box prop back to HTMLElementTagNameMap --------- Co-authored-by: George Marshall <george.marshall@consensys.net> Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
108 lines
3.3 KiB
JavaScript
108 lines
3.3 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { Redirect } from 'react-router-dom';
|
|
|
|
import Identicon from '../../../../components/ui/identicon';
|
|
import Button from '../../../../components/ui/button/button.component';
|
|
import {
|
|
ICON_NAMES,
|
|
ICON_SIZES,
|
|
} from '../../../../components/component-library/icon/deprecated';
|
|
|
|
import { ButtonIcon } from '../../../../components/component-library/button-icon/deprecated';
|
|
|
|
import Tooltip from '../../../../components/ui/tooltip';
|
|
import { useI18nContext } from '../../../../hooks/useI18nContext';
|
|
import { useCopyToClipboard } from '../../../../hooks/useCopyToClipboard';
|
|
import { IconColor } from '../../../../helpers/constants/design-system';
|
|
|
|
function quadSplit(address) {
|
|
return `0x${address
|
|
.slice(2)
|
|
.match(/.{1,4}/gu)
|
|
.join('')}`;
|
|
}
|
|
|
|
function ViewContact({
|
|
history,
|
|
name,
|
|
address,
|
|
checkSummedAddress,
|
|
memo,
|
|
editRoute,
|
|
listRoute,
|
|
}) {
|
|
const t = useI18nContext();
|
|
const [copied, handleCopy] = useCopyToClipboard();
|
|
|
|
if (!address) {
|
|
return <Redirect to={{ pathname: listRoute }} />;
|
|
}
|
|
|
|
return (
|
|
<div className="settings-page__content-row">
|
|
<div className="settings-page__content-item">
|
|
<div className="settings-page__header address-book__header">
|
|
<Identicon address={address} diameter={60} />
|
|
<div className="address-book__header__name">{name || address}</div>
|
|
</div>
|
|
<div className="address-book__view-contact__group">
|
|
<Button
|
|
type="secondary"
|
|
onClick={() => {
|
|
history.push(`${editRoute}/${address}`);
|
|
}}
|
|
>
|
|
{t('edit')}
|
|
</Button>
|
|
</div>
|
|
<div className="address-book__view-contact__group">
|
|
<div className="address-book__view-contact__group__label">
|
|
{t('ethereumPublicAddress')}
|
|
</div>
|
|
<div className="address-book__view-contact__group__value">
|
|
<div className="address-book__view-contact__group__static-address">
|
|
{quadSplit(checkSummedAddress)}
|
|
</div>
|
|
<Tooltip
|
|
position="bottom"
|
|
title={copied ? t('copiedExclamation') : t('copyToClipboard')}
|
|
>
|
|
<ButtonIcon
|
|
ariaLabel="copy"
|
|
className="address-book__view-contact__group__static-address--copy-icon"
|
|
onClick={() => {
|
|
handleCopy(checkSummedAddress);
|
|
}}
|
|
iconName={copied ? ICON_NAMES.COPY_SUCCESS : ICON_NAMES.COPY}
|
|
size={ICON_SIZES.LG}
|
|
color={IconColor.primaryDefault}
|
|
/>
|
|
</Tooltip>
|
|
</div>
|
|
</div>
|
|
<div className="address-book__view-contact__group">
|
|
<div className="address-book__view-contact__group__label--capitalized">
|
|
{t('memo')}
|
|
</div>
|
|
<div className="address-book__view-contact__group__static-address">
|
|
{memo}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
ViewContact.propTypes = {
|
|
name: PropTypes.string,
|
|
address: PropTypes.string,
|
|
history: PropTypes.object,
|
|
checkSummedAddress: PropTypes.string,
|
|
memo: PropTypes.string,
|
|
editRoute: PropTypes.string,
|
|
listRoute: PropTypes.string.isRequired,
|
|
};
|
|
|
|
export default React.memo(ViewContact);
|