Fix TxViewer when no to
(contract deployment) (#4847)
* Added React Hot Reload to dapps + TokenDeplpoy fix * Fixes to the LocalTx dapp * Don't send the nonce for mined transactions * Don't encode empty to values for options
This commit is contained in:
parent
5e54c0fa91
commit
be87151f1c
@ -143,8 +143,15 @@ export function inOptions (options) {
|
|||||||
if (options) {
|
if (options) {
|
||||||
Object.keys(options).forEach((key) => {
|
Object.keys(options).forEach((key) => {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'from':
|
|
||||||
case 'to':
|
case 'to':
|
||||||
|
// Don't encode the `to` option if it's empty
|
||||||
|
// (eg. contract deployments)
|
||||||
|
if (options[key]) {
|
||||||
|
options[key] = inAddress(options[key]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'from':
|
||||||
options[key] = inAddress(options[key]);
|
options[key] = inAddress(options[key]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -208,6 +208,13 @@ describe('api/format/input', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not encode an empty `to` value', () => {
|
||||||
|
const options = { to: '' };
|
||||||
|
const formatted = inOptions(options);
|
||||||
|
|
||||||
|
expect(formatted.to).to.equal('');
|
||||||
|
});
|
||||||
|
|
||||||
['gas', 'gasPrice', 'value', 'minBlock', 'nonce'].forEach((input) => {
|
['gas', 'gasPrice', 'value', 'minBlock', 'nonce'].forEach((input) => {
|
||||||
it(`formats ${input} number as hexnumber`, () => {
|
it(`formats ${input} number as hexnumber`, () => {
|
||||||
const block = {};
|
const block = {};
|
||||||
|
@ -15,5 +15,29 @@
|
|||||||
th {
|
th {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
background-color: rgba(0, 136, 170, 1);
|
||||||
|
border: none;
|
||||||
|
border-radius: 5px;
|
||||||
|
color: white;
|
||||||
|
font-size: 1rem;
|
||||||
|
padding: 0.5em 1em;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: rgba(0, 136, 170, 0.8);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
font-size: 1rem;
|
||||||
|
padding: 0.5em 1em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,6 @@ export default class Application extends Component {
|
|||||||
local[tx.hash].transaction = tx;
|
local[tx.hash].transaction = tx;
|
||||||
local[tx.hash].stats = data.stats;
|
local[tx.hash].stats = data.stats;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Convert local transactions to array
|
// Convert local transactions to array
|
||||||
const localTransactions = Object.keys(local).map(hash => {
|
const localTransactions = Object.keys(local).map(hash => {
|
||||||
const data = local[hash];
|
const data = local[hash];
|
||||||
|
@ -6,6 +6,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.txhash {
|
||||||
|
display: inline-block;
|
||||||
|
overflow: hidden;
|
||||||
|
padding-right: 3ch;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
width: 10ch;
|
||||||
|
}
|
||||||
|
|
||||||
.transaction {
|
.transaction {
|
||||||
td {
|
td {
|
||||||
padding: 7px 15px;
|
padding: 7px 15px;
|
||||||
|
@ -31,8 +31,8 @@ class BaseTransaction extends Component {
|
|||||||
|
|
||||||
renderHash (hash) {
|
renderHash (hash) {
|
||||||
return (
|
return (
|
||||||
<code title={ hash }>
|
<code title={ hash } className={ styles.txhash }>
|
||||||
{ this.shortHash(hash) }
|
{ hash }
|
||||||
</code>
|
</code>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -206,7 +206,10 @@ export class LocalTransaction extends BaseTransaction {
|
|||||||
From
|
From
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
Gas Price / Gas
|
Gas Price
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Gas
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
Status
|
Status
|
||||||
@ -224,18 +227,18 @@ export class LocalTransaction extends BaseTransaction {
|
|||||||
|
|
||||||
toggleResubmit = () => {
|
toggleResubmit = () => {
|
||||||
const { transaction } = this.props;
|
const { transaction } = this.props;
|
||||||
const { isResubmitting, gasPrice } = this.state;
|
const { isResubmitting } = this.state;
|
||||||
|
|
||||||
this.setState({
|
const nextState = {
|
||||||
isResubmitting: !isResubmitting
|
isResubmitting: !isResubmitting
|
||||||
});
|
};
|
||||||
|
|
||||||
if (gasPrice === null) {
|
if (!isResubmitting) {
|
||||||
this.setState({
|
nextState.gasPrice = api.util.fromWei(transaction.gasPrice, 'shannon').toNumber();
|
||||||
gasPrice: `0x${transaction.gasPrice.toString(16)}`,
|
nextState.gas = transaction.gas.div(1000000).toNumber();
|
||||||
gas: `0x${transaction.gas.toString(16)}`
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.setState(nextState);
|
||||||
};
|
};
|
||||||
|
|
||||||
setGasPrice = el => {
|
setGasPrice = el => {
|
||||||
@ -251,16 +254,15 @@ export class LocalTransaction extends BaseTransaction {
|
|||||||
};
|
};
|
||||||
|
|
||||||
sendTransaction = () => {
|
sendTransaction = () => {
|
||||||
const { transaction } = this.props;
|
const { transaction, status } = this.props;
|
||||||
const { gasPrice, gas } = this.state;
|
const { gasPrice, gas } = this.state;
|
||||||
|
|
||||||
const newTransaction = {
|
const newTransaction = {
|
||||||
from: transaction.from,
|
from: transaction.from,
|
||||||
to: transaction.to,
|
|
||||||
nonce: transaction.nonce,
|
|
||||||
value: transaction.value,
|
value: transaction.value,
|
||||||
data: transaction.input,
|
data: transaction.input,
|
||||||
gasPrice, gas
|
gasPrice: api.util.toWei(gasPrice, 'shannon'),
|
||||||
|
gas: new BigNumber(gas).mul(1000000)
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
@ -268,11 +270,21 @@ export class LocalTransaction extends BaseTransaction {
|
|||||||
isSending: true
|
isSending: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const closeSending = () => this.setState({
|
const closeSending = () => {
|
||||||
|
this.setState({
|
||||||
isSending: false,
|
isSending: false,
|
||||||
gasPrice: null,
|
gasPrice: null,
|
||||||
gas: null
|
gas: null
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (transaction.to) {
|
||||||
|
newTransaction.to = transaction.to;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!['mined', 'replaced'].includes(status)) {
|
||||||
|
newTransaction.nonce = transaction.nonce;
|
||||||
|
}
|
||||||
|
|
||||||
api.eth.sendTransaction(newTransaction)
|
api.eth.sendTransaction(newTransaction)
|
||||||
.then(closeSending)
|
.then(closeSending)
|
||||||
@ -290,9 +302,9 @@ export class LocalTransaction extends BaseTransaction {
|
|||||||
const resubmit = isSending ? (
|
const resubmit = isSending ? (
|
||||||
'sending...'
|
'sending...'
|
||||||
) : (
|
) : (
|
||||||
<a href='javascript:void' onClick={ this.toggleResubmit }>
|
<button onClick={ this.toggleResubmit }>
|
||||||
resubmit
|
resubmit
|
||||||
</a>
|
</button>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -308,7 +320,8 @@ export class LocalTransaction extends BaseTransaction {
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{ this.renderGasPrice(transaction) }
|
{ this.renderGasPrice(transaction) }
|
||||||
<br />
|
</td>
|
||||||
|
<td>
|
||||||
{ this.renderGas(transaction) }
|
{ this.renderGas(transaction) }
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@ -345,9 +358,9 @@ export class LocalTransaction extends BaseTransaction {
|
|||||||
return (
|
return (
|
||||||
<tr className={ styles.transaction }>
|
<tr className={ styles.transaction }>
|
||||||
<td>
|
<td>
|
||||||
<a href='javascript:void' onClick={ this.toggleResubmit }>
|
<button onClick={ this.toggleResubmit }>
|
||||||
cancel
|
cancel
|
||||||
</a>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{ this.renderHash(transaction.hash) }
|
{ this.renderHash(transaction.hash) }
|
||||||
@ -357,20 +370,24 @@ export class LocalTransaction extends BaseTransaction {
|
|||||||
</td>
|
</td>
|
||||||
<td className={ styles.edit }>
|
<td className={ styles.edit }>
|
||||||
<input
|
<input
|
||||||
type='text'
|
type='number'
|
||||||
value={ gasPrice }
|
value={ gasPrice }
|
||||||
onChange={ this.setGasPrice }
|
onChange={ this.setGasPrice }
|
||||||
/>
|
/>
|
||||||
|
<span>shannon</span>
|
||||||
|
</td>
|
||||||
|
<td className={ styles.edit }>
|
||||||
<input
|
<input
|
||||||
type='text'
|
type='number'
|
||||||
value={ gas }
|
value={ gas }
|
||||||
onChange={ this.setGas }
|
onChange={ this.setGas }
|
||||||
/>
|
/>
|
||||||
|
<span>MGas</span>
|
||||||
</td>
|
</td>
|
||||||
<td colSpan='2'>
|
<td colSpan='2'>
|
||||||
<a href='javascript:void' onClick={ this.sendTransaction }>
|
<button onClick={ this.sendTransaction }>
|
||||||
Send
|
Send
|
||||||
</a>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user