import React, { Component } from 'react' import PropTypes from 'prop-types' import AccountListItem from '../send/account-list-item/account-list-item.component' import Button from '../../components/ui/button' import Identicon from '../../components/ui/identicon' import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../app/scripts/lib/enums' import { getEnvironmentType } from '../../../../app/scripts/lib/util' import { conversionUtil } from '../../helpers/utils/conversion-util' import { DEFAULT_ROUTE } from '../../helpers/constants/routes' export default class ConfirmEncryptionPublicKey extends Component { static contextTypes = { t: PropTypes.func.isRequired, metricsEvent: PropTypes.func.isRequired, } static propTypes = { fromAccount: PropTypes.shape({ address: PropTypes.string.isRequired, balance: PropTypes.string, name: PropTypes.string, }).isRequired, 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, } state = { fromAccount: this.props.fromAccount, } componentDidMount = () => { if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION) { window.addEventListener('beforeunload', this._beforeUnload) } } componentWillUnmount = () => { this._removeBeforeUnload() } _beforeUnload = (event) => { const { clearConfirmTransaction, cancelEncryptionPublicKey } = this.props const { metricsEvent } = this.context metricsEvent({ eventOpts: { category: 'Messages', action: 'Encryption public key Request', name: 'Cancel Via Notification Close', }, }) clearConfirmTransaction() cancelEncryptionPublicKey(event) } _removeBeforeUnload = () => { if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION) { window.removeEventListener('beforeunload', this._beforeUnload) } } renderHeader = () => { return (
{ this.context.t('encryptionPublicKeyRequest') }
) } renderAccount = () => { const { fromAccount } = this.state return (
{ `${this.context.t('account')}:` }
) } renderBalance = () => { const { conversionRate } = this.props const { fromAccount: { balance } } = this.state const balanceInEther = conversionUtil(balance, { fromNumericBase: 'hex', toNumericBase: 'dec', fromDenomination: 'WEI', numberOfDecimals: 6, conversionRate, }) return (
{ `${this.context.t('balance')}:` }
{ `${balanceInEther} ETH` }
) } renderRequestIcon = () => { const { requesterAddress } = this.props return (
) } renderAccountInfo = () => { return (
{ this.renderAccount() } { this.renderRequestIcon() } { this.renderBalance() }
) } renderBody = () => { const { txData } = this.props const origin = this.props.domainMetadata[txData.origin] const notice = this.context.t('encryptionPublicKeyNotice', [origin.name]) return (
{ this.renderAccountInfo() }
{origin.icon ? ( ) : ( {origin.name.charAt(0).toUpperCase()} )}
{ notice }
) } renderFooter = () => { const { txData } = this.props return (
) } render = () => { return (
{ this.renderHeader() } { this.renderBody() } { this.renderFooter() }
) } }