aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-17 02:26:01 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-17 02:26:01 +0800
commit9c182fe6e41f47e6f1eac2fbc7158f9143e406c4 (patch)
treead12ac3206d2ece4a1c778c59ce6a5de1b81aa38 /packages/instant/src/util
parentcbcb954c3015b7044e0c1f1b594103df8ea4dfa7 (diff)
parent1626e284cd6488663ad1be03f0d8f72afced7afb (diff)
downloaddexon-sol-tools-9c182fe6e41f47e6f1eac2fbc7158f9143e406c4.tar
dexon-sol-tools-9c182fe6e41f47e6f1eac2fbc7158f9143e406c4.tar.gz
dexon-sol-tools-9c182fe6e41f47e6f1eac2fbc7158f9143e406c4.tar.bz2
dexon-sol-tools-9c182fe6e41f47e6f1eac2fbc7158f9143e406c4.tar.lz
dexon-sol-tools-9c182fe6e41f47e6f1eac2fbc7158f9143e406c4.tar.xz
dexon-sol-tools-9c182fe6e41f47e6f1eac2fbc7158f9143e406c4.tar.zst
dexon-sol-tools-9c182fe6e41f47e6f1eac2fbc7158f9143e406c4.zip
Merge branch 'development' into feature/instant/heap
Diffstat (limited to 'packages/instant/src/util')
-rw-r--r--packages/instant/src/util/buy_quote_updater.ts47
-rw-r--r--packages/instant/src/util/heartbeater_factory.ts4
2 files changed, 28 insertions, 23 deletions
diff --git a/packages/instant/src/util/buy_quote_updater.ts b/packages/instant/src/util/buy_quote_updater.ts
index fcdded0a9..2fd16d781 100644
--- a/packages/instant/src/util/buy_quote_updater.ts
+++ b/packages/instant/src/util/buy_quote_updater.ts
@@ -16,39 +16,42 @@ export const buyQuoteUpdater = {
dispatch: Dispatch<Action>,
asset: ERC20Asset,
assetUnitAmount: BigNumber,
- setPending = true,
- affiliateInfo?: AffiliateInfo,
+ options: { setPending: boolean; dispatchErrors: boolean; affiliateInfo?: AffiliateInfo },
): Promise<void> => {
// 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());
}
- const feePercentage = oc(affiliateInfo).feePercentage();
+ const feePercentage = oc(options.affiliateInfo).feePercentage();
let newBuyQuote: BuyQuote | undefined;
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);
};