From 804f986cb5c718b9938da8abe68a1ee003e55b28 Mon Sep 17 00:00:00 2001 From: James Prado Date: Wed, 18 Oct 2017 19:49:10 -0400 Subject: [PATCH] Fix errors thrown on /send-transaction by adding a query string to the url (#291) Fix errors thrown on /send-transaction by adding a query string to the url --- .../containers/Tabs/SendTransaction/index.tsx | 40 ++++++++++--------- package-lock.json | 9 +++++ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/common/containers/Tabs/SendTransaction/index.tsx b/common/containers/Tabs/SendTransaction/index.tsx index 1fbce96f..35dc1426 100644 --- a/common/containers/Tabs/SendTransaction/index.tsx +++ b/common/containers/Tabs/SendTransaction/index.tsx @@ -155,8 +155,8 @@ export class SendTransaction extends React.Component { // TODO listen to gas price changes here // TODO debounce the call // handle gas estimation - // if any relevant fields changed return ( + // if any relevant fields changed this.haveFieldsChanged(prevState) && // if gas has not changed !this.state.gasChanged && @@ -215,7 +215,7 @@ export class SendTransaction extends React.Component { } public handleWalletStateOnUpdate(prevProps) { - if (this.props.wallet !== prevProps.wallet) { + if (this.props.wallet !== prevProps.wallet && !!prevProps.wallet) { this.setState(initialState); } } @@ -415,15 +415,15 @@ export class SendTransaction extends React.Component { const query = queryString.parse(searchStr); const to = getParam(query, 'to'); const data = getParam(query, 'data'); - // FIXME validate token against presets const unit = getParam(query, 'tokenSymbol'); + const token = this.props.tokens.find(x => x.symbol === unit); const value = getParam(query, 'value'); - let gasLimit = getParam(query, 'gas'); + let gasLimit = getParam(query, 'gaslimit'); if (gasLimit === null) { gasLimit = getParam(query, 'limit'); } const readOnly = getParam(query, 'readOnly') != null; - return { to, data, value, unit, gasLimit, readOnly }; + return { to, token, data, value, unit, gasLimit, readOnly }; } public isValidNonce() { @@ -488,21 +488,23 @@ export class SendTransaction extends React.Component { return; } - try { - const cachedFormattedTx = await this.getFormattedTxFromState(); - // Grab a reference to state. If it has changed by the time the estimateGas - // call comes back, we don't want to replace the gasLimit in state. - const state = this.state; - gasLimit = await nodeLib.estimateGas(cachedFormattedTx); - if (this.state === state) { - this.setState({ gasLimit: formatGasLimit(gasLimit, state.unit) }); - } else { - // state has changed, so try again from the start (with the hope that state won't change by the next time) - this.estimateGas(); + if (this.props.wallet) { + try { + const cachedFormattedTx = await this.getFormattedTxFromState(); + // Grab a reference to state. If it has changed by the time the estimateGas + // call comes back, we don't want to replace the gasLimit in state. + const state = this.state; + gasLimit = await nodeLib.estimateGas(cachedFormattedTx); + if (this.state === state) { + this.setState({ gasLimit: formatGasLimit(gasLimit, state.unit) }); + } else { + // state has changed, so try again from the start (with the hope that state won't change by the next time) + this.estimateGas(); + } + } catch (error) { + this.setState({ generateDisabled: true }); + this.props.showNotification('danger', error.message, 5000); } - } catch (error) { - this.setState({ generateDisabled: true }); - this.props.showNotification('danger', error.message, 5000); } } diff --git a/package-lock.json b/package-lock.json index d1200475..453382a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13437,6 +13437,15 @@ } } }, + "types-rlp": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/types-rlp/-/types-rlp-0.0.1.tgz", + "integrity": "sha512-UUn2x3z9aTItExmCg0fqPuaKBzLCt+pbNfxY2kQ4TRB/06QxrVShILANfBEvrVemg7GZqn9qCIMJK6WkWI+izA==", + "dev": true, + "requires": { + "rlp": "2.0.0" + } + }, "typescript": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.5.2.tgz",