aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/components
diff options
context:
space:
mode:
authorSteve Klebanoff <steve@0xproject.com>2018-11-10 08:02:09 +0800
committerGitHub <noreply@github.com>2018-11-10 08:02:09 +0800
commit26cbe7ae6646d97c286e58756c23a93de32ae37b (patch)
tree96943e8dd87f0e3ef8c994101bce5a16a47082ea /packages/instant/src/components
parent2c585bfbdc4940e3e6089ac1cf595dd009b141d2 (diff)
parentfd83ca2cb893ab7cc027efd6829ba2eb07cdb539 (diff)
downloaddexon-sol-tools-26cbe7ae6646d97c286e58756c23a93de32ae37b.tar
dexon-sol-tools-26cbe7ae6646d97c286e58756c23a93de32ae37b.tar.gz
dexon-sol-tools-26cbe7ae6646d97c286e58756c23a93de32ae37b.tar.bz2
dexon-sol-tools-26cbe7ae6646d97c286e58756c23a93de32ae37b.tar.lz
dexon-sol-tools-26cbe7ae6646d97c286e58756c23a93de32ae37b.tar.xz
dexon-sol-tools-26cbe7ae6646d97c286e58756c23a93de32ae37b.tar.zst
dexon-sol-tools-26cbe7ae6646d97c286e58756c23a93de32ae37b.zip
Merge pull request #1237 from 0xProject/feature/instant/buy-quote-heartbeat
[instant] Heartbeats for account info and buy quotes
Diffstat (limited to 'packages/instant/src/components')
-rw-r--r--packages/instant/src/components/zero_ex_instant_provider.tsx35
1 files changed, 31 insertions, 4 deletions
diff --git a/packages/instant/src/components/zero_ex_instant_provider.tsx b/packages/instant/src/components/zero_ex_instant_provider.tsx
index cceb44377..11f867abc 100644
--- a/packages/instant/src/components/zero_ex_instant_provider.tsx
+++ b/packages/instant/src/components/zero_ex_instant_provider.tsx
@@ -5,15 +5,18 @@ import * as _ from 'lodash';
import * as React from 'react';
import { Provider as ReduxProvider } from 'react-redux';
+import { ACCOUNT_UPDATE_INTERVAL_TIME_MS, BUY_QUOTE_UPDATE_INTERVAL_TIME_MS } from '../constants';
import { SelectedAssetThemeProvider } from '../containers/selected_asset_theme_provider';
import { asyncData } from '../redux/async_data';
import { DEFAULT_STATE, DefaultState, State } from '../redux/reducer';
import { store, Store } from '../redux/store';
import { fonts } from '../style/fonts';
-import { AffiliateInfo, AssetMetaData, Network, OrderSource } from '../types';
+import { AccountState, AffiliateInfo, AssetMetaData, Network, OrderSource } from '../types';
import { assetUtils } from '../util/asset';
import { errorFlasher } from '../util/error_flasher';
import { gasPriceEstimator } from '../util/gas_price_estimator';
+import { Heartbeater } from '../util/heartbeater';
+import { generateAccountHeartbeater, generateBuyQuoteHeartbeater } from '../util/heartbeater_factory';
import { providerStateFactory } from '../util/provider_state_factory';
fonts.include();
@@ -37,6 +40,9 @@ export interface ZeroExInstantProviderOptionalProps {
export class ZeroExInstantProvider extends React.Component<ZeroExInstantProviderProps> {
private readonly _store: Store;
+ private _accountUpdateHeartbeat?: Heartbeater;
+ private _buyQuoteHeartbeat?: Heartbeater;
+
// TODO(fragosti): Write tests for this beast once we inject a provider.
private static _mergeDefaultStateWithProps(
props: ZeroExInstantProviderProps,
@@ -92,10 +98,23 @@ export class ZeroExInstantProvider extends React.Component<ZeroExInstantProvider
// tslint:disable-next-line:no-floating-promises
asyncData.fetchAvailableAssetDatasAndDispatchToStore(this._store);
}
+
+ if (state.providerState.account.state !== AccountState.None) {
+ this._accountUpdateHeartbeat = generateAccountHeartbeater({
+ store: this._store,
+ shouldPerformImmediatelyOnStart: true,
+ });
+ this._accountUpdateHeartbeat.start(ACCOUNT_UPDATE_INTERVAL_TIME_MS);
+ }
+
+ this._buyQuoteHeartbeat = generateBuyQuoteHeartbeater({
+ store: this._store,
+ shouldPerformImmediatelyOnStart: false,
+ });
+ this._buyQuoteHeartbeat.start(BUY_QUOTE_UPDATE_INTERVAL_TIME_MS);
// tslint:disable-next-line:no-floating-promises
- asyncData.fetchAccountInfoAndDispatchToStore(this._store);
- // tslint:disable-next-line:no-floating-promises
- asyncData.fetchCurrentBuyQuoteAndDispatchToStore(this._store);
+ asyncData.fetchCurrentBuyQuoteAndDispatchToStore({ store: this._store, shouldSetPending: true });
+
// 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
@@ -103,6 +122,14 @@ export class ZeroExInstantProvider extends React.Component<ZeroExInstantProvider
// tslint:disable-next-line:no-floating-promises
this._flashErrorIfWrongNetwork();
}
+ public componentWillUnmount(): void {
+ if (this._accountUpdateHeartbeat) {
+ this._accountUpdateHeartbeat.stop();
+ }
+ if (this._buyQuoteHeartbeat) {
+ this._buyQuoteHeartbeat.stop();
+ }
+ }
public render(): React.ReactNode {
return (
<ReduxProvider store={this._store}>