Newer
Older
// Copyright 2015-2019 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';
import i18n, { packageNS } from '../../../i18n';
class TxDetails extends Component {
const { estimatedTxFee, token, values } = this.props;
if (
!estimatedTxFee ||
!values.gasPrice ||
!values.amount ||
!values.chainId ||
!values.ethBalance ||
!values.gas ||
!values.gasPrice ||
!values.transactionCount ||
!token.address
) {
// Keep line break so message is centered
return `
${i18n.t(`${packageNS}:tx.form.details.missing_fields`)}`;
}
return `${this.renderCalculation()}
${this.renderTotalAmount()}`;
Luke Schoen
committed
renderCalculation = () => {
const { estimatedTxFee, values } = this.props;
if (!estimatedTxFee || !values.gasPrice) {
return;
}
const gasPriceBn = new BigNumber(values.gasPrice.toString());
Luke Schoen
committed
const gasLimitBn = estimatedTxFee
.div(gasPriceBn)
.div(10 ** 9)
.toFixed(0)
.toString();
return i18n.t(`${packageNS}:tx.form.details.gas_limit`, {
gas_limit: gasLimitBn
});
};
Luke Schoen
committed
renderFee = () => {
const { estimatedTxFee } = this.props;
if (!estimatedTxFee) {
return;
}
const fee = `${fromWei(estimatedTxFee, 'ether')
.toFixed(9)
.toString()}`;
return i18n.t(`${packageNS}:tx.form.details.fee`, { fee });
};
Luke Schoen
committed
renderTotalAmount = () => {
const { estimatedTxFee, token, values } = this.props;
if (!estimatedTxFee || !values.amount || !token.address) {
return;
}
const totalAmount = `${fromWei(
estimatedTxFee.plus(
token.address === 'ETH' ? toWei(values.amount.toString()) : 0
),
'ether'
).toString()}`;
return i18n.t(`${packageNS}:tx.form.details.total_amount`, {
total_amount: totalAmount
});
};
render () {
Luke Schoen
committed
const { showDetails } = this.props;
return (
Luke Schoen
committed
<div>
<div className='form_field'>
<div hidden={!showDetails}>
<label htmlFor='txDetails'>
{i18n.t(`${packageNS}:tx.form.details.title`)}
</label>
<textarea
className='-sm-details'
id='txDetails'
readOnly
Luke Schoen
committed
value={this.renderDetails()}