import React from 'react'; import translate from 'translations'; import { TransactionData, TransactionReceipt } from 'types/transactions'; import { NetworkConfig } from 'types/network'; import { Identicon, UnitDisplay, NewTabLink, Address, CodeBlock } from 'components/ui'; import './TransactionDataTable.scss'; interface TableRow { label: React.ReactElement | string; data: React.ReactElement | string | number | null; } const MaybeLink: React.SFC<{ href: string | null | undefined | false; children: any; // Too many damn React element types }> = ({ href, children }) => { if (href) { return {children}; } else { return {children}; } }; interface Props { data: TransactionData; receipt: TransactionReceipt | null; network: NetworkConfig; } const TransactionDataTable: React.SFC = ({ data, receipt, network }) => { const explorer: { [key: string]: string | false | null } = {}; const hasInputData = data.input && data.input !== '0x'; if (!network.isCustom) { explorer.tx = network.blockExplorer && network.blockExplorer.txUrl(data.hash); explorer.block = network.blockExplorer && !!data.blockNumber && network.blockExplorer.blockUrl(data.blockNumber); explorer.to = network.blockExplorer && network.blockExplorer.addressUrl(data.to); explorer.from = network.blockExplorer && network.blockExplorer.addressUrl(data.from); explorer.contract = network.blockExplorer && receipt && receipt.contractAddress && network.blockExplorer.addressUrl(receipt.contractAddress); } let statusMsg = ''; let statusType = ''; let statusSeeMore = false; if (receipt) { if (receipt.status === 1) { statusMsg = 'SUCCESSFUL'; statusType = 'success'; } else if (receipt.status === 0) { statusMsg = 'FAILED'; statusType = 'danger'; statusSeeMore = true; } else { // Pre-byzantium transactions don't use status, and cannot have their // success determined over the JSON RPC api statusMsg = 'UNKNOWN'; statusType = 'warning'; statusSeeMore = true; } } else { statusMsg = 'PENDING'; statusType = 'warning'; } const rows: TableRow[] = [ { label: translate('TX_STATUS'), data: ( {statusMsg} {statusSeeMore && explorer.tx && !network.isCustom && ( (See more on {network.blockExplorer.name}) )} ) }, { label: translate('X_TXHASH'), data: {data.hash} }, { label: translate('TX_BLOCK_NUMB'), data: receipt && {receipt.blockNumber} }, { label: translate('OFFLINE_STEP1_LABEL_1'), data: (
) }, { label: translate('OFFLINE_STEP2_LABEL_1'), data: (
) }, { label: translate('SEND_AMOUNT_SHORT'), data: }, { label: translate('OFFLINE_STEP2_LABEL_3'), data: }, { label: translate('OFFLINE_STEP2_LABEL_4'), data: }, { label: translate('TX_GAS_USED'), data: receipt && }, { label: translate('CONFIRM_TX_FEE'), data: receipt && ( ) }, { label: translate('NEW_CONTRACT_ADDR'), data: receipt && receipt.contractAddress && (
) }, { label: translate('OFFLINE_STEP2_LABEL_5'), data: data.nonce }, { label: translate('TRANS_DATA'), data: hasInputData ? {data.input} : null } ]; const filteredRows = rows.filter(row => !!row.data); return ( {filteredRows.map((row, idx) => ( ))}
{row.label} {row.data}
); }; export default TransactionDataTable;