Newer
Older
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: BSD-3-Clause
import React, { Component } from 'react';
import BigNumber from 'bignumber.js';
import { fromWei, toWei } from '@parity/api/lib/util/wei';
class TxDetails extends Component {
state = {
showDetails: false
};
Luke Schoen
committed
renderCalculation = () => {
const { estimatedTxFee, values } = this.props;
const gasPriceBn = new BigNumber(values.gasPrice.toString());
Luke Schoen
committed
const gasLimitBn = estimatedTxFee
.div(gasPriceBn)
.div(10 ** 9)
.toFixed(0)
.toString();
return `Estimate amount of gas: ${gasLimitBn}`;
};
Luke Schoen
committed
renderDetails = () => {
return `${this.renderCalculation()}
${this.renderFee()}
${this.renderTotalAmount()}`;
};
Luke Schoen
committed
renderFee = () => {
const { estimatedTxFee } = this.props;
Luke Schoen
committed
return `Fee: ${fromWei(estimatedTxFee, 'ether')
.toFixed(9)
.toString()} ETH (estimate * gas price)`;
};
Luke Schoen
committed
renderTotalAmount = () => {
const { estimatedTxFee, token, values } = this.props;
return `Total Amount: ${fromWei(
estimatedTxFee.plus(
token.address === 'ETH' ? toWei(values.amount.toString()) : 0
),
'ether'
).toString()} ETH`;
};
showDetailsAnchor = () => {
return (
Luke Schoen
committed
<span className='toggle-details'>
<a onClick={this.toggleDetails}>↑ Details</a>
</span>
);
};
showHideAnchor = () => {
return (
Luke Schoen
committed
<span className='toggle-details'>
<a onClick={this.toggleDetails}>↓ Hide</a>
</span>
);
};
toggleDetails = () => {
const { showDetails } = this.state;
this.setState({ showDetails: !showDetails });
};
render () {
const { showDetails } = this.state;
return (
Luke Schoen
committed
<div className='form-details-wrapper'>
<div className='form-details-buttons'>
{showDetails ? this.showHideAnchor() : this.showDetailsAnchor()}
</div>
Luke Schoen
committed
<div className='form_field -details-value'>
<div hidden={!showDetails}>
<label htmlFor='txDetails'>Transaction Details (Estimate):</label>
<textarea
className='-sm-details'
id='txDetails'
readOnly
Luke Schoen
committed
value={this.renderDetails()}