import Identicon from 'components/ui/Identicon'; import Modal, { IButton } from 'components/ui/Modal'; import Spinner from 'components/ui/Spinner'; import { NetworkConfig, NodeConfig } from 'config/data'; import EthTx from 'ethereumjs-tx'; import { BroadcastTransactionStatus, getTransactionFields, decodeTransaction } from 'libs/transaction'; import React from 'react'; import { connect } from 'react-redux'; import { getLanguageSelection, getNetworkConfig, getNodeConfig } from 'selectors/config'; import { getTokens, getTxFromState, MergedToken } from 'selectors/wallet'; import translate, { translateRaw } from 'translations'; import './ConfirmationModal.scss'; interface Props { signedTx: string; transaction: EthTx; node: NodeConfig; token: MergedToken; network: NetworkConfig; lang: string; broadCastTxStatus: BroadcastTransactionStatus; onConfirm(signedTx: string): void; onClose(): void; } interface State { timeToRead: number; hasBroadCasted: boolean; } class ConfirmationModal extends React.Component { public state = { timeToRead: 5, hasBroadCasted: false }; private readTimer = 0; public componentDidUpdate() { if ( this.state.hasBroadCasted && this.props.broadCastTxStatus && !this.props.broadCastTxStatus.isBroadcasting ) { this.props.onClose(); } } // Count down 5 seconds before allowing them to confirm public componentDidMount() { this.readTimer = window.setInterval(() => { if (this.state.timeToRead > 0) { this.setState({ timeToRead: this.state.timeToRead - 1 }); } else { window.clearInterval(this.readTimer); } }, 1000); } public render() { const { node, token, network, onClose, broadCastTxStatus, transaction } = this.props; const { timeToRead } = this.state; const { toAddress, value, gasPrice, data, from, nonce } = decodeTransaction( transaction, token ); const buttonPrefix = timeToRead > 0 ? `(${timeToRead}) ` : ''; const buttons: IButton[] = [ { text: buttonPrefix + translateRaw('SENDModal_Yes'), type: 'primary', disabled: timeToRead > 0, onClick: this.confirm }, { text: translateRaw('SENDModal_No'), type: 'default', onClick: onClose } ]; const symbol = token ? token.symbol : network.unit; const isBroadcasting = broadCastTxStatus && broadCastTxStatus.isBroadcasting; return (
{
{isBroadcasting ? (
) : (
{value} {symbol}
  • You are sending from {from}
  • You are sending to {toAddress}
  • You are sending with a nonce of {nonce}
  • You are sending{' '} {value} {symbol} {' '} with a gas price of {gasPrice} gwei
  • You are interacting with the{' '} {node.network}{' '} network provided by {node.service}
  • {!token && (
  • {data ? ( You are sending the following data:{' '}