aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebnaoff@gmail.com>2018-10-30 11:06:31 +0800
committerSteve Klebanoff <steve.klebnaoff@gmail.com>2018-10-30 11:06:31 +0800
commitf9eba65aee8e71de609801e640de4101af9645e6 (patch)
treede01bf0d4e72f45bcd02aa864f9bb68e92d48e55 /packages/instant/src/util
parent5901ee7e963a4413f49fffdd9477085229e7623f (diff)
downloaddexon-0x-contracts-f9eba65aee8e71de609801e640de4101af9645e6.tar.gz
dexon-0x-contracts-f9eba65aee8e71de609801e640de4101af9645e6.tar.zst
dexon-0x-contracts-f9eba65aee8e71de609801e640de4101af9645e6.zip
return estimated state
Diffstat (limited to 'packages/instant/src/util')
-rw-r--r--packages/instant/src/util/gas_price_estimator.ts19
1 files changed, 13 insertions, 6 deletions
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();