import React, { Component } from 'react'; import { connect } from 'react-redux'; import EthTx from 'ethereumjs-tx'; import { addHexPrefix } from 'ethereumjs-util'; import translate from 'translations'; import { getTransactionFields, makeTransaction } from 'libs/transaction'; import { AppState } from 'features/reducers'; import * as derivedSelectors from 'features/selectors'; import { transactionNetworkSelectors, transactionSignSelectors, transactionSelectors } from 'features/transaction'; import { walletSelectors } from 'features/wallet'; import { OfflineBroadcast } from 'components/SendButtonFactory/OfflineBroadcast'; import { CodeBlock } from 'components/ui'; import { WithSigner } from './Container'; export interface CallbackProps { disabled: boolean; isWeb3Wallet: boolean; onClick(): void; } interface StateProps { transaction: EthTx; walletType: walletSelectors.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; export 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) => ({ ...derivedSelectors.getTransaction(state), walletType: walletSelectors.getWalletType(state), serializedTransaction: derivedSelectors.getSerializedTransaction(state), networkRequestPending: transactionNetworkSelectors.isNetworkRequestPending(state), isWeb3Wallet: walletSelectors.getWalletType(state).isWeb3Wallet, validGasPrice: transactionSelectors.isValidGasPrice(state), validGasLimit: transactionSelectors.isValidGasLimit(state), signedTx: !!transactionSignSelectors.getSignedTx(state) }))(GenerateTransactionFactoryClass);