2018-01-07 16:43:06 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { translateRaw } from 'translations';
|
|
|
|
import { connect } from 'react-redux';
|
2018-01-15 09:59:59 +00:00
|
|
|
import { inputGasPrice, TInputGasPrice } from 'actions/transaction';
|
2018-01-07 16:43:06 +00:00
|
|
|
import { fetchCCRates, TFetchCCRates } from 'actions/rates';
|
2018-01-15 09:59:59 +00:00
|
|
|
import { getNetworkConfig, getOffline } from 'selectors/config';
|
2018-01-07 16:43:06 +00:00
|
|
|
import { AppState } from 'reducers';
|
|
|
|
import SimpleGas from './components/SimpleGas';
|
|
|
|
import AdvancedGas from './components/AdvancedGas';
|
|
|
|
import './GasSlider.scss';
|
2018-01-15 09:59:59 +00:00
|
|
|
import { getGasPrice } from 'selectors/transaction';
|
2018-01-07 16:43:06 +00:00
|
|
|
|
2018-01-15 09:59:59 +00:00
|
|
|
interface StateProps {
|
2018-01-07 16:43:06 +00:00
|
|
|
gasPrice: AppState['transaction']['fields']['gasPrice'];
|
|
|
|
offline: AppState['config']['offline'];
|
|
|
|
network: AppState['config']['network'];
|
2018-01-15 09:59:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface DispatchProps {
|
2018-01-07 16:43:06 +00:00
|
|
|
inputGasPrice: TInputGasPrice;
|
|
|
|
fetchCCRates: TFetchCCRates;
|
|
|
|
}
|
|
|
|
|
2018-01-15 09:59:59 +00:00
|
|
|
interface OwnProps {
|
|
|
|
disableAdvanced?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
type Props = DispatchProps & OwnProps & StateProps;
|
|
|
|
|
2018-01-07 16:43:06 +00:00
|
|
|
interface State {
|
|
|
|
showAdvanced: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
class GasSlider extends React.Component<Props, State> {
|
|
|
|
public state: State = {
|
|
|
|
showAdvanced: false
|
|
|
|
};
|
|
|
|
|
|
|
|
public componentDidMount() {
|
2018-01-11 18:04:11 +00:00
|
|
|
if (!this.props.offline) {
|
|
|
|
this.props.fetchCCRates([this.props.network.unit]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public componentWillReceiveProps(nextProps: Props) {
|
|
|
|
if (this.props.offline && !nextProps.offline) {
|
|
|
|
this.props.fetchCCRates([this.props.network.unit]);
|
|
|
|
}
|
2018-01-07 16:43:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
2018-01-15 09:59:59 +00:00
|
|
|
const { offline, disableAdvanced, gasPrice } = this.props;
|
2018-01-07 16:43:06 +00:00
|
|
|
const showAdvanced = (this.state.showAdvanced || offline) && !disableAdvanced;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="GasSlider">
|
|
|
|
{showAdvanced ? (
|
2018-01-15 09:59:59 +00:00
|
|
|
<AdvancedGas gasPrice={gasPrice} inputGasPrice={this.props.inputGasPrice} />
|
2018-01-07 16:43:06 +00:00
|
|
|
) : (
|
2018-01-15 09:59:59 +00:00
|
|
|
<SimpleGas gasPrice={gasPrice} inputGasPrice={this.props.inputGasPrice} />
|
2018-01-07 16:43:06 +00:00
|
|
|
)}
|
|
|
|
|
|
|
|
{!offline &&
|
|
|
|
!disableAdvanced && (
|
|
|
|
<div className="help-block">
|
|
|
|
<a className="GasSlider-toggle" onClick={this.toggleAdvanced}>
|
|
|
|
<strong>
|
|
|
|
{showAdvanced
|
|
|
|
? `- ${translateRaw('Back to simple')}`
|
2018-01-15 09:59:59 +00:00
|
|
|
: `+ ${translateRaw('Advanced Settings')}`}
|
2018-01-07 16:43:06 +00:00
|
|
|
</strong>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private toggleAdvanced = () => {
|
|
|
|
this.setState({ showAdvanced: !this.state.showAdvanced });
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-01-15 09:59:59 +00:00
|
|
|
function mapStateToProps(state: AppState): StateProps {
|
2018-01-07 16:43:06 +00:00
|
|
|
return {
|
2018-01-15 09:59:59 +00:00
|
|
|
gasPrice: getGasPrice(state),
|
|
|
|
offline: getOffline(state),
|
2018-01-07 16:43:06 +00:00
|
|
|
network: getNetworkConfig(state)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, {
|
|
|
|
inputGasPrice,
|
|
|
|
fetchCCRates
|
|
|
|
})(GasSlider);
|