From c3ec1ad361be711fa0e9f597fca72aa20b8b1e43 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 15 Jun 2018 17:56:05 +0200 Subject: [PATCH 1/3] Use toString because BigNumber needs it (fix #53) --- packages/light-react/src/stores/sendStore.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/light-react/src/stores/sendStore.js b/packages/light-react/src/stores/sendStore.js index 136c166c..7dac7e0d 100644 --- a/packages/light-react/src/stores/sendStore.js +++ b/packages/light-react/src/stores/sendStore.js @@ -149,7 +149,7 @@ class SendStore { return { gasPrice: toWei(this.tx.gasPrice, 'shannon'), // shannon == gwei to: this.tx.to, - value: toWei(this.tx.amount) + value: toWei(this.tx.amount.toString()) }; } @@ -160,7 +160,10 @@ class SendStore { @computed get txForErc20 () { return { - args: [this.tx.to, this.tx.amount * 10 ** this.token.decimals], + args: [ + this.tx.to, + (this.tx.amount * 10 ** this.token.decimals).toString() + ], options: { gasPrice: toWei(this.tx.gasPrice, 'shannon') // shannon == gwei } -- GitLab From d602e1f716e062f878cd8b98b223e6bad27693b7 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 15 Jun 2018 18:10:02 +0200 Subject: [PATCH 2/3] Verify transaction before estimateGas and send --- packages/light-react/src/stores/sendStore.js | 34 ++++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/packages/light-react/src/stores/sendStore.js b/packages/light-react/src/stores/sendStore.js index 7dac7e0d..2f119fbd 100644 --- a/packages/light-react/src/stores/sendStore.js +++ b/packages/light-react/src/stores/sendStore.js @@ -83,11 +83,11 @@ class SendStore { * Estimate the amount of gas for our transaction. */ estimateGas = () => { + if (!this.isTxValid) { + return Promise.resolve(DEFAULT_GAS); + } + if (this.tokenAddress === 'ETH') { - // We only estimate txs to a correct address - if (!this.tx || !isAddress(this.tx.to)) { - return Promise.resolve(DEFAULT_GAS); - } return this.api.eth .estimateGas(this.txForEth) .then(this.setEstimated) @@ -100,12 +100,34 @@ class SendStore { } }; + @computed + get isTxValid () { + // The address should be okay + if (!this.tx || !isAddress(this.tx.to)) { + return false; + } + + // The amount should be a number + if (!Number.isFinite(this.tx.amount)) { + return false; + } + + // The amount should be a number + if (!Number.isFinite(this.tx.gasPrice)) { + return false; + } + + console.log(true); + + return true; + } + /** * Create a transaction. */ send = () => { - if (!this.tx) { - console.error('Cannot send empty transaction.'); + if (!this.isTxValid) { + console.error('Transaction is invalid.'); return; } -- GitLab From b78be5bda8e6e65bd074b1b06592ff4f4fd89514 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 15 Jun 2018 18:11:52 +0200 Subject: [PATCH 3/3] Fix small bugs --- packages/light-react/src/stores/sendStore.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/light-react/src/stores/sendStore.js b/packages/light-react/src/stores/sendStore.js index 2f119fbd..72f66fc3 100644 --- a/packages/light-react/src/stores/sendStore.js +++ b/packages/light-react/src/stores/sendStore.js @@ -112,13 +112,11 @@ class SendStore { return false; } - // The amount should be a number + // The gasPrice should be a number if (!Number.isFinite(this.tx.gasPrice)) { return false; } - console.log(true); - return true; } -- GitLab