2020-07-24 16:17:03 +02:00
|
|
|
import React from 'react'
|
2019-07-31 21:56:44 +02:00
|
|
|
import PropTypes from 'prop-types'
|
2020-07-20 16:55:47 +02:00
|
|
|
import { Redirect } from 'react-router-dom'
|
|
|
|
|
2019-07-31 21:56:44 +02:00
|
|
|
import Identicon from '../../../../components/ui/identicon'
|
2020-03-16 14:44:02 +01:00
|
|
|
import Copy from '../../../../components/ui/icon/copy-icon.component'
|
2019-07-31 21:56:44 +02:00
|
|
|
import Button from '../../../../components/ui/button/button.component'
|
2020-07-24 16:17:03 +02:00
|
|
|
|
2020-08-18 18:13:55 +02:00
|
|
|
import Tooltip from '../../../../components/ui/tooltip'
|
2020-07-24 16:17:03 +02:00
|
|
|
import { useI18nContext } from '../../../../hooks/useI18nContext'
|
|
|
|
import { useCopyToClipboard } from '../../../../hooks/useCopyToClipboard'
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
function quadSplit (address) {
|
2020-07-24 16:17:03 +02:00
|
|
|
return (
|
2020-08-19 18:27:05 +02:00
|
|
|
`0x ${
|
|
|
|
address
|
|
|
|
.slice(2)
|
|
|
|
.match(/.{1,4}/ug)
|
|
|
|
.join(' ')}`
|
2020-07-24 16:17:03 +02:00
|
|
|
)
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-07-24 16:17:03 +02:00
|
|
|
function ViewContact ({
|
|
|
|
history,
|
|
|
|
name,
|
|
|
|
address,
|
|
|
|
checkSummedAddress,
|
|
|
|
memo,
|
|
|
|
editRoute,
|
|
|
|
listRoute,
|
|
|
|
}) {
|
|
|
|
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) {
|
|
|
|
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={() => {
|
|
|
|
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')}
|
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={() => {
|
|
|
|
handleCopy(checkSummedAddress)
|
|
|
|
}}
|
2020-03-16 14:44:02 +01:00
|
|
|
>
|
|
|
|
<Copy size={20} color="#3098DC" />
|
|
|
|
</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>
|
|
|
|
)
|
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,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default React.memo(ViewContact)
|