import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; import Identicon from '../../ui/identicon'; import LedgerInstructionField from '../ledger-instruction-field'; import Header from './signature-request-header'; import Footer from './signature-request-footer'; import Message from './signature-request-message'; export default class SignatureRequest extends PureComponent { static propTypes = { txData: PropTypes.object.isRequired, fromAccount: PropTypes.shape({ address: PropTypes.string.isRequired, balance: PropTypes.string, name: PropTypes.string, }).isRequired, isLedgerWallet: PropTypes.bool, cancel: PropTypes.func.isRequired, sign: PropTypes.func.isRequired, hardwareWalletRequiresConnection: PropTypes.func.isRequired, }; static contextTypes = { t: PropTypes.func, metricsEvent: PropTypes.func, }; formatWallet(wallet) { return `${wallet.slice(0, 8)}...${wallet.slice( wallet.length - 8, wallet.length, )}`; } render() { const { fromAccount, txData: { msgParams: { data, origin, version }, type, }, cancel, sign, isLedgerWallet, hardwareWalletRequiresConnection, } = this.props; const { address: fromAddress } = fromAccount; const { message, domain = {} } = JSON.parse(data); const { metricsEvent } = this.context; const onSign = (event) => { sign(event); metricsEvent({ eventOpts: { category: 'Transactions', action: 'Sign Request', name: 'Confirm', }, customVariables: { type, version, }, }); }; const onCancel = (event) => { cancel(event); metricsEvent({ eventOpts: { category: 'Transactions', action: 'Sign Request', name: 'Cancel', }, customVariables: { type, version, }, }); }; return (
{this.context.t('sigRequest')}
{domain.name && domain.name[0]}
{domain.name}
{origin}
{this.formatWallet(fromAddress)}
{isLedgerWallet ? (
) : null}
); } }