diff options
Diffstat (limited to 'packages/instant/src/util/buy_quote_updater.ts')
-rw-r--r-- | packages/instant/src/util/buy_quote_updater.ts | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/packages/instant/src/util/buy_quote_updater.ts b/packages/instant/src/util/buy_quote_updater.ts deleted file mode 100644 index 37974e71c..000000000 --- a/packages/instant/src/util/buy_quote_updater.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { AssetBuyer, BuyQuote } from '@0x/asset-buyer'; -import { BigNumber } from '@0x/utils'; -import { Web3Wrapper } from '@0x/web3-wrapper'; -import * as _ from 'lodash'; -import { Dispatch } from 'redux'; -import { oc } from 'ts-optchain'; - -import { SLIPPAGE_PERCENTAGE } from '../constants'; -import { Action, actions } from '../redux/actions'; -import { AffiliateInfo, ERC20Asset, QuoteFetchOrigin } from '../types'; -import { analytics } from '../util/analytics'; -import { assetUtils } from '../util/asset'; -import { errorFlasher } from '../util/error_flasher'; -import { errorReporter } from '../util/error_reporter'; - -export const buyQuoteUpdater = { - updateBuyQuoteAsync: async ( - assetBuyer: AssetBuyer, - dispatch: Dispatch<Action>, - asset: ERC20Asset, - assetUnitAmount: BigNumber, - fetchOrigin: QuoteFetchOrigin, - options: { - setPending: boolean; - dispatchErrors: boolean; - affiliateInfo?: AffiliateInfo; - }, - ): Promise<void> => { - // get a new buy quote. - const baseUnitValue = Web3Wrapper.toBaseUnitAmount(assetUnitAmount, asset.metaData.decimals); - if (options.setPending) { - // mark quote as pending - dispatch(actions.setQuoteRequestStatePending()); - } - const feePercentage = oc(options.affiliateInfo).feePercentage(); - let newBuyQuote: BuyQuote | undefined; - const slippagePercentage = SLIPPAGE_PERCENTAGE; - try { - newBuyQuote = await assetBuyer.getBuyQuoteAsync(asset.assetData, baseUnitValue, { - feePercentage, - slippagePercentage, - }); - } catch (error) { - const errorMessage = assetUtils.assetBuyerErrorMessage(asset, error); - - errorReporter.report(error); - analytics.trackQuoteError(error.message ? error.message : 'other', baseUnitValue, fetchOrigin); - - if (options.dispatchErrors) { - dispatch(actions.setQuoteRequestStateFailure()); - errorFlasher.flashNewErrorMessage(dispatch, errorMessage || 'Error fetching price, please try again'); - } - return; - } - // We have a successful new buy quote - errorFlasher.clearError(dispatch); - // invalidate the last buy quote. - dispatch(actions.updateLatestBuyQuote(newBuyQuote)); - analytics.trackQuoteFetched(newBuyQuote, fetchOrigin); - }, -}; |