Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Go through contract links in Transaction List display (#4863)
Browse files Browse the repository at this point in the history
* Go through contract links (#4822)

* Fix tests, add one for /contracts/<address>
  • Loading branch information
ngotchac authored and gavofyork committed Mar 11, 2017
1 parent 96f4033 commit 1c37ea5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 11 deletions.
29 changes: 23 additions & 6 deletions js/src/ui/TxList/TxRow/txRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class TxRow extends Component {
static propTypes = {
accountAddresses: PropTypes.array.isRequired,
address: PropTypes.string.isRequired,
contractAddresses: PropTypes.array.isRequired,
netVersion: PropTypes.string.isRequired,
tx: PropTypes.object.isRequired,

Expand All @@ -53,7 +54,7 @@ class TxRow extends Component {
return (
<tr className={ className || '' }>
{ this.renderBlockNumber(tx.blockNumber) }
{ this.renderAddress(tx.from) }
{ this.renderAddress(tx.from, false) }
<td className={ styles.transaction }>
{ this.renderEtherValue(tx.value) }
<div></div>
Expand All @@ -67,7 +68,7 @@ class TxRow extends Component {
</a>
</div>
</td>
{ this.renderAddress(tx.to) }
{ this.renderAddress(tx.to || tx.creates, !!tx.creates) }
<td className={ styles.method }>
<MethodDecoding
historic={ historic }
Expand All @@ -79,10 +80,11 @@ class TxRow extends Component {
);
}

renderAddress (address) {
renderAddress (address, isDeploy = false) {
const isKnownContract = this.getIsKnownContract(address);
let esLink = null;

if (address) {
if (address && (!isDeploy || isKnownContract)) {
esLink = (
<Link
activeClassName={ styles.currentLink }
Expand All @@ -103,7 +105,7 @@ class TxRow extends Component {
<IdentityIcon
center
className={ styles.icon }
address={ address }
address={ (!isDeploy || isKnownContract) ? address : '' }
/>
</div>
<div className={ styles.center }>
Expand Down Expand Up @@ -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) {
const { accountAddresses } = this.props;
const isAccount = accountAddresses.includes(address);
const isContract = this.getIsKnownContract(address);

if (isContract) {
return `/contracts/${address}`;
}

if (isAccount) {
return `/accounts/${address}`;
Expand All @@ -153,14 +168,16 @@ class TxRow extends Component {
}

function mapStateToProps (initState) {
const { accounts } = initState.personal;
const { accounts, contracts } = initState.personal;
const accountAddresses = Object.keys(accounts);
const contractAddresses = Object.keys(contracts);

return (state) => {
const { netVersion } = state.nodeStatus;

return {
accountAddresses,
contractAddresses,
netVersion
};
};
Expand Down
38 changes: 33 additions & 5 deletions js/src/ui/TxList/TxRow/txRow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ const STORE = {
},
personal: {
accounts: {
'0x123': {}
'0x123': {
address: '0x123'
}
},
contracts: {
'0x999': {
address: '0x999'
}
}
}
};
Expand All @@ -60,43 +67,64 @@ describe('ui/TxList/TxRow', () => {
};
const tx = {
blockNumber: new BigNumber(123),
from: '0x234',
hash: '0x123456789abcdef0123456789abcdef0123456789abcdef',
to: '0x123',
value: new BigNumber(1)
};

expect(render({ address: '0x123', block, netVersion: '42', tx })).to.be.ok;
});

it('renders an account link', () => {
it('renders account links', () => {
const block = {
timestamp: new Date()
};
const tx = {
blockNumber: new BigNumber(123),
from: '0x234',
hash: '0x123456789abcdef0123456789abcdef0123456789abcdef',
to: '0x123',
value: new BigNumber(1)
};

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 = {
timestamp: new Date()
};
const tx = {
blockNumber: new BigNumber(123),
from: '0x234',
hash: '0x123456789abcdef0123456789abcdef0123456789abcdef',
to: '0x456',
value: new BigNumber(1)
};

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');
});
});
});

0 comments on commit 1c37ea5

Please sign in to comment.