From 8ab8c279989114662d6dce4b5b998ad8fd88fc1a Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 29 Oct 2018 15:19:48 -0700 Subject: gas price estimator --- packages/instant/src/components/buy_button.tsx | 5 +++-- packages/instant/src/components/zero_ex_instant.tsx | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'packages/instant/src/components') diff --git a/packages/instant/src/components/buy_button.tsx b/packages/instant/src/components/buy_button.tsx index e65e62e47..58575b1b3 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -7,6 +7,7 @@ import { ColorOption } from '../style/theme'; import { ZeroExInstantError } from '../types'; import { getBestAddress } from '../util/address'; import { balanceUtil } from '../util/balance'; +import { gasPriceEstimator } from '../util/gas_price_estimator'; import { util } from '../util/util'; import { web3Wrapper } from '../util/web3_wrapper'; @@ -56,9 +57,9 @@ export class BuyButton extends React.Component { } let txHash: string | undefined; + const gasPrice = await gasPriceEstimator.getFastAmountInWeiAsync(); try { - const gasPrice = DEFAULT_GAS_PRICE; - txHash = await assetBuyer.executeBuyQuoteAsync(buyQuote, { gasPrice, takerAddress }); + txHash = await assetBuyer.executeBuyQuoteAsync(buyQuote, { takerAddress, gasPrice }); } catch (e) { if (e instanceof Error) { if (e.message === AssetBuyerError.SignatureRequestDenied) { diff --git a/packages/instant/src/components/zero_ex_instant.tsx b/packages/instant/src/components/zero_ex_instant.tsx index 19a2d6b9b..6a5846963 100644 --- a/packages/instant/src/components/zero_ex_instant.tsx +++ b/packages/instant/src/components/zero_ex_instant.tsx @@ -13,6 +13,7 @@ import { AssetMetaData, Network } from '../types'; import { assetUtils } from '../util/asset'; import { BigNumberInput } from '../util/big_number_input'; import { errorFlasher } from '../util/error_flasher'; +import { gasPriceEstimator } from '../util/gas_price_estimator'; import { getProvider } from '../util/provider'; import { web3Wrapper } from '../util/web3_wrapper'; @@ -78,6 +79,7 @@ export class ZeroExInstant extends React.Component { public componentDidMount(): void { // tslint:disable-next-line:no-floating-promises asyncData.fetchAndDispatchToStore(this._store); + gasPriceEstimator.getFastAmountInWeiAsync(); // tslint:disable-next-line:no-floating-promises this._flashErrorIfWrongNetwork(); } -- cgit From cd419edf69ae13c6eb7eb1daadcfa73bd731e6f4 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 29 Oct 2018 15:37:30 -0700 Subject: linting --- packages/instant/src/components/buy_button.tsx | 2 +- packages/instant/src/components/zero_ex_instant.tsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'packages/instant/src/components') diff --git a/packages/instant/src/components/buy_button.tsx b/packages/instant/src/components/buy_button.tsx index 58575b1b3..93bd8e635 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -2,7 +2,7 @@ import { AssetBuyer, AssetBuyerError, BuyQuote } from '@0x/asset-buyer'; import * as _ from 'lodash'; import * as React from 'react'; -import { DEFAULT_GAS_PRICE, WEB_3_WRAPPER_TRANSACTION_FAILED_ERROR_MSG_PREFIX } from '../constants'; +import { WEB_3_WRAPPER_TRANSACTION_FAILED_ERROR_MSG_PREFIX } from '../constants'; import { ColorOption } from '../style/theme'; import { ZeroExInstantError } from '../types'; import { getBestAddress } from '../util/address'; diff --git a/packages/instant/src/components/zero_ex_instant.tsx b/packages/instant/src/components/zero_ex_instant.tsx index 6a5846963..87069bb6f 100644 --- a/packages/instant/src/components/zero_ex_instant.tsx +++ b/packages/instant/src/components/zero_ex_instant.tsx @@ -79,6 +79,7 @@ export class ZeroExInstant extends React.Component { public componentDidMount(): void { // tslint:disable-next-line:no-floating-promises asyncData.fetchAndDispatchToStore(this._store); + // tslint:disable-next-line:no-floating-promises gasPriceEstimator.getFastAmountInWeiAsync(); // tslint:disable-next-line:no-floating-promises this._flashErrorIfWrongNetwork(); -- cgit From a49fc27042f9797f7a035e5471e572b148679456 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 29 Oct 2018 16:49:13 -0700 Subject: Comment for warming up cache --- packages/instant/src/components/zero_ex_instant.tsx | 2 ++ 1 file changed, 2 insertions(+) (limited to 'packages/instant/src/components') diff --git a/packages/instant/src/components/zero_ex_instant.tsx b/packages/instant/src/components/zero_ex_instant.tsx index 87069bb6f..63c2c9072 100644 --- a/packages/instant/src/components/zero_ex_instant.tsx +++ b/packages/instant/src/components/zero_ex_instant.tsx @@ -80,6 +80,8 @@ export class ZeroExInstant extends React.Component { // tslint:disable-next-line:no-floating-promises asyncData.fetchAndDispatchToStore(this._store); // tslint:disable-next-line:no-floating-promises + // warm up the gas price estimator cache just in case we can't + // grab the gas price estimate when submitting the transaction gasPriceEstimator.getFastAmountInWeiAsync(); // tslint:disable-next-line:no-floating-promises this._flashErrorIfWrongNetwork(); -- cgit From 5901ee7e963a4413f49fffdd9477085229e7623f Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 29 Oct 2018 17:18:56 -0700 Subject: Move tslint disable line --- packages/instant/src/components/zero_ex_instant.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'packages/instant/src/components') diff --git a/packages/instant/src/components/zero_ex_instant.tsx b/packages/instant/src/components/zero_ex_instant.tsx index 63c2c9072..d54dfc153 100644 --- a/packages/instant/src/components/zero_ex_instant.tsx +++ b/packages/instant/src/components/zero_ex_instant.tsx @@ -79,10 +79,12 @@ export class ZeroExInstant extends React.Component { public componentDidMount(): void { // tslint:disable-next-line:no-floating-promises asyncData.fetchAndDispatchToStore(this._store); - // tslint:disable-next-line:no-floating-promises + // warm up the gas price estimator cache just in case we can't // grab the gas price estimate when submitting the transaction + // tslint:disable-next-line:no-floating-promises gasPriceEstimator.getFastAmountInWeiAsync(); + // tslint:disable-next-line:no-floating-promises this._flashErrorIfWrongNetwork(); } -- cgit