2016-12-09 13:44:35 +01:00
|
|
|
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import BigNumber from 'bignumber.js';
|
|
|
|
import { observer } from 'mobx-react';
|
2016-12-11 17:43:51 +01:00
|
|
|
import React, { Component, PropTypes } from 'react';
|
2016-12-09 13:44:35 +01:00
|
|
|
|
|
|
|
import Input from '../Form/Input';
|
2016-12-11 17:43:51 +01:00
|
|
|
import GasPriceSelector from '../GasPriceSelector';
|
2016-12-09 13:44:35 +01:00
|
|
|
import Store from './store';
|
|
|
|
|
|
|
|
import styles from './gasPriceEditor.css';
|
|
|
|
|
|
|
|
@observer
|
|
|
|
export default class GasPriceEditor extends Component {
|
2016-12-09 15:43:24 +01:00
|
|
|
static contextTypes = {
|
|
|
|
api: PropTypes.object.isRequired
|
|
|
|
};
|
|
|
|
|
2016-12-09 13:44:35 +01:00
|
|
|
static propTypes = {
|
2016-12-11 17:43:51 +01:00
|
|
|
children: PropTypes.node,
|
|
|
|
onChange: PropTypes.func,
|
|
|
|
store: PropTypes.object.isRequired
|
2016-12-09 13:44:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Store = Store;
|
|
|
|
|
|
|
|
render () {
|
2016-12-09 15:43:24 +01:00
|
|
|
const { api } = this.context;
|
2016-12-11 17:43:51 +01:00
|
|
|
const { children, store } = this.props;
|
|
|
|
const { errorGas, errorPrice, errorTotal, estimated, gas, histogram, price, priceDefault, totalValue } = store;
|
2016-12-09 13:44:35 +01:00
|
|
|
|
2016-12-09 15:43:24 +01:00
|
|
|
const eth = api.util.fromWei(totalValue).toFormat();
|
2016-12-09 13:44:35 +01:00
|
|
|
const gasLabel = `gas (estimated: ${new BigNumber(estimated).toFormat()})`;
|
|
|
|
const priceLabel = `price (current: ${new BigNumber(priceDefault).toFormat()})`;
|
|
|
|
|
|
|
|
return (
|
2016-12-11 17:43:51 +01:00
|
|
|
<div className={ styles.container }>
|
2016-12-09 13:44:35 +01:00
|
|
|
<div className={ styles.graphColumn }>
|
|
|
|
<GasPriceSelector
|
2016-12-11 17:43:51 +01:00
|
|
|
histogram={ histogram }
|
|
|
|
onChange={ this.onEditGasPrice }
|
|
|
|
price={ price } />
|
2016-12-09 13:44:35 +01:00
|
|
|
<div className={ styles.gasPriceDesc }>
|
2016-12-11 17:43:51 +01:00
|
|
|
You can choose the gas price based on the distribution of recent included transaction gas prices. The lower the gas price is, the cheaper the transaction will be. The higher the gas price is, the faster it should get mined by the network.
|
2016-12-09 13:44:35 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className={ styles.editColumn }>
|
|
|
|
<div className={ styles.row }>
|
|
|
|
<Input
|
|
|
|
error={ errorGas }
|
2016-12-11 17:43:51 +01:00
|
|
|
hint='the amount of gas to use for the transaction'
|
|
|
|
label={ gasLabel }
|
|
|
|
onChange={ this.onEditGas }
|
|
|
|
value={ gas } />
|
2016-12-09 13:44:35 +01:00
|
|
|
<Input
|
|
|
|
error={ errorPrice }
|
2016-12-11 17:43:51 +01:00
|
|
|
hint='the price of gas to use for the transaction'
|
|
|
|
label={ priceLabel }
|
|
|
|
onChange={ this.onEditGasPrice }
|
|
|
|
value={ price } />
|
2016-12-09 13:44:35 +01:00
|
|
|
</div>
|
|
|
|
<div className={ styles.row }>
|
2016-12-09 15:43:24 +01:00
|
|
|
<Input
|
|
|
|
disabled
|
|
|
|
error={ errorTotal }
|
2016-12-11 17:43:51 +01:00
|
|
|
hint='the total amount of the transaction'
|
|
|
|
label='total transaction amount'
|
2016-12-09 15:43:24 +01:00
|
|
|
value={ `${eth} ETH` } />
|
2016-12-09 13:44:35 +01:00
|
|
|
</div>
|
2016-12-11 17:43:51 +01:00
|
|
|
<div className={ styles.row }>
|
|
|
|
{ children }
|
|
|
|
</div>
|
2016-12-09 13:44:35 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
onEditGas = (event, gas) => {
|
|
|
|
const { store, onChange } = this.props;
|
|
|
|
|
|
|
|
store.setGas(gas);
|
|
|
|
onChange && onChange('gas', gas);
|
|
|
|
}
|
|
|
|
|
|
|
|
onEditGasPrice = (event, price) => {
|
|
|
|
const { store, onChange } = this.props;
|
|
|
|
|
|
|
|
store.setPrice(price);
|
|
|
|
onChange && onChange('gasPrice', price);
|
|
|
|
}
|
|
|
|
}
|