aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-07-06 06:37:35 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-07-06 06:37:35 +0800
commitf894ffc0ccccca8e94ea37dda6184168f126839d (patch)
tree8815bca7eeac39f293fdcb246383825c18622db0 /packages/website/ts
parent127fbc6e943d23cf1202f403a5b402226963d947 (diff)
downloaddexon-sol-tools-f894ffc0ccccca8e94ea37dda6184168f126839d.tar
dexon-sol-tools-f894ffc0ccccca8e94ea37dda6184168f126839d.tar.gz
dexon-sol-tools-f894ffc0ccccca8e94ea37dda6184168f126839d.tar.bz2
dexon-sol-tools-f894ffc0ccccca8e94ea37dda6184168f126839d.tar.lz
dexon-sol-tools-f894ffc0ccccca8e94ea37dda6184168f126839d.tar.xz
dexon-sol-tools-f894ffc0ccccca8e94ea37dda6184168f126839d.tar.zst
dexon-sol-tools-f894ffc0ccccca8e94ea37dda6184168f126839d.zip
Poll for gas prices and use fast instead of average for better UX
Diffstat (limited to 'packages/website/ts')
-rw-r--r--packages/website/ts/blockchain.ts30
-rw-r--r--packages/website/ts/types.ts3
2 files changed, 29 insertions, 4 deletions
diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts
index cc2afa28a..efeeafe32 100644
--- a/packages/website/ts/blockchain.ts
+++ b/packages/website/ts/blockchain.ts
@@ -89,6 +89,7 @@ export class Blockchain {
private _userAddressIfExists: string;
private _ledgerSubprovider: LedgerSubprovider;
private _defaultGasPrice: BigNumber;
+ private _watchGasPriceIntervalId: NodeJS.Timer;
private static _getNameGivenProvider(provider: Provider): string {
const providerType = utils.getProviderType(provider);
const providerNameIfExists = providerToName[providerType];
@@ -196,13 +197,11 @@ export class Blockchain {
}
constructor(dispatcher: Dispatcher) {
this._dispatcher = dispatcher;
- const defaultGasPrice = GWEI_IN_WEI * 30;
+ const defaultGasPrice = GWEI_IN_WEI * 40;
this._defaultGasPrice = new BigNumber(defaultGasPrice);
// We need a unique reference to this function so we can use it to unsubcribe.
this._injectedProviderUpdateHandler = this._handleInjectedProviderUpdateAsync.bind(this);
// tslint:disable-next-line:no-floating-promises
- this._updateDefaultGasPriceAsync();
- // tslint:disable-next-line:no-floating-promises
this._onPageLoadInitFireAndForgetAsync();
}
public async networkIdUpdatedFireAndForgetAsync(newNetworkId: number): Promise<void> {
@@ -537,6 +536,7 @@ export class Blockchain {
this._blockchainWatcher.destroy();
this._injectedProviderObservable.unsubscribe(this._injectedProviderUpdateHandler);
this._stopWatchingExchangeLogFillEvents();
+ this._stopWatchingGasPrice();
}
public async fetchTokenInformationAsync(): Promise<void> {
utils.assert(
@@ -798,8 +798,30 @@ export class Blockchain {
this._updateProviderName(injectedWeb3IfExists);
const shouldPollUserAddress = true;
const shouldUseLedgerProvider = false;
+ this._startWatchingGasPrice();
await this._resetOrInitializeAsync(this.networkId, shouldPollUserAddress, shouldUseLedgerProvider);
}
+ private _startWatchingGasPrice(): void {
+ if (!_.isUndefined(this._watchGasPriceIntervalId)) {
+ return; // we are already watching
+ }
+ // tslint:disable-next-line:no-floating-promises
+ this._updateDefaultGasPriceAsync();
+ this._watchGasPriceIntervalId = intervalUtils.setAsyncExcludingInterval(
+ this._updateDefaultGasPriceAsync.bind(this),
+ // 1 minute
+ 60000,
+ (err: Error) => {
+ logUtils.log(`Watching gas price failed: ${err.stack}`);
+ this._stopWatchingGasPrice();
+ },
+ );
+ }
+ private _stopWatchingGasPrice(): void {
+ if (!_.isUndefined(this._watchGasPriceIntervalId)) {
+ intervalUtils.clearAsyncExcludingInterval(this._watchGasPriceIntervalId);
+ }
+ }
private async _resetOrInitializeAsync(
networkId: number,
shouldPollUserAddress: boolean = false,
@@ -895,7 +917,7 @@ export class Blockchain {
private async _updateDefaultGasPriceAsync(): Promise<void> {
try {
const gasInfo = await backendClient.getGasInfoAsync();
- const gasPriceInGwei = new BigNumber(gasInfo.average / 10);
+ const gasPriceInGwei = new BigNumber(gasInfo.fast / 10);
const gasPriceInWei = gasPriceInGwei.mul(1000000000);
this._defaultGasPrice = gasPriceInWei;
} catch (err) {
diff --git a/packages/website/ts/types.ts b/packages/website/ts/types.ts
index 93d029325..a13853052 100644
--- a/packages/website/ts/types.ts
+++ b/packages/website/ts/types.ts
@@ -551,7 +551,10 @@ export interface WebsiteBackendTokenInfo {
}
export interface WebsiteBackendGasInfo {
+ safeSlow: number;
average: number;
+ fast: number;
+ fastest: number;
}
export interface WebsiteBackendJobInfo {