diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/instant/src/components/buy_button.tsx | 4 | ||||
-rw-r--r-- | packages/instant/src/components/zero_ex_instant.tsx | 2 | ||||
-rw-r--r-- | packages/instant/src/types.ts | 1 | ||||
-rw-r--r-- | packages/instant/src/util/gas_price_estimator.ts | 19 |
4 files changed, 17 insertions, 9 deletions
diff --git a/packages/instant/src/components/buy_button.tsx b/packages/instant/src/components/buy_button.tsx index 93bd8e635..36cc32dbc 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -57,9 +57,9 @@ export class BuyButton extends React.Component<BuyButtonProps> { } let txHash: string | undefined; - const gasPrice = await gasPriceEstimator.getFastAmountInWeiAsync(); + const gasInfo = await gasPriceEstimator.getGasInfoAsync(); try { - txHash = await assetBuyer.executeBuyQuoteAsync(buyQuote, { takerAddress, gasPrice }); + txHash = await assetBuyer.executeBuyQuoteAsync(buyQuote, { takerAddress, gasPrice: gasInfo.gasPriceInWei }); } 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 d54dfc153..365c1610f 100644 --- a/packages/instant/src/components/zero_ex_instant.tsx +++ b/packages/instant/src/components/zero_ex_instant.tsx @@ -83,7 +83,7 @@ export class ZeroExInstant extends React.Component<ZeroExInstantProps> { // 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(); + gasPriceEstimator.getGasInfoAsync(); // tslint:disable-next-line:no-floating-promises this._flashErrorIfWrongNetwork(); diff --git a/packages/instant/src/types.ts b/packages/instant/src/types.ts index 336465e43..4631c9cae 100644 --- a/packages/instant/src/types.ts +++ b/packages/instant/src/types.ts @@ -22,6 +22,7 @@ interface OrderStatePreTx { interface OrderStatePostTx { processState: OrderProcessState.PROCESSING | OrderProcessState.SUCCESS | OrderProcessState.FAILURE; txHash: string; + estimatedTimeMs?: number; } export type OrderState = OrderStatePreTx | OrderStatePostTx; diff --git a/packages/instant/src/util/gas_price_estimator.ts b/packages/instant/src/util/gas_price_estimator.ts index 336c4a3fa..0552ccde1 100644 --- a/packages/instant/src/util/gas_price_estimator.ts +++ b/packages/instant/src/util/gas_price_estimator.ts @@ -16,18 +16,25 @@ interface EthGasStationResult { safeLow: number; } -const fetchFastAmountInWeiAsync = async () => { +interface GasInfo { + gasPriceInWei: BigNumber; + estimatedTimeMs?: number; +} + +const fetchFastAmountInWeiAsync = async (): Promise<GasInfo> => { const res = await fetchAsync(`${ETH_GAS_STATION_API_BASE_URL}/json/ethgasAPI.json`); const gasInfo = (await res.json()) as EthGasStationResult; // Eth Gas Station result is gwei * 10 const gasPriceInGwei = new BigNumber(gasInfo.fast / 10); - return gasPriceInGwei.mul(GWEI_IN_WEI); + // Time is in minutes + const estimatedTimeMs = gasInfo.fastWait * 60 * 1000; // Minutes to MS + return { gasPriceInWei: gasPriceInGwei.mul(GWEI_IN_WEI), estimatedTimeMs }; }; export class GasPriceEstimator { - private _lastFetched?: BigNumber; - public async getFastAmountInWeiAsync(): Promise<BigNumber> { - let fetchedAmount: BigNumber | undefined; + private _lastFetched?: GasInfo; + public async getGasInfoAsync(): Promise<GasInfo> { + let fetchedAmount: GasInfo | undefined; try { fetchedAmount = await fetchFastAmountInWeiAsync(); } catch { @@ -38,7 +45,7 @@ export class GasPriceEstimator { this._lastFetched = fetchedAmount; } - return fetchedAmount || this._lastFetched || DEFAULT_GAS_PRICE; + return fetchedAmount || this._lastFetched || { gasPriceInWei: DEFAULT_GAS_PRICE, estimatedTimeMs: undefined }; } } export const gasPriceEstimator = new GasPriceEstimator(); |