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

Commit

Permalink
[beta] UI backports (#4855)
Browse files Browse the repository at this point in the history
* Added React Hot Reload to dapps + TokenDeplpoy fix (#4846)

* Fix method decoding (#4845)

* Fix contract deployment method decoding in Signer

* Linting

* 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

* Pull steps from actual available steps (#4848)

* Wait for the value to have changed in the input (#4844)

* Backport Regsirty changes from #4589

* Test fixes for #4589
  • Loading branch information
jacogr authored and arkpar committed Mar 10, 2017
1 parent 34e8110 commit ab23669
Show file tree
Hide file tree
Showing 17 changed files with 266 additions and 61 deletions.
9 changes: 8 additions & 1 deletion js/src/api/format/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,15 @@ export function inOptions (options) {
if (options) {
Object.keys(options).forEach((key) => {
switch (key) {
case 'from':
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]);
break;

Expand Down
7 changes: 7 additions & 0 deletions js/src/api/format/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
it(`formats ${input} number as hexnumber`, () => {
const block = {};
Expand Down
55 changes: 51 additions & 4 deletions js/src/contracts/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@

import * as abis from './abi';

const REGISTRY_V1_HASHES = [
'0x34f7c51bbb1b1902fbdabfdf04811100f5c9f998f26dd535d2f6f977492c748e', // ropsten
'0x64c3ee34851517a9faecd995c102b339f03e564ad6772dc43a26f993238b20ec' // homestead
];

export default class Registry {
_registryContract = null;

constructor (api) {
this._api = api;

Expand All @@ -43,11 +50,10 @@ export default class Registry {

this._fetching = true;

return this._api.parity
.registryAddress()
.then((address) => {
return this.fetchContract()
.then((contract) => {
this._fetching = false;
this._instance = this._api.newContract(abis.registry, address).instance;
this._instance = contract.instance;

this._queue.forEach((queued) => {
queued.resolve(this._instance);
Expand Down Expand Up @@ -89,6 +95,47 @@ export default class Registry {
.then((contract) => contract.instance);
}

fetchContract () {
if (this._registryContract) {
return Promise.resolve(this._registryContract);
}

return this._api.parity
.registryAddress()
.then((address) => Promise.all([ address, this._api.eth.getCode(address) ]))
.then(([ address, code ]) => {
const codeHash = this._api.util.sha3(code);
const version = REGISTRY_V1_HASHES.includes(codeHash)
? 1
: 2;
const abi = version === 1
? abis.registry
: abis.registry2;
const contract = this._api.newContract(abi, address);

// Add support for previous `set` and `get` methods
if (!contract.instance.get && contract.instance.getData) {
contract.instance.get = contract.instance.getData;
}

if (contract.instance.get && !contract.instance.getData) {
contract.instance.getData = contract.instance.get;
}

if (!contract.instance.set && contract.instance.setData) {
contract.instance.set = contract.instance.setData;
}

if (contract.instance.set && !contract.instance.setData) {
contract.instance.setData = contract.instance.set;
}

console.log(`registry at ${address}, code ${codeHash}, version ${version}`);
this._registryContract = contract;
return this._registryContract;
});
}

_createGetParams (_name, key) {
const name = _name.toLowerCase();
const sha3 = this._api.util.sha3.text(name);
Expand Down
3 changes: 3 additions & 0 deletions js/src/contracts/registry.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ function create () {
}
};
api = {
eth: {
getCode: sinon.stub().resolves(0)
},
parity: {
registryAddress: sinon.stub().resolves('testRegistryAddress')
},
Expand Down
18 changes: 17 additions & 1 deletion js/src/dapps/githubhint.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import ReactDOM from 'react-dom';
import React from 'react';
import { AppContainer } from 'react-hot-loader';

import injectTapEventPlugin from 'react-tap-event-plugin';
injectTapEventPlugin();
Expand All @@ -27,6 +28,21 @@ import '../../assets/fonts/RobotoMono/font.css';
import './style.css';

ReactDOM.render(
<Application />,
<AppContainer>
<Application />
</AppContainer>,
document.querySelector('#container')
);

if (module.hot) {
module.hot.accept('./githubhint/Application/index.js', () => {
require('./githubhint/Application/index.js');

ReactDOM.render(
<AppContainer>
<Application />
</AppContainer>,
document.querySelector('#container')
);
});
}
18 changes: 17 additions & 1 deletion js/src/dapps/localtx.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import ReactDOM from 'react-dom';
import React from 'react';
import { AppContainer } from 'react-hot-loader';

import injectTapEventPlugin from 'react-tap-event-plugin';
injectTapEventPlugin();
Expand All @@ -27,6 +28,21 @@ import '../../assets/fonts/RobotoMono/font.css';
import './style.css';

ReactDOM.render(
<Application />,
<AppContainer>
<Application />
</AppContainer>,
document.querySelector('#container')
);

if (module.hot) {
module.hot.accept('./localtx/Application/index.js', () => {
require('./localtx/Application/index.js');

ReactDOM.render(
<AppContainer>
<Application />
</AppContainer>,
document.querySelector('#container')
);
});
}
24 changes: 24 additions & 0 deletions js/src/dapps/localtx/Application/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,29 @@
th {
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;
}
}
1 change: 0 additions & 1 deletion js/src/dapps/localtx/Application/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export default class Application extends Component {
local[tx.hash].transaction = tx;
local[tx.hash].stats = data.stats;
});

// Convert local transactions to array
const localTransactions = Object.keys(local).map(hash => {
const data = local[hash];
Expand Down
8 changes: 8 additions & 0 deletions js/src/dapps/localtx/Transaction/transaction.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
}
}

.txhash {
display: inline-block;
overflow: hidden;
padding-right: 3ch;
text-overflow: ellipsis;
width: 10ch;
}

.transaction {
td {
padding: 7px 15px;
Expand Down
75 changes: 46 additions & 29 deletions js/src/dapps/localtx/Transaction/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class BaseTransaction extends Component {

renderHash (hash) {
return (
<code title={ hash }>
{ this.shortHash(hash) }
<code title={ hash } className={ styles.txhash }>
{ hash }
</code>
);
}
Expand Down Expand Up @@ -206,7 +206,10 @@ export class LocalTransaction extends BaseTransaction {
From
</th>
<th>
Gas Price / Gas
Gas Price
</th>
<th>
Gas
</th>
<th>
Status
Expand All @@ -224,18 +227,18 @@ export class LocalTransaction extends BaseTransaction {

toggleResubmit = () => {
const { transaction } = this.props;
const { isResubmitting, gasPrice } = this.state;
const { isResubmitting } = this.state;

this.setState({
const nextState = {
isResubmitting: !isResubmitting
});
};

if (gasPrice === null) {
this.setState({
gasPrice: `0x${transaction.gasPrice.toString(16)}`,
gas: `0x${transaction.gas.toString(16)}`
});
if (!isResubmitting) {
nextState.gasPrice = api.util.fromWei(transaction.gasPrice, 'shannon').toNumber();
nextState.gas = transaction.gas.div(1000000).toNumber();
}

this.setState(nextState);
};

setGasPrice = el => {
Expand All @@ -251,28 +254,37 @@ export class LocalTransaction extends BaseTransaction {
};

sendTransaction = () => {
const { transaction } = this.props;
const { transaction, status } = this.props;
const { gasPrice, gas } = this.state;

const newTransaction = {
from: transaction.from,
to: transaction.to,
nonce: transaction.nonce,
value: transaction.value,
data: transaction.input,
gasPrice, gas
gasPrice: api.util.toWei(gasPrice, 'shannon'),
gas: new BigNumber(gas).mul(1000000)
};

this.setState({
isResubmitting: false,
isSending: true
});

const closeSending = () => this.setState({
isSending: false,
gasPrice: null,
gas: null
});
const closeSending = () => {
this.setState({
isSending: false,
gasPrice: null,
gas: null
});
};

if (transaction.to) {
newTransaction.to = transaction.to;
}

if (!['mined', 'replaced'].includes(status)) {
newTransaction.nonce = transaction.nonce;
}

api.eth.sendTransaction(newTransaction)
.then(closeSending)
Expand All @@ -290,9 +302,9 @@ export class LocalTransaction extends BaseTransaction {
const resubmit = isSending ? (
'sending...'
) : (
<a href='javascript:void' onClick={ this.toggleResubmit }>
<button onClick={ this.toggleResubmit }>
resubmit
</a>
</button>
);

return (
Expand All @@ -308,7 +320,8 @@ export class LocalTransaction extends BaseTransaction {
</td>
<td>
{ this.renderGasPrice(transaction) }
<br />
</td>
<td>
{ this.renderGas(transaction) }
</td>
<td>
Expand Down Expand Up @@ -345,9 +358,9 @@ export class LocalTransaction extends BaseTransaction {
return (
<tr className={ styles.transaction }>
<td>
<a href='javascript:void' onClick={ this.toggleResubmit }>
<button onClick={ this.toggleResubmit }>
cancel
</a>
</button>
</td>
<td>
{ this.renderHash(transaction.hash) }
Expand All @@ -357,20 +370,24 @@ export class LocalTransaction extends BaseTransaction {
</td>
<td className={ styles.edit }>
<input
type='text'
type='number'
value={ gasPrice }
onChange={ this.setGasPrice }
/>
<span>shannon</span>
</td>
<td className={ styles.edit }>
<input
type='text'
type='number'
value={ gas }
onChange={ this.setGas }
/>
<span>MGas</span>
</td>
<td colSpan='2'>
<a href='javascript:void' onClick={ this.sendTransaction }>
<button onClick={ this.sendTransaction }>
Send
</a>
</button>
</td>
</tr>
);
Expand Down
Loading

0 comments on commit ab23669

Please sign in to comment.