import React, { Component } from 'react'; import { connect } from 'react-redux'; import TabSection from 'containers/TabSection'; import translate from 'translations'; import { signLocalTransactionSucceeded, TSignLocalTransactionSucceeded, signTransactionFailed, TSignTransactionFailed } from 'actions/transaction'; import { computeIndexingHash, getTransactionFields, makeTransaction } from 'libs/transaction'; import { QRCode, Input, CodeBlock } from 'components/ui'; import EthTx from 'ethereumjs-tx'; import { SendButton } from 'components/SendButton'; import { toBuffer, bufferToHex } from 'ethereumjs-util'; import { getSerializedTransaction } from 'selectors/transaction'; import { AppState } from 'reducers'; import './index.scss'; import { Switch, Route, RouteComponentProps } from 'react-router'; import { RouteNotFound } from 'components/RouteNotFound'; interface StateProps { stateTransaction: AppState['transaction']['sign']['local']['signedTransaction']; } interface DispatchProps { signLocalTransactionSucceeded: TSignLocalTransactionSucceeded; signTransactionFailed: TSignTransactionFailed; } interface State { userInput: string; } const INITIAL_STATE: State = { userInput: '' }; type Props = DispatchProps & StateProps & RouteComponentProps<{}>; const getStringifiedTx = (serializedTx: Buffer) => JSON.stringify(getTransactionFields(makeTransaction(serializedTx)), null, 2); class BroadcastTx extends Component { public state: State = INITIAL_STATE; public render() { const { userInput } = this.state; const { stateTransaction } = this.props; const currentPath = this.props.match.url; return (
(

{translate('BROADCAST_TX_TITLE')}

{translate('BROADCAST_TX_DESCRIPTION')}

{stateTransaction && ( {getStringifiedTx(stateTransaction)} )}
{stateTransaction && }
)} />
); } protected handleChange = ({ currentTarget }: React.FormEvent) => { const { value } = currentTarget; this.setState({ userInput: value }); try { const bufferTransaction = toBuffer(value); const tx = new EthTx(bufferTransaction); if (!tx.verifySignature()) { throw Error(); } const indexingHash = computeIndexingHash(bufferTransaction); this.props.signLocalTransactionSucceeded({ signedTransaction: bufferTransaction, indexingHash, noVerify: true }); } catch { this.props.signTransactionFailed(); } }; } export default connect( (state: AppState) => ({ stateTransaction: getSerializedTransaction(state) }), { signLocalTransactionSucceeded, signTransactionFailed } )(BroadcastTx);