import log from 'loglevel'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import copyToClipboard from 'copy-to-clipboard'; import Button from '../../../ui/button'; import AccountModalContainer from '../account-modal-container'; import { toChecksumHexAddress, stripHexPrefix, } from '../../../../../shared/modules/hexstring-utils'; import { MetaMetricsEventCategory, MetaMetricsEventKeyType, MetaMetricsEventName, } from '../../../../../shared/constants/metametrics'; export default class ExportPrivateKeyModal extends Component { static contextTypes = { t: PropTypes.func, trackEvent: PropTypes.func, }; static defaultProps = { warning: null, previousModalState: null, }; static propTypes = { exportAccount: PropTypes.func.isRequired, selectedIdentity: PropTypes.object.isRequired, warning: PropTypes.node, showAccountDetailModal: PropTypes.func.isRequired, hideModal: PropTypes.func.isRequired, hideWarning: PropTypes.func.isRequired, clearAccountDetails: PropTypes.func.isRequired, previousModalState: PropTypes.string, }; state = { password: '', privateKey: null, showWarning: true, }; componentWillUnmount() { this.props.clearAccountDetails(); this.props.hideWarning(); } exportAccountAndGetPrivateKey = (password, address) => { const { exportAccount } = this.props; exportAccount(password, address) .then((privateKey) => { this.context.trackEvent({ category: MetaMetricsEventCategory.Keys, event: MetaMetricsEventName.KeyExportRevealed, properties: { key_type: MetaMetricsEventKeyType.Pkey, }, }); this.setState({ privateKey, showWarning: false, }); }) .catch((e) => { this.context.trackEvent({ category: MetaMetricsEventCategory.Keys, event: MetaMetricsEventName.KeyExportFailed, properties: { key_type: MetaMetricsEventKeyType.Pkey, reason: 'incorrect_password', }, }); log.error(e); }); }; renderPasswordLabel(privateKey) { return ( {privateKey ? this.context.t('copyPrivateKey') : this.context.t('typePassword')} ); } renderPasswordInput(privateKey) { const plainKey = privateKey && stripHexPrefix(privateKey); if (!privateKey) { return ( this.setState({ password: event.target.value })} /> ); } return (