Fix "no bignumber" Error (#155)

* provide link to mailchimp based subscription

* only estimate gas when the amount value is a number
This commit is contained in:
Daniel Ternyak 2017-08-31 17:01:34 -07:00 committed by GitHub
parent f6b5e8f426
commit c2c9f39c6b

View File

@ -21,7 +21,6 @@ import BaseWallet from 'libs/wallet/base';
import customMessages from './messages'; import customMessages from './messages';
import { donationAddressMap } from 'config/data'; import { donationAddressMap } from 'config/data';
import { isValidETHAddress } from 'libs/validators'; import { isValidETHAddress } from 'libs/validators';
import { toUnit } from 'libs/units';
import { import {
getNodeLib, getNodeLib,
getNetworkConfig, getNetworkConfig,
@ -337,46 +336,47 @@ export class SendTransaction extends React.Component {
async getTransactionInfoFromState(): Promise<TransactionWithoutGas> { async getTransactionInfoFromState(): Promise<TransactionWithoutGas> {
const { wallet } = this.props; const { wallet } = this.props;
const { token } = this.state; const { token, unit, value, to, data } = this.state;
if (this.state.unit === 'ether') { if (unit === 'ether') {
return { return {
to: this.state.to, to,
from: await wallet.getAddress(), from: await wallet.getAddress(),
value: valueToHex(this.state.value), value: valueToHex(value),
data: this.state.data data
}; };
} else { } else {
if (!token) { if (!token) {
throw new Error('No matching token'); throw new Error('No matching token');
} }
const bigAmount = new Big(value);
return { return {
to: token.address, to: token.address,
from: await wallet.getAddress(), from: await wallet.getAddress(),
value: '0x0', value: '0x0',
data: ERC20.transfer( data: ERC20.transfer(to, toTokenUnit(bigAmount, token))
this.state.to,
toTokenUnit(new Big(this.state.value), token)
)
}; };
} }
} }
async estimateGas() { async estimateGas() {
try { if (!isNaN(parseInt(this.state.value))) {
const transaction = await this.getTransactionInfoFromState(); try {
// Grab a reference to state. If it has changed by the time the estimateGas const transaction = await this.getTransactionInfoFromState();
// call comes back, we don't want to replace the gasLimit in state. // Grab a reference to state. If it has changed by the time the estimateGas
const state = this.state; // call comes back, we don't want to replace the gasLimit in state.
const gasLimit = await this.props.nodeLib.estimateGas(transaction); const state = this.state;
if (this.state === state) { const gasLimit = await this.props.nodeLib.estimateGas(transaction);
this.setState({ gasLimit: formatGasLimit(gasLimit, state.unit) }); if (this.state === state) {
} else { this.setState({ gasLimit: formatGasLimit(gasLimit, state.unit) });
this.estimateGas(); } else {
this.estimateGas();
}
} catch (error) {
this.props.showNotification('danger', error.message, 5000);
} }
} catch (error) {
this.props.showNotification('danger', error.message, 5000);
} }
} }
@ -439,6 +439,7 @@ export class SendTransaction extends React.Component {
value = tokenBalance.balance.toString(); value = tokenBalance.balance.toString();
} }
} }
let token = this.props.tokens.find(x => x.symbol === unit); let token = this.props.tokens.find(x => x.symbol === unit);
this.setState({ this.setState({