import React from 'react'; import translate from 'translations'; import { Identicon, UnitDisplay, NewTabLink } from 'components/ui'; import { TransactionData, TransactionReceipt } from 'libs/nodes'; import { NetworkConfig } from 'types/network'; 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: 'Status', data: ( {statusMsg} {statusSeeMore && explorer.tx && !network.isCustom && ( (See more on {network.blockExplorer.name}) )} ) }, { label: translate('x_TxHash'), data: {data.hash} }, { label: 'Block Number', data: receipt && {receipt.blockNumber} }, { label: translate('OFFLINE_Step1_Label_1'), data: ( {data.from} ) }, { label: translate('OFFLINE_Step2_Label_1'), data: ( {data.to} ) }, { label: translate('SEND_amount_short'), data: }, { label: translate('OFFLINE_Step2_Label_3'), data: }, { label: translate('OFFLINE_Step2_Label_4'), data: }, { label: 'Gas Used', data: receipt && }, { label: 'Transaction Fee', data: receipt && ( ) }, { label: translate('New contract address'), data: receipt && receipt.contractAddress && ( {receipt.contractAddress} ) }, { label: translate('OFFLINE_Step2_Label_5'), data: data.nonce }, { label: translate('TRANS_data'), data: hasInputData ? (