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 Copy from '../../../../components/ui/icon/copy-icon.component';
|
|
|
|
import Button from '../../../../components/ui/button/button.component';
|
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';
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function quadSplit(address) {
|
|
|
|
return `0x ${address
|
|
|
|
.slice(2)
|
|
|
|
.match(/.{1,4}/gu)
|
2021-02-04 19:15:23 +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} />
|
|
|
|
<div className="address-book__header__name">{name}</div>
|
|
|
|
</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')}
|
|
|
|
>
|
2020-03-16 14:44:02 +01:00
|
|
|
<button
|
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
|
|
|
}}
|
2020-03-16 14:44:02 +01:00
|
|
|
>
|
2022-03-25 23:15:31 +01:00
|
|
|
<Copy size={20} color="var(--color-primary-default)" />
|
2020-03-16 14:44:02 +01:00
|
|
|
</button>
|
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);
|