2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Redirect } from 'react-router-dom';
|
2020-07-20 16:55:47 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import Identicon from '../../../../components/ui/identicon';
|
|
|
|
import Button from '../../../../components/ui/button/button.component';
|
2023-01-31 18:00:26 +01:00
|
|
|
import {
|
|
|
|
ButtonIcon,
|
|
|
|
ICON_NAMES,
|
|
|
|
ICON_SIZES,
|
|
|
|
} from '../../../../components/component-library';
|
2020-07-24 16:17:03 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import Tooltip from '../../../../components/ui/tooltip';
|
|
|
|
import { useI18nContext } from '../../../../hooks/useI18nContext';
|
|
|
|
import { useCopyToClipboard } from '../../../../hooks/useCopyToClipboard';
|
2023-01-31 18:00:26 +01:00
|
|
|
import { COLORS } from '../../../../helpers/constants/design-system';
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function quadSplit(address) {
|
2023-01-17 22:36:33 +01:00
|
|
|
return `0x${address
|
2020-11-03 00:41:28 +01:00
|
|
|
.slice(2)
|
|
|
|
.match(/.{1,4}/gu)
|
2023-01-17 22:36:33 +01:00
|
|
|
.join('')}`;
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function ViewContact({
|
2020-07-24 16:17:03 +02:00
|
|
|
history,
|
|
|
|
name,
|
|
|
|
address,
|
|
|
|
checkSummedAddress,
|
|
|
|
memo,
|
|
|
|
editRoute,
|
|
|
|
listRoute,
|
|
|
|
}) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const t = useI18nContext();
|
|
|
|
const [copied, handleCopy] = useCopyToClipboard();
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-07-24 16:17:03 +02:00
|
|
|
if (!address) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return <Redirect to={{ pathname: listRoute }} />;
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-07-24 16:17:03 +02:00
|
|
|
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} />
|
2023-01-17 22:36:33 +01:00
|
|
|
<div className="address-book__header__name">{name || address}</div>
|
2020-07-24 16:17:03 +02:00
|
|
|
</div>
|
|
|
|
<div className="address-book__view-contact__group">
|
|
|
|
<Button
|
|
|
|
type="secondary"
|
|
|
|
onClick={() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
history.push(`${editRoute}/${address}`);
|
2020-07-24 16:17:03 +02:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t('edit')}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
<div className="address-book__view-contact__group">
|
|
|
|
<div className="address-book__view-contact__group__label">
|
|
|
|
{t('ethereumPublicAddress')}
|
2019-07-31 21:56:44 +02:00
|
|
|
</div>
|
2020-07-24 16:17:03 +02:00
|
|
|
<div className="address-book__view-contact__group__value">
|
|
|
|
<div className="address-book__view-contact__group__static-address">
|
|
|
|
{quadSplit(checkSummedAddress)}
|
2019-07-31 21:56:44 +02:00
|
|
|
</div>
|
2020-07-24 16:17:03 +02:00
|
|
|
<Tooltip
|
|
|
|
position="bottom"
|
|
|
|
title={copied ? t('copiedExclamation') : t('copyToClipboard')}
|
|
|
|
>
|
2023-01-31 18:00:26 +01:00
|
|
|
<ButtonIcon
|
|
|
|
ariaLabel="copy"
|
2019-07-31 21:56:44 +02:00
|
|
|
className="address-book__view-contact__group__static-address--copy-icon"
|
2020-07-24 16:17:03 +02:00
|
|
|
onClick={() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
handleCopy(checkSummedAddress);
|
2020-07-24 16:17:03 +02:00
|
|
|
}}
|
2023-01-31 18:00:26 +01:00
|
|
|
iconName={copied ? ICON_NAMES.COPY_SUCCESS : ICON_NAMES.COPY}
|
|
|
|
size={ICON_SIZES.LG}
|
|
|
|
color={COLORS.PRIMARY_DEFAULT}
|
|
|
|
/>
|
2020-07-24 16:17:03 +02:00
|
|
|
</Tooltip>
|
2019-07-31 21:56:44 +02:00
|
|
|
</div>
|
2020-07-24 16:17:03 +02:00
|
|
|
</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}
|
2019-07-31 21:56:44 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-07-24 16:17:03 +02:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
2020-07-24 16:17:03 +02:00
|
|
|
|
|
|
|
ViewContact.propTypes = {
|
|
|
|
name: PropTypes.string,
|
|
|
|
address: PropTypes.string,
|
|
|
|
history: PropTypes.object,
|
|
|
|
checkSummedAddress: PropTypes.string,
|
|
|
|
memo: PropTypes.string,
|
|
|
|
editRoute: PropTypes.string,
|
|
|
|
listRoute: PropTypes.string.isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-07-24 16:17:03 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default React.memo(ViewContact);
|