From 7acaae37a969339d1b4971f80d7fd842266bb60b Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 8 Nov 2018 14:57:39 -0800 Subject: feat(instant): Heartbeat for updating account info --- packages/instant/src/redux/async_data.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/instant/src/redux') diff --git a/packages/instant/src/redux/async_data.ts b/packages/instant/src/redux/async_data.ts index 862f60e78..055d3de20 100644 --- a/packages/instant/src/redux/async_data.ts +++ b/packages/instant/src/redux/async_data.ts @@ -34,10 +34,10 @@ export const asyncData = { store.dispatch(actions.setAvailableAssets([])); } }, - fetchAccountInfoAndDispatchToStore: async (store: Store) => { + fetchAccountInfoAndDispatchToStore: async (store: Store, options = { setLoading: true }) => { const { providerState } = store.getState(); const web3Wrapper = providerState.web3Wrapper; - if (providerState.account.state !== AccountState.Loading) { + if (options.setLoading && providerState.account.state !== AccountState.Loading) { store.dispatch(actions.setAccountStateLoading()); } let availableAddresses: string[]; -- cgit v1.2.3 From 2e8f74abce7be3a5799bb93a0360d299de55b621 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Fri, 9 Nov 2018 10:40:47 -0800 Subject: Use existing functions instead of writing our own --- packages/instant/src/redux/async_data.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages/instant/src/redux') diff --git a/packages/instant/src/redux/async_data.ts b/packages/instant/src/redux/async_data.ts index a50f24cba..7af6e1e56 100644 --- a/packages/instant/src/redux/async_data.ts +++ b/packages/instant/src/redux/async_data.ts @@ -74,7 +74,7 @@ export const asyncData = { return; } }, - fetchCurrentBuyQuoteAndDispatchToStore: async (store: Store) => { + fetchCurrentBuyQuoteAndDispatchToStore: async (store: Store, setPending: boolean) => { const { providerState, selectedAsset, selectedAssetAmount, affiliateInfo } = store.getState(); const assetBuyer = providerState.assetBuyer; if ( @@ -87,6 +87,7 @@ export const asyncData = { store.dispatch, selectedAsset as ERC20Asset, selectedAssetAmount, + setPending, affiliateInfo, ); } -- cgit v1.2.3 From 39657b633bd386526f5772238cbebfb976427c07 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Fri, 9 Nov 2018 11:04:44 -0800 Subject: Make sure we only update price when they are not in the middle of an order --- packages/instant/src/redux/async_data.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'packages/instant/src/redux') diff --git a/packages/instant/src/redux/async_data.ts b/packages/instant/src/redux/async_data.ts index 7af6e1e56..c7fe4cd0e 100644 --- a/packages/instant/src/redux/async_data.ts +++ b/packages/instant/src/redux/async_data.ts @@ -2,7 +2,7 @@ import { AssetProxyId } from '@0x/types'; import * as _ from 'lodash'; import { BIG_NUMBER_ZERO } from '../constants'; -import { AccountState, ERC20Asset } from '../types'; +import { AccountState, ERC20Asset, OrderProcessState } from '../types'; import { assetUtils } from '../util/asset'; import { buyQuoteUpdater } from '../util/buy_quote_updater'; import { coinbaseApi } from '../util/coinbase_api'; @@ -75,11 +75,12 @@ export const asyncData = { } }, fetchCurrentBuyQuoteAndDispatchToStore: async (store: Store, setPending: boolean) => { - const { providerState, selectedAsset, selectedAssetAmount, affiliateInfo } = store.getState(); + const { buyOrderState, providerState, selectedAsset, selectedAssetAmount, affiliateInfo } = store.getState(); const assetBuyer = providerState.assetBuyer; if ( !_.isUndefined(selectedAssetAmount) && !_.isUndefined(selectedAsset) && + buyOrderState.processState === OrderProcessState.None && selectedAsset.metaData.assetProxyId === AssetProxyId.ERC20 ) { await buyQuoteUpdater.updateBuyQuoteAsync( -- cgit v1.2.3 From 474db7c18de63429f72511796291ff135c77f10b Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Fri, 9 Nov 2018 11:22:46 -0800 Subject: Emulate named parameters with interface --- packages/instant/src/redux/async_data.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages/instant/src/redux') diff --git a/packages/instant/src/redux/async_data.ts b/packages/instant/src/redux/async_data.ts index c7fe4cd0e..61de54d82 100644 --- a/packages/instant/src/redux/async_data.ts +++ b/packages/instant/src/redux/async_data.ts @@ -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 ( -- cgit v1.2.3 From 36b8c9c5dd6cc650eaed8a2a6abd8f596c189fed Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Fri, 9 Nov 2018 11:28:08 -0800 Subject: Use interface like named parameters here --- packages/instant/src/redux/async_data.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'packages/instant/src/redux') diff --git a/packages/instant/src/redux/async_data.ts b/packages/instant/src/redux/async_data.ts index 61de54d82..1f1cafdf3 100644 --- a/packages/instant/src/redux/async_data.ts +++ b/packages/instant/src/redux/async_data.ts @@ -36,10 +36,11 @@ export const asyncData = { store.dispatch(actions.setAvailableAssets([])); } }, - fetchAccountInfoAndDispatchToStore: async (store: Store, options = { setLoading: true }) => { + fetchAccountInfoAndDispatchToStore: async (options: { store: Store; setLoading: boolean }) => { + const { store, setLoading } = options; const { providerState } = store.getState(); const web3Wrapper = providerState.web3Wrapper; - if (options.setLoading && providerState.account.state !== AccountState.Loading) { + if (setLoading && providerState.account.state !== AccountState.Loading) { store.dispatch(actions.setAccountStateLoading()); } let availableAddresses: string[]; -- cgit v1.2.3 From cc8debe53b9a6efc75b91f1b6c47f0820c3beb8c Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Fri, 9 Nov 2018 11:39:36 -0800 Subject: Linting and renaming variables --- packages/instant/src/redux/async_data.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'packages/instant/src/redux') diff --git a/packages/instant/src/redux/async_data.ts b/packages/instant/src/redux/async_data.ts index 1f1cafdf3..a47c7a605 100644 --- a/packages/instant/src/redux/async_data.ts +++ b/packages/instant/src/redux/async_data.ts @@ -36,11 +36,11 @@ export const asyncData = { store.dispatch(actions.setAvailableAssets([])); } }, - fetchAccountInfoAndDispatchToStore: async (options: { store: Store; setLoading: boolean }) => { - const { store, setLoading } = options; + fetchAccountInfoAndDispatchToStore: async (options: { store: Store; shouldSetToLoading: boolean }) => { + const { store, shouldSetToLoading } = options; const { providerState } = store.getState(); const web3Wrapper = providerState.web3Wrapper; - if (setLoading && providerState.account.state !== AccountState.Loading) { + if (shouldSetToLoading && providerState.account.state !== AccountState.Loading) { store.dispatch(actions.setAccountStateLoading()); } let availableAddresses: string[]; @@ -75,8 +75,8 @@ export const asyncData = { return; } }, - fetchCurrentBuyQuoteAndDispatchToStore: async (options: { store: Store; setPending: boolean }) => { - const { store, setPending } = options; + fetchCurrentBuyQuoteAndDispatchToStore: async (options: { store: Store; shouldSetPending: boolean }) => { + const { store, shouldSetPending } = options; const { buyOrderState, providerState, selectedAsset, selectedAssetAmount, affiliateInfo } = store.getState(); const assetBuyer = providerState.assetBuyer; if ( @@ -90,7 +90,7 @@ export const asyncData = { store.dispatch, selectedAsset as ERC20Asset, selectedAssetAmount, - setPending, + shouldSetPending, affiliateInfo, ); } -- cgit v1.2.3