Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const processSwapQuoteError = (error: any) => (dispatch: Dispatch, getState: GetState) => {
const state = getState()
const { fromCurrencyCode, toCurrencyCode } = state.cryptoExchange
// Basic sanity checks (should never fail):
if (error == null) return
if (fromCurrencyCode == null || toCurrencyCode == null) return
// Check for known error types:
switch (error.name) {
case errorNames.InsufficientFundsError: {
return dispatch({ type: 'RECEIVED_INSUFFICENT_FUNDS_ERROR' })
}
case errorNames.SwapAboveLimitError: {
const settings = SETTINGS_SELECTORS.getSettings(state)
const currentCurrencyDenomination = SETTINGS_SELECTORS.getDisplayDenominationFromSettings(settings, fromCurrencyCode)
const nativeMax: string = error.nativeMax
const displayDenomination = SETTINGS_SELECTORS.getDisplayDenomination(state, fromCurrencyCode)
const nativeToDisplayRatio = displayDenomination.multiplier
const displayMax = UTILS.convertNativeToDisplay(nativeToDisplayRatio)(nativeMax)
return dispatch({
type: 'GENERIC_SHAPE_SHIFT_ERROR',
data: sprintf(s.strings.amount_above_limit, displayMax, currentCurrencyDenomination.name)
})
}
case errorNames.SwapBelowLimitError: {
const settings = SETTINGS_SELECTORS.getSettings(state)