mirror of https://github.com/embarklabs/embark.git
feat(cockpit/transaction): display a link for contracts and accounts
This commit is contained in:
parent
236f6e63e2
commit
74847ee323
|
@ -8,8 +8,22 @@ import Description from './Description';
|
||||||
import CardTitleIdenticon from './CardTitleIdenticon';
|
import CardTitleIdenticon from './CardTitleIdenticon';
|
||||||
import {utils} from 'web3';
|
import {utils} from 'web3';
|
||||||
|
|
||||||
|
function linkTemplate(to, text) {
|
||||||
|
return <Link to={to}>{text}</Link>
|
||||||
|
}
|
||||||
|
|
||||||
const Transaction = ({transaction, contracts}) => (
|
function getLink(contracts, accounts, address) {
|
||||||
|
if (accounts.find(account => account.address === address)) {
|
||||||
|
return linkTemplate(`/explorer/accounts/${address}`, address);
|
||||||
|
}
|
||||||
|
const contract = contracts.find(contract => contract.deployedAddress === address);
|
||||||
|
if (contract) {
|
||||||
|
return linkTemplate(`/explorer/contracts/${contract.className}`, address);
|
||||||
|
}
|
||||||
|
return address
|
||||||
|
}
|
||||||
|
|
||||||
|
const Transaction = ({transaction, contracts, accounts}) => (
|
||||||
<Row>
|
<Row>
|
||||||
<Col>
|
<Col>
|
||||||
<Card>
|
<Card>
|
||||||
|
@ -23,9 +37,9 @@ const Transaction = ({transaction, contracts}) => (
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardBody>
|
<CardBody>
|
||||||
<dl className="row">
|
<dl className="row">
|
||||||
<Description label="Block" value={<Link to={`/explorer/blocks/${transaction.blockNumber}`}>{transaction.blockNumber}</Link>} />
|
<Description label="Block" value={linkTemplate(`/explorer/blocks/${transaction.blockNumber}`, transaction.blockNumber)} />
|
||||||
<Description label="From" value={transaction.from} />
|
<Description label="From" value={getLink(contracts, accounts, transaction.from)} />
|
||||||
<Description label="To" value={transaction.to} />
|
<Description label="To" value={getLink(contracts, accounts, transaction.to)} />
|
||||||
<Description label="Value" value={`${utils.fromWei(transaction.value)} Ether`}/>
|
<Description label="Value" value={`${utils.fromWei(transaction.value)} Ether`}/>
|
||||||
<Description label="Input" value={transaction.input} />
|
<Description label="Input" value={transaction.input} />
|
||||||
<Description label="Gas" value={transaction.gas} />
|
<Description label="Gas" value={transaction.gas} />
|
||||||
|
@ -40,6 +54,7 @@ const Transaction = ({transaction, contracts}) => (
|
||||||
|
|
||||||
Transaction.propTypes = {
|
Transaction.propTypes = {
|
||||||
contracts: PropTypes.arrayOf(PropTypes.object),
|
contracts: PropTypes.arrayOf(PropTypes.object),
|
||||||
|
accounts: PropTypes.arrayOf(PropTypes.object),
|
||||||
transaction: PropTypes.object
|
transaction: PropTypes.object
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,16 @@ import {connect} from 'react-redux';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import {withRouter} from 'react-router-dom';
|
import {withRouter} from 'react-router-dom';
|
||||||
|
|
||||||
import {transaction as transactionAction, contracts as contractsAction} from '../actions';
|
import {transaction as transactionAction, contracts as contractsAction, accounts as accountsAction} from '../actions';
|
||||||
import Transaction from '../components/Transaction';
|
import Transaction from '../components/Transaction';
|
||||||
import DataWrapper from "../components/DataWrapper";
|
import DataWrapper from "../components/DataWrapper";
|
||||||
import PageHead from "../components/PageHead";
|
import PageHead from "../components/PageHead";
|
||||||
import {getTransaction, getContracts} from "../reducers/selectors";
|
import {getTransaction, getContracts, getAccounts} from "../reducers/selectors";
|
||||||
|
|
||||||
class TransactionContainer extends Component {
|
class TransactionContainer extends Component {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.fetchContracts();
|
this.props.fetchContracts();
|
||||||
|
this.props.fetchAccounts();
|
||||||
this.props.fetchTransaction(this.props.match.params.hash);
|
this.props.fetchTransaction(this.props.match.params.hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ class TransactionContainer extends Component {
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<PageHead title={`Transaction ${this.props.match.params.hash}`} description={`View details of transaction ${this.props.match.params.hash}`} />
|
<PageHead title={`Transaction ${this.props.match.params.hash}`} description={`View details of transaction ${this.props.match.params.hash}`} />
|
||||||
<DataWrapper shouldRender={this.props.transaction !== undefined } {...this.props} render={({transaction}) => (
|
<DataWrapper shouldRender={this.props.transaction !== undefined } {...this.props} render={({transaction}) => (
|
||||||
<Transaction contracts={this.props.contracts} transaction={transaction} />
|
<Transaction contracts={this.props.contracts} transaction={transaction} accounts={this.props.accounts} />
|
||||||
)} />
|
)} />
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
|
@ -31,6 +32,7 @@ function mapStateToProps(state, props) {
|
||||||
return {
|
return {
|
||||||
transaction: getTransaction(state, props.match.params.hash),
|
transaction: getTransaction(state, props.match.params.hash),
|
||||||
contracts: getContracts(state),
|
contracts: getContracts(state),
|
||||||
|
accounts: getAccounts(state),
|
||||||
error: state.errorMessage,
|
error: state.errorMessage,
|
||||||
loading: state.loading
|
loading: state.loading
|
||||||
};
|
};
|
||||||
|
@ -40,6 +42,7 @@ TransactionContainer.propTypes = {
|
||||||
match: PropTypes.object,
|
match: PropTypes.object,
|
||||||
transaction: PropTypes.object,
|
transaction: PropTypes.object,
|
||||||
contracts: PropTypes.arrayOf(PropTypes.object),
|
contracts: PropTypes.arrayOf(PropTypes.object),
|
||||||
|
accounts: PropTypes.arrayOf(PropTypes.object),
|
||||||
fetchContracts: PropTypes.func,
|
fetchContracts: PropTypes.func,
|
||||||
fetchTransaction: PropTypes.func,
|
fetchTransaction: PropTypes.func,
|
||||||
error: PropTypes.string
|
error: PropTypes.string
|
||||||
|
@ -49,6 +52,7 @@ export default withRouter(connect(
|
||||||
mapStateToProps,
|
mapStateToProps,
|
||||||
{
|
{
|
||||||
fetchContracts: contractsAction.request,
|
fetchContracts: contractsAction.request,
|
||||||
fetchTransaction: transactionAction.request
|
fetchTransaction: transactionAction.request,
|
||||||
|
fetchAccounts: accountsAction.request
|
||||||
}
|
}
|
||||||
)(TransactionContainer));
|
)(TransactionContainer));
|
||||||
|
|
Loading…
Reference in New Issue