From 447b0f91f9bdc200d14897be94796873c95490c7 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 15 Nov 2018 14:20:19 -0800 Subject: Have heartbeat update not trigger errors --- .../src/components/zero_ex_instant_provider.tsx | 3 +- .../selected_erc20_asset_amount_input.ts | 9 ++++- packages/instant/src/redux/async_data.ts | 4 +- packages/instant/src/util/buy_quote_updater.ts | 44 ++++++++++++---------- packages/instant/src/util/heartbeater_factory.ts | 4 +- 5 files changed, 39 insertions(+), 25 deletions(-) (limited to 'packages/instant') diff --git a/packages/instant/src/components/zero_ex_instant_provider.tsx b/packages/instant/src/components/zero_ex_instant_provider.tsx index 18e71edb6..f6dadf3e4 100644 --- a/packages/instant/src/components/zero_ex_instant_provider.tsx +++ b/packages/instant/src/components/zero_ex_instant_provider.tsx @@ -113,7 +113,8 @@ export class ZeroExInstantProvider extends React.Component { const { buyOrderState, providerState, selectedAsset, selectedAssetUnitAmount, affiliateInfo } = state; const assetBuyer = providerState.assetBuyer; @@ -97,7 +97,7 @@ export const asyncData = { dispatch, selectedAsset as ERC20Asset, selectedAssetUnitAmount, - shouldSetPending, + { setPending: !options.updateSilently, dispatchErrors: !options.updateSilently }, affiliateInfo, ); } diff --git a/packages/instant/src/util/buy_quote_updater.ts b/packages/instant/src/util/buy_quote_updater.ts index fcdded0a9..eeb792bcf 100644 --- a/packages/instant/src/util/buy_quote_updater.ts +++ b/packages/instant/src/util/buy_quote_updater.ts @@ -16,12 +16,12 @@ export const buyQuoteUpdater = { dispatch: Dispatch, asset: ERC20Asset, assetUnitAmount: BigNumber, - setPending = true, + options: { setPending: boolean; dispatchErrors: boolean }, affiliateInfo?: AffiliateInfo, ): Promise => { // get a new buy quote. const baseUnitValue = Web3Wrapper.toBaseUnitAmount(assetUnitAmount, asset.metaData.decimals); - if (setPending) { + if (options.setPending) { // mark quote as pending dispatch(actions.setQuoteRequestStatePending()); } @@ -30,25 +30,29 @@ export const buyQuoteUpdater = { try { newBuyQuote = await assetBuyer.getBuyQuoteAsync(asset.assetData, baseUnitValue, { feePercentage }); } catch (error) { - dispatch(actions.setQuoteRequestStateFailure()); - let errorMessage; - if (error.message === AssetBuyerError.InsufficientAssetLiquidity) { - const assetName = assetUtils.bestNameForAsset(asset, 'of this asset'); - errorMessage = `Not enough ${assetName} available`; - } else if (error.message === AssetBuyerError.InsufficientZrxLiquidity) { - errorMessage = 'Not enough ZRX available'; - } else if ( - error.message === AssetBuyerError.StandardRelayerApiError || - error.message.startsWith(AssetBuyerError.AssetUnavailable) - ) { - const assetName = assetUtils.bestNameForAsset(asset, 'This asset'); - errorMessage = `${assetName} is currently unavailable`; - } - if (!_.isUndefined(errorMessage)) { - errorFlasher.flashNewErrorMessage(dispatch, errorMessage); - } else { - throw error; + if (options.dispatchErrors) { + dispatch(actions.setQuoteRequestStateFailure()); + let errorMessage; + if (error.message === AssetBuyerError.InsufficientAssetLiquidity) { + const assetName = assetUtils.bestNameForAsset(asset, 'of this asset'); + errorMessage = `Not enough ${assetName} available`; + } else if (error.message === AssetBuyerError.InsufficientZrxLiquidity) { + errorMessage = 'Not enough ZRX available'; + } else if ( + error.message === AssetBuyerError.StandardRelayerApiError || + error.message.startsWith(AssetBuyerError.AssetUnavailable) + ) { + const assetName = assetUtils.bestNameForAsset(asset, 'This asset'); + errorMessage = `${assetName} is currently unavailable`; + } + if (!_.isUndefined(errorMessage)) { + errorFlasher.flashNewErrorMessage(dispatch, errorMessage); + } else { + throw error; + } } + // TODO: report to error reporter on else + return; } // We have a successful new buy quote diff --git a/packages/instant/src/util/heartbeater_factory.ts b/packages/instant/src/util/heartbeater_factory.ts index 06fcdb8bb..2b852fb0d 100644 --- a/packages/instant/src/util/heartbeater_factory.ts +++ b/packages/instant/src/util/heartbeater_factory.ts @@ -17,6 +17,8 @@ export const generateAccountHeartbeater = (options: HeartbeatFactoryOptions): He export const generateBuyQuoteHeartbeater = (options: HeartbeatFactoryOptions): Heartbeater => { const { store, shouldPerformImmediatelyOnStart } = options; return new Heartbeater(async () => { - await asyncData.fetchCurrentBuyQuoteAndDispatchToStore(store.getState(), store.dispatch, false); + await asyncData.fetchCurrentBuyQuoteAndDispatchToStore(store.getState(), store.dispatch, { + updateSilently: true, + }); }, shouldPerformImmediatelyOnStart); }; -- cgit v1.2.3 From 33a156d9b5278c0e85a1fa0fe158440a41bcc60e Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 15 Nov 2018 15:12:43 -0800 Subject: Send in affiliate info as option --- .../src/containers/selected_erc20_asset_amount_input.ts | 11 ++++------- packages/instant/src/redux/async_data.ts | 3 +-- packages/instant/src/util/buy_quote_updater.ts | 5 ++--- 3 files changed, 7 insertions(+), 12 deletions(-) (limited to 'packages/instant') diff --git a/packages/instant/src/containers/selected_erc20_asset_amount_input.ts b/packages/instant/src/containers/selected_erc20_asset_amount_input.ts index 3e6ef41a0..2c2661e1a 100644 --- a/packages/instant/src/containers/selected_erc20_asset_amount_input.ts +++ b/packages/instant/src/containers/selected_erc20_asset_amount_input.ts @@ -81,14 +81,11 @@ const mapDispatchToProps = ( // even if it's debounced, give them the illusion it's loading dispatch(actions.setQuoteRequestStatePending()); // tslint:disable-next-line:no-floating-promises - debouncedUpdateBuyQuoteAsync( - assetBuyer, - dispatch, - asset, - value, - { setPending: true, dispatchErrors: true }, + debouncedUpdateBuyQuoteAsync(assetBuyer, dispatch, asset, value, { + setPending: true, + dispatchErrors: true, affiliateInfo, - ); + }); } }, }); diff --git a/packages/instant/src/redux/async_data.ts b/packages/instant/src/redux/async_data.ts index f4b3f94bf..5d30388b8 100644 --- a/packages/instant/src/redux/async_data.ts +++ b/packages/instant/src/redux/async_data.ts @@ -97,8 +97,7 @@ export const asyncData = { dispatch, selectedAsset as ERC20Asset, selectedAssetUnitAmount, - { setPending: !options.updateSilently, dispatchErrors: !options.updateSilently }, - affiliateInfo, + { setPending: !options.updateSilently, dispatchErrors: !options.updateSilently, affiliateInfo }, ); } }, diff --git a/packages/instant/src/util/buy_quote_updater.ts b/packages/instant/src/util/buy_quote_updater.ts index eeb792bcf..2fd16d781 100644 --- a/packages/instant/src/util/buy_quote_updater.ts +++ b/packages/instant/src/util/buy_quote_updater.ts @@ -16,8 +16,7 @@ export const buyQuoteUpdater = { dispatch: Dispatch, asset: ERC20Asset, assetUnitAmount: BigNumber, - options: { setPending: boolean; dispatchErrors: boolean }, - affiliateInfo?: AffiliateInfo, + options: { setPending: boolean; dispatchErrors: boolean; affiliateInfo?: AffiliateInfo }, ): Promise => { // get a new buy quote. const baseUnitValue = Web3Wrapper.toBaseUnitAmount(assetUnitAmount, asset.metaData.decimals); @@ -25,7 +24,7 @@ export const buyQuoteUpdater = { // mark quote as pending dispatch(actions.setQuoteRequestStatePending()); } - const feePercentage = oc(affiliateInfo).feePercentage(); + const feePercentage = oc(options.affiliateInfo).feePercentage(); let newBuyQuote: BuyQuote | undefined; try { newBuyQuote = await assetBuyer.getBuyQuoteAsync(asset.assetData, baseUnitValue, { feePercentage }); -- cgit v1.2.3