2018-02-16 16:57:23 +00:00
|
|
|
import React from 'react';
|
|
|
|
import translate from 'translations';
|
2018-03-23 16:41:47 +00:00
|
|
|
import { Identicon, UnitDisplay, NewTabLink, Address, CodeBlock } from 'components/ui';
|
2018-03-14 20:10:14 +00:00
|
|
|
import { TransactionData, TransactionReceipt } from 'types/transactions';
|
2018-02-16 16:57:23 +00:00
|
|
|
import { NetworkConfig } from 'types/network';
|
|
|
|
import './TransactionDataTable.scss';
|
|
|
|
|
|
|
|
interface TableRow {
|
|
|
|
label: React.ReactElement<string> | string;
|
|
|
|
data: React.ReactElement<string> | 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 <NewTabLink href={href}>{children}</NewTabLink>;
|
|
|
|
} else {
|
|
|
|
return <React.Fragment>{children}</React.Fragment>;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
data: TransactionData;
|
|
|
|
receipt: TransactionReceipt | null;
|
|
|
|
network: NetworkConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TransactionDataTable: React.SFC<Props> = ({ 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[] = [
|
|
|
|
{
|
2018-03-22 03:50:25 +00:00
|
|
|
label: translate('TX_STATUS'),
|
2018-02-16 16:57:23 +00:00
|
|
|
data: (
|
|
|
|
<React.Fragment>
|
|
|
|
<strong className={`TxData-row-data-status is-${statusType}`}>{statusMsg}</strong>
|
|
|
|
{statusSeeMore &&
|
|
|
|
explorer.tx &&
|
|
|
|
!network.isCustom && (
|
2018-03-27 04:04:08 +00:00
|
|
|
<NewTabLink className="TxData-row-data-more" href={explorer.tx}>
|
2018-02-16 16:57:23 +00:00
|
|
|
(See more on {network.blockExplorer.name})
|
|
|
|
</NewTabLink>
|
|
|
|
)}
|
|
|
|
</React.Fragment>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
{
|
2018-03-22 03:50:25 +00:00
|
|
|
label: translate('X_TXHASH'),
|
2018-02-16 16:57:23 +00:00
|
|
|
data: <MaybeLink href={explorer.tx}>{data.hash}</MaybeLink>
|
|
|
|
},
|
|
|
|
{
|
2018-03-22 03:50:25 +00:00
|
|
|
label: translate('TX_BLOCK_NUMB'),
|
2018-02-16 16:57:23 +00:00
|
|
|
data: receipt && <MaybeLink href={explorer.block}>{receipt.blockNumber}</MaybeLink>
|
|
|
|
},
|
|
|
|
{
|
2018-03-22 03:50:25 +00:00
|
|
|
label: translate('OFFLINE_STEP1_LABEL_1'),
|
2018-02-16 16:57:23 +00:00
|
|
|
data: (
|
|
|
|
<MaybeLink href={explorer.from}>
|
|
|
|
<Identicon address={data.from} size="26px" />
|
2018-03-01 02:54:43 +00:00
|
|
|
<Address address={data.from} />
|
2018-02-16 16:57:23 +00:00
|
|
|
</MaybeLink>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
{
|
2018-03-22 03:50:25 +00:00
|
|
|
label: translate('OFFLINE_STEP2_LABEL_1'),
|
2018-02-16 16:57:23 +00:00
|
|
|
data: (
|
|
|
|
<MaybeLink href={explorer.to}>
|
|
|
|
<Identicon address={data.to} size="26px" />
|
2018-03-01 02:54:43 +00:00
|
|
|
<Address address={data.to} />
|
2018-02-16 16:57:23 +00:00
|
|
|
</MaybeLink>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
{
|
2018-03-22 03:50:25 +00:00
|
|
|
label: translate('SEND_AMOUNT_SHORT'),
|
2018-02-16 16:57:23 +00:00
|
|
|
data: <UnitDisplay value={data.value} unit="ether" symbol={network.unit} />
|
|
|
|
},
|
|
|
|
{
|
2018-03-22 03:50:25 +00:00
|
|
|
label: translate('OFFLINE_STEP2_LABEL_3'),
|
2018-02-16 16:57:23 +00:00
|
|
|
data: <UnitDisplay value={data.gasPrice} unit="gwei" symbol="Gwei" />
|
|
|
|
},
|
|
|
|
{
|
2018-03-22 03:50:25 +00:00
|
|
|
label: translate('OFFLINE_STEP2_LABEL_4'),
|
2018-02-16 16:57:23 +00:00
|
|
|
data: <UnitDisplay value={data.gas} unit="wei" />
|
|
|
|
},
|
|
|
|
{
|
2018-03-22 03:50:25 +00:00
|
|
|
label: translate('TX_GAS_USED'),
|
2018-02-16 16:57:23 +00:00
|
|
|
data: receipt && <UnitDisplay value={receipt.gasUsed} unit="wei" />
|
|
|
|
},
|
|
|
|
{
|
2018-03-22 03:50:25 +00:00
|
|
|
label: translate('CONFIRM_TX_FEE'),
|
2018-02-16 16:57:23 +00:00
|
|
|
data: receipt && (
|
|
|
|
<UnitDisplay
|
|
|
|
value={receipt.gasUsed.mul(data.gasPrice)}
|
|
|
|
unit="ether"
|
|
|
|
symbol={network.unit}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
{
|
2018-03-22 03:50:25 +00:00
|
|
|
label: translate('NEW_CONTRACT_ADDR'),
|
2018-02-16 16:57:23 +00:00
|
|
|
data: receipt &&
|
|
|
|
receipt.contractAddress && (
|
2018-03-01 02:54:43 +00:00
|
|
|
<MaybeLink href={explorer.contract}>
|
|
|
|
<Address address={receipt.contractAddress} />
|
|
|
|
</MaybeLink>
|
2018-02-16 16:57:23 +00:00
|
|
|
)
|
|
|
|
},
|
|
|
|
{
|
2018-03-22 03:50:25 +00:00
|
|
|
label: translate('OFFLINE_STEP2_LABEL_5'),
|
2018-02-16 16:57:23 +00:00
|
|
|
data: data.nonce
|
|
|
|
},
|
|
|
|
{
|
2018-03-22 03:50:25 +00:00
|
|
|
label: translate('TRANS_DATA'),
|
2018-03-23 16:41:47 +00:00
|
|
|
data: hasInputData ? <CodeBlock>{data.input}</CodeBlock> : null
|
2018-02-16 16:57:23 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
const filteredRows = rows.filter(row => !!row.data);
|
|
|
|
return (
|
|
|
|
<table className="TxData table table-striped">
|
|
|
|
<tbody>
|
|
|
|
{filteredRows.map((row, idx) => (
|
|
|
|
<tr className="TxData-row" key={idx}>
|
|
|
|
<td className="TxData-row-label">{row.label}</td>
|
|
|
|
<td className="TxData-row-data">{row.data}</td>
|
|
|
|
</tr>
|
|
|
|
))}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default TransactionDataTable;
|