Go through contract links in Transaction List display (#4863)
* Go through contract links (#4822) * Fix tests, add one for /contracts/<address>
This commit is contained in:
parent
96f4033a40
commit
1c37ea5860
@ -35,6 +35,7 @@ class TxRow extends Component {
|
|||||||
static propTypes = {
|
static propTypes = {
|
||||||
accountAddresses: PropTypes.array.isRequired,
|
accountAddresses: PropTypes.array.isRequired,
|
||||||
address: PropTypes.string.isRequired,
|
address: PropTypes.string.isRequired,
|
||||||
|
contractAddresses: PropTypes.array.isRequired,
|
||||||
netVersion: PropTypes.string.isRequired,
|
netVersion: PropTypes.string.isRequired,
|
||||||
tx: PropTypes.object.isRequired,
|
tx: PropTypes.object.isRequired,
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ class TxRow extends Component {
|
|||||||
return (
|
return (
|
||||||
<tr className={ className || '' }>
|
<tr className={ className || '' }>
|
||||||
{ this.renderBlockNumber(tx.blockNumber) }
|
{ this.renderBlockNumber(tx.blockNumber) }
|
||||||
{ this.renderAddress(tx.from) }
|
{ this.renderAddress(tx.from, false) }
|
||||||
<td className={ styles.transaction }>
|
<td className={ styles.transaction }>
|
||||||
{ this.renderEtherValue(tx.value) }
|
{ this.renderEtherValue(tx.value) }
|
||||||
<div>⇒</div>
|
<div>⇒</div>
|
||||||
@ -67,7 +68,7 @@ class TxRow extends Component {
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
{ this.renderAddress(tx.to) }
|
{ this.renderAddress(tx.to || tx.creates, !!tx.creates) }
|
||||||
<td className={ styles.method }>
|
<td className={ styles.method }>
|
||||||
<MethodDecoding
|
<MethodDecoding
|
||||||
historic={ historic }
|
historic={ historic }
|
||||||
@ -79,10 +80,11 @@ class TxRow extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderAddress (address) {
|
renderAddress (address, isDeploy = false) {
|
||||||
|
const isKnownContract = this.getIsKnownContract(address);
|
||||||
let esLink = null;
|
let esLink = null;
|
||||||
|
|
||||||
if (address) {
|
if (address && (!isDeploy || isKnownContract)) {
|
||||||
esLink = (
|
esLink = (
|
||||||
<Link
|
<Link
|
||||||
activeClassName={ styles.currentLink }
|
activeClassName={ styles.currentLink }
|
||||||
@ -103,7 +105,7 @@ class TxRow extends Component {
|
|||||||
<IdentityIcon
|
<IdentityIcon
|
||||||
center
|
center
|
||||||
className={ styles.icon }
|
className={ styles.icon }
|
||||||
address={ address }
|
address={ (!isDeploy || isKnownContract) ? address : '' }
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className={ styles.center }>
|
<div className={ styles.center }>
|
||||||
@ -140,9 +142,22 @@ class TxRow extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getIsKnownContract (address) {
|
||||||
|
const { contractAddresses } = this.props;
|
||||||
|
|
||||||
|
return contractAddresses
|
||||||
|
.map((a) => a.toLowerCase())
|
||||||
|
.includes(address.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
addressLink (address) {
|
addressLink (address) {
|
||||||
const { accountAddresses } = this.props;
|
const { accountAddresses } = this.props;
|
||||||
const isAccount = accountAddresses.includes(address);
|
const isAccount = accountAddresses.includes(address);
|
||||||
|
const isContract = this.getIsKnownContract(address);
|
||||||
|
|
||||||
|
if (isContract) {
|
||||||
|
return `/contracts/${address}`;
|
||||||
|
}
|
||||||
|
|
||||||
if (isAccount) {
|
if (isAccount) {
|
||||||
return `/accounts/${address}`;
|
return `/accounts/${address}`;
|
||||||
@ -153,14 +168,16 @@ class TxRow extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mapStateToProps (initState) {
|
function mapStateToProps (initState) {
|
||||||
const { accounts } = initState.personal;
|
const { accounts, contracts } = initState.personal;
|
||||||
const accountAddresses = Object.keys(accounts);
|
const accountAddresses = Object.keys(accounts);
|
||||||
|
const contractAddresses = Object.keys(contracts);
|
||||||
|
|
||||||
return (state) => {
|
return (state) => {
|
||||||
const { netVersion } = state.nodeStatus;
|
const { netVersion } = state.nodeStatus;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
accountAddresses,
|
accountAddresses,
|
||||||
|
contractAddresses,
|
||||||
netVersion
|
netVersion
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -35,7 +35,14 @@ const STORE = {
|
|||||||
},
|
},
|
||||||
personal: {
|
personal: {
|
||||||
accounts: {
|
accounts: {
|
||||||
'0x123': {}
|
'0x123': {
|
||||||
|
address: '0x123'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
contracts: {
|
||||||
|
'0x999': {
|
||||||
|
address: '0x999'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -60,19 +67,22 @@ describe('ui/TxList/TxRow', () => {
|
|||||||
};
|
};
|
||||||
const tx = {
|
const tx = {
|
||||||
blockNumber: new BigNumber(123),
|
blockNumber: new BigNumber(123),
|
||||||
|
from: '0x234',
|
||||||
hash: '0x123456789abcdef0123456789abcdef0123456789abcdef',
|
hash: '0x123456789abcdef0123456789abcdef0123456789abcdef',
|
||||||
|
to: '0x123',
|
||||||
value: new BigNumber(1)
|
value: new BigNumber(1)
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(render({ address: '0x123', block, netVersion: '42', tx })).to.be.ok;
|
expect(render({ address: '0x123', block, netVersion: '42', tx })).to.be.ok;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders an account link', () => {
|
it('renders account links', () => {
|
||||||
const block = {
|
const block = {
|
||||||
timestamp: new Date()
|
timestamp: new Date()
|
||||||
};
|
};
|
||||||
const tx = {
|
const tx = {
|
||||||
blockNumber: new BigNumber(123),
|
blockNumber: new BigNumber(123),
|
||||||
|
from: '0x234',
|
||||||
hash: '0x123456789abcdef0123456789abcdef0123456789abcdef',
|
hash: '0x123456789abcdef0123456789abcdef0123456789abcdef',
|
||||||
to: '0x123',
|
to: '0x123',
|
||||||
value: new BigNumber(1)
|
value: new BigNumber(1)
|
||||||
@ -80,15 +90,16 @@ describe('ui/TxList/TxRow', () => {
|
|||||||
|
|
||||||
const element = render({ address: '0x123', block, netVersion: '42', tx });
|
const element = render({ address: '0x123', block, netVersion: '42', tx });
|
||||||
|
|
||||||
expect(element.find('Link').prop('to')).to.equal('/accounts/0x123');
|
expect(element.find('Link').get(1).props.to).to.equal('/accounts/0x123');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders an address link', () => {
|
it('renders address links', () => {
|
||||||
const block = {
|
const block = {
|
||||||
timestamp: new Date()
|
timestamp: new Date()
|
||||||
};
|
};
|
||||||
const tx = {
|
const tx = {
|
||||||
blockNumber: new BigNumber(123),
|
blockNumber: new BigNumber(123),
|
||||||
|
from: '0x234',
|
||||||
hash: '0x123456789abcdef0123456789abcdef0123456789abcdef',
|
hash: '0x123456789abcdef0123456789abcdef0123456789abcdef',
|
||||||
to: '0x456',
|
to: '0x456',
|
||||||
value: new BigNumber(1)
|
value: new BigNumber(1)
|
||||||
@ -96,7 +107,24 @@ describe('ui/TxList/TxRow', () => {
|
|||||||
|
|
||||||
const element = render({ address: '0x123', block, netVersion: '42', tx });
|
const element = render({ address: '0x123', block, netVersion: '42', tx });
|
||||||
|
|
||||||
expect(element.find('Link').prop('to')).to.equal('/addresses/0x456');
|
expect(element.find('Link').get(1).props.to).to.equal('/addresses/0x456');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders contract links', () => {
|
||||||
|
const block = {
|
||||||
|
timestamp: new Date()
|
||||||
|
};
|
||||||
|
const tx = {
|
||||||
|
blockNumber: new BigNumber(123),
|
||||||
|
from: '0x234',
|
||||||
|
hash: '0x123456789abcdef0123456789abcdef0123456789abcdef',
|
||||||
|
to: '0x999',
|
||||||
|
value: new BigNumber(1)
|
||||||
|
};
|
||||||
|
|
||||||
|
const element = render({ address: '0x123', block, netVersion: '42', tx });
|
||||||
|
|
||||||
|
expect(element.find('Link').get(1).props.to).to.equal('/contracts/0x999');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user