import { WithSigner } from './Container'; import EthTx from 'ethereumjs-tx'; import React, { Component } from 'react'; import { connect } from 'react-redux'; import { AppState } from 'reducers'; import { getTransaction, isNetworkRequestPending, isValidGasPrice, isValidGasLimit, getSignedTx, getSerializedTransaction } from 'selectors/transaction'; import { getWalletType, IWalletType } from 'selectors/wallet'; import { OfflineBroadcast } from 'components/SendButtonFactory/OfflineBroadcast'; import { getTransactionFields, makeTransaction } from 'libs/transaction'; import translate from 'translations'; import { addHexPrefix } from 'ethereumjs-util'; import { CodeBlock } from 'components/ui'; export interface CallbackProps { disabled: boolean; isWeb3Wallet: boolean; onClick(): void; } interface StateProps { transaction: EthTx; walletType: IWalletType; serializedTransaction: AppState['transaction']['sign']['local']['signedTransaction']; networkRequestPending: boolean; isFullTransaction: boolean; isWeb3Wallet: boolean; validGasPrice: boolean; validGasLimit: boolean; signedTx: boolean; } interface OwnProps { withProps(props: CallbackProps): React.ReactElement | null; } type Props = OwnProps & StateProps; class GenerateTransactionFactoryClass extends Component { public render() { const { walletType, serializedTransaction, isFullTransaction, isWeb3Wallet, networkRequestPending, validGasPrice, validGasLimit, transaction, signedTx } = this.props; const getStringifiedTx = (serializedTx: Buffer) => JSON.stringify(getTransactionFields(makeTransaction(serializedTx)), null, 2); const isButtonDisabled = !isFullTransaction || networkRequestPending || !validGasPrice || !validGasLimit; return ( this.props.withProps({ disabled: isButtonDisabled, isWeb3Wallet, onClick: () => signer(transaction) }) } /> {signedTx && ( {/* shows the json representation of the transaction */}
{getStringifiedTx(serializedTransaction as Buffer)}
{serializedTransaction && (
{addHexPrefix(serializedTransaction.toString('hex'))}
)}
)}
); } } export const GenerateTransactionFactory = connect((state: AppState) => ({ ...getTransaction(state), walletType: getWalletType(state), serializedTransaction: getSerializedTransaction(state), networkRequestPending: isNetworkRequestPending(state), isWeb3Wallet: getWalletType(state).isWeb3Wallet, validGasPrice: isValidGasPrice(state), validGasLimit: isValidGasLimit(state), signedTx: !!getSignedTx(state) }))(GenerateTransactionFactoryClass);