2020-02-19 19:24:16 +01:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
2020-08-06 15:04:55 +02:00
|
|
|
import AccountListItem from '../../components/app/account-list-item'
|
2020-03-06 22:34:56 +01:00
|
|
|
import Button from '../../components/ui/button'
|
|
|
|
import Identicon from '../../components/ui/identicon'
|
|
|
|
|
2020-02-19 19:24:16 +01:00
|
|
|
import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../app/scripts/lib/enums'
|
|
|
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util'
|
|
|
|
import { conversionUtil } from '../../helpers/utils/conversion-util'
|
|
|
|
|
|
|
|
export default class ConfirmEncryptionPublicKey extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func.isRequired,
|
|
|
|
metricsEvent: PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
2020-03-06 22:34:56 +01:00
|
|
|
fromAccount: PropTypes.shape({
|
|
|
|
address: PropTypes.string.isRequired,
|
|
|
|
balance: PropTypes.string,
|
|
|
|
name: PropTypes.string,
|
|
|
|
}).isRequired,
|
2020-02-19 19:24:16 +01:00
|
|
|
clearConfirmTransaction: PropTypes.func.isRequired,
|
|
|
|
cancelEncryptionPublicKey: PropTypes.func.isRequired,
|
|
|
|
encryptionPublicKey: PropTypes.func.isRequired,
|
|
|
|
conversionRate: PropTypes.number,
|
|
|
|
history: PropTypes.object.isRequired,
|
|
|
|
requesterAddress: PropTypes.string,
|
|
|
|
txData: PropTypes.object,
|
|
|
|
domainMetadata: PropTypes.object,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
2020-02-19 19:24:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
state = {
|
2020-03-06 22:34:56 +01:00
|
|
|
fromAccount: this.props.fromAccount,
|
2020-02-19 19:24:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount = () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
if (
|
|
|
|
getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION
|
|
|
|
) {
|
2020-02-19 19:24:16 +01:00
|
|
|
window.addEventListener('beforeunload', this._beforeUnload)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount = () => {
|
|
|
|
this._removeBeforeUnload()
|
|
|
|
}
|
|
|
|
|
2020-06-16 16:40:00 +02:00
|
|
|
_beforeUnload = async (event) => {
|
|
|
|
const {
|
|
|
|
clearConfirmTransaction,
|
|
|
|
cancelEncryptionPublicKey,
|
|
|
|
txData,
|
|
|
|
} = this.props
|
2020-02-19 19:24:16 +01:00
|
|
|
const { metricsEvent } = this.context
|
2020-06-16 16:40:00 +02:00
|
|
|
await cancelEncryptionPublicKey(txData, event)
|
2020-02-19 19:24:16 +01:00
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Messages',
|
|
|
|
action: 'Encryption public key Request',
|
|
|
|
name: 'Cancel Via Notification Close',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
clearConfirmTransaction()
|
|
|
|
}
|
|
|
|
|
|
|
|
_removeBeforeUnload = () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
if (
|
|
|
|
getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION
|
|
|
|
) {
|
2020-02-19 19:24:16 +01:00
|
|
|
window.removeEventListener('beforeunload', this._beforeUnload)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderHeader = () => {
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__header">
|
|
|
|
<div className="request-encryption-public-key__header-background" />
|
|
|
|
|
|
|
|
<div className="request-encryption-public-key__header__text">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.context.t('encryptionPublicKeyRequest')}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="request-encryption-public-key__header__tip-container">
|
|
|
|
<div className="request-encryption-public-key__header__tip" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderAccount = () => {
|
2020-03-06 22:34:56 +01:00
|
|
|
const { fromAccount } = this.state
|
2020-06-16 16:40:00 +02:00
|
|
|
const { t } = this.context
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__account">
|
|
|
|
<div className="request-encryption-public-key__account-text">
|
2020-11-03 00:41:28 +01:00
|
|
|
{`${t('account')}:`}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="request-encryption-public-key__account-item">
|
2020-11-03 00:41:28 +01:00
|
|
|
<AccountListItem account={fromAccount} />
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderBalance = () => {
|
2020-03-06 22:34:56 +01:00
|
|
|
const { conversionRate } = this.props
|
2020-06-16 16:40:00 +02:00
|
|
|
const { t } = this.context
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
fromAccount: { balance },
|
|
|
|
} = this.state
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
const balanceInEther = conversionUtil(balance, {
|
|
|
|
fromNumericBase: 'hex',
|
|
|
|
toNumericBase: 'dec',
|
|
|
|
fromDenomination: 'WEI',
|
|
|
|
numberOfDecimals: 6,
|
|
|
|
conversionRate,
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__balance">
|
|
|
|
<div className="request-encryption-public-key__balance-text">
|
2020-11-03 00:41:28 +01:00
|
|
|
{`${t('balance')}:`}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
<div className="request-encryption-public-key__balance-value">
|
2020-11-03 00:41:28 +01:00
|
|
|
{`${balanceInEther} ETH`}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderRequestIcon = () => {
|
|
|
|
const { requesterAddress } = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__request-icon">
|
2020-11-03 00:41:28 +01:00
|
|
|
<Identicon diameter={40} address={requesterAddress} />
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderAccountInfo = () => {
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__account-info">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderAccount()}
|
|
|
|
{this.renderRequestIcon()}
|
|
|
|
{this.renderBalance()}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderBody = () => {
|
2020-06-16 16:40:00 +02:00
|
|
|
const { domainMetadata, txData } = this.props
|
|
|
|
const { t } = this.context
|
2020-02-19 19:24:16 +01:00
|
|
|
|
2020-06-16 16:40:00 +02:00
|
|
|
const origin = domainMetadata[txData.origin]
|
|
|
|
const notice = t('encryptionPublicKeyNotice', [origin.name])
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__body">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderAccountInfo()}
|
|
|
|
<div className="request-encryption-public-key__visual">
|
2020-02-19 19:24:16 +01:00
|
|
|
<section>
|
|
|
|
{origin.icon ? (
|
|
|
|
<img
|
|
|
|
className="request-encryption-public-key__visual-identicon"
|
|
|
|
src={origin.icon}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<i className="request-encryption-public-key__visual-identicon--default">
|
|
|
|
{origin.name.charAt(0).toUpperCase()}
|
|
|
|
</i>
|
|
|
|
)}
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="request-encryption-public-key__notice">
|
|
|
|
{notice}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderFooter = () => {
|
2020-06-01 19:54:32 +02:00
|
|
|
const {
|
|
|
|
cancelEncryptionPublicKey,
|
|
|
|
clearConfirmTransaction,
|
|
|
|
encryptionPublicKey,
|
|
|
|
history,
|
|
|
|
mostRecentOverviewPage,
|
|
|
|
txData,
|
|
|
|
} = this.props
|
2020-06-16 16:40:00 +02:00
|
|
|
const { t, metricsEvent } = this.context
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__footer">
|
|
|
|
<Button
|
|
|
|
type="default"
|
|
|
|
large
|
|
|
|
className="request-encryption-public-key__footer__cancel-button"
|
|
|
|
onClick={async (event) => {
|
|
|
|
this._removeBeforeUnload()
|
2020-06-01 19:54:32 +02:00
|
|
|
await cancelEncryptionPublicKey(txData, event)
|
2020-06-16 16:40:00 +02:00
|
|
|
metricsEvent({
|
2020-02-19 19:24:16 +01:00
|
|
|
eventOpts: {
|
|
|
|
category: 'Messages',
|
|
|
|
action: 'Encryption public key Request',
|
|
|
|
name: 'Cancel',
|
|
|
|
},
|
|
|
|
})
|
2020-06-01 19:54:32 +02:00
|
|
|
clearConfirmTransaction()
|
|
|
|
history.push(mostRecentOverviewPage)
|
2020-02-19 19:24:16 +01:00
|
|
|
}}
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.context.t('cancel')}
|
2020-02-19 19:24:16 +01:00
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
type="secondary"
|
|
|
|
large
|
|
|
|
className="request-encryption-public-key__footer__sign-button"
|
|
|
|
onClick={async (event) => {
|
|
|
|
this._removeBeforeUnload()
|
2020-06-01 19:54:32 +02:00
|
|
|
await encryptionPublicKey(txData, event)
|
2020-02-19 19:24:16 +01:00
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Messages',
|
|
|
|
action: 'Encryption public key Request',
|
|
|
|
name: 'Confirm',
|
|
|
|
},
|
|
|
|
})
|
2020-06-01 19:54:32 +02:00
|
|
|
clearConfirmTransaction()
|
|
|
|
history.push(mostRecentOverviewPage)
|
2020-02-19 19:24:16 +01:00
|
|
|
}}
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('provide')}
|
2020-02-19 19:24:16 +01:00
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
render = () => {
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__container">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderHeader()}
|
|
|
|
{this.renderBody()}
|
|
|
|
{this.renderFooter()}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|