Emulate named parameters with interface

This commit is contained in:
Steve Klebanoff
2018-11-09 11:22:46 -08:00
parent 39657b633b
commit 474db7c18d
3 changed files with 17 additions and 7 deletions

View File

@@ -100,12 +100,15 @@ export class ZeroExInstantProvider extends React.Component<ZeroExInstantProvider
}
// tslint:disable-next-line:no-floating-promises
this._accountUpdateHeartbeat = generateAccountHeartbeater(this._store, true);
this._accountUpdateHeartbeat = generateAccountHeartbeater({
store: this._store,
performImmediatelyOnStart: true,
});
this._accountUpdateHeartbeat.start(ACCOUNT_UPDATE_INTERVAL_TIME_MS);
this._buyQuoteHeartbeat = generateBuyQuoteHeartbeater(this._store, false);
this._buyQuoteHeartbeat = generateBuyQuoteHeartbeater({ store: this._store, performImmediatelyOnStart: false });
this._buyQuoteHeartbeat.start(BUY_QUOTE_UPDATE_INTERVAL_TIME_MS);
asyncData.fetchCurrentBuyQuoteAndDispatchToStore(this._store, true);
asyncData.fetchCurrentBuyQuoteAndDispatchToStore({ store: this._store, setPending: true });
// warm up the gas price estimator cache just in case we can't
// grab the gas price estimate when submitting the transaction

View File

@@ -74,7 +74,8 @@ export const asyncData = {
return;
}
},
fetchCurrentBuyQuoteAndDispatchToStore: async (store: Store, setPending: boolean) => {
fetchCurrentBuyQuoteAndDispatchToStore: async (options: { store: Store; setPending: boolean }) => {
const { store, setPending } = options;
const { buyOrderState, providerState, selectedAsset, selectedAssetAmount, affiliateInfo } = store.getState();
const assetBuyer = providerState.assetBuyer;
if (

View File

@@ -3,14 +3,20 @@ import { Store } from '../redux/store';
import { Heartbeater } from './heartbeater';
export const generateAccountHeartbeater = (store: Store, performImmediatelyOnStart: boolean): Heartbeater => {
export interface HeartbeatFactoryOptions {
store: Store;
performImmediatelyOnStart: boolean;
}
export const generateAccountHeartbeater = (options: HeartbeatFactoryOptions): Heartbeater => {
const { store, performImmediatelyOnStart } = options;
return new Heartbeater(async () => {
await asyncData.fetchAccountInfoAndDispatchToStore(store, { setLoading: false });
}, performImmediatelyOnStart);
};
export const generateBuyQuoteHeartbeater = (store: Store, performImmediatelyOnStart: boolean): Heartbeater => {
export const generateBuyQuoteHeartbeater = (options: HeartbeatFactoryOptions): Heartbeater => {
const { store, performImmediatelyOnStart } = options;
return new Heartbeater(async () => {
await asyncData.fetchCurrentBuyQuoteAndDispatchToStore(store, false);
await asyncData.fetchCurrentBuyQuoteAndDispatchToStore({ store, setPending: false });
}, performImmediatelyOnStart);
};