@@ -36,13 +36,12 @@ import {
3636 trackSubmitButtonReady ,
3737} from '../utils/tracking'
3838import useDebounce from './useDebounce'
39- import { formatCurrency } from '@/utils'
4039import { ChainId } from '@/utils/chains'
4140
4241const DUST_REFRESH_THRESHOLD = 0.025
4342const PRICE_IMPACT_THRESHOLD = 2
44- const MIN_INPUT_PRICE_FOR_ZAP = 1000
45- const DTFS_WITH_MIN_INPUT_PRICE_FOR_ZAP = {
43+ const MIN_INPUT_VALUE_FOR_ZAP = 1000
44+ const DTFS_WITH_MIN_INPUT_VALUE_FOR_ZAP = {
4645 [ ChainId . BSC ] : [ '0x2f8a339b5889ffac4c5a956787cda593b3c36867' ] . map ( ( address ) =>
4746 address . toLowerCase ( )
4847 ) ,
@@ -57,7 +56,7 @@ const useZapSwapQuery = ({
5756 forceMint,
5857 dtfTicker,
5958 type,
60- inputPrice ,
59+ inputValue ,
6160} : {
6261 tokenIn ?: Address
6362 tokenOut ?: Address
@@ -67,7 +66,7 @@ const useZapSwapQuery = ({
6766 forceMint : boolean
6867 dtfTicker : string
6968 type : 'buy' | 'sell'
70- inputPrice : number
69+ inputValue : number
7170} ) => {
7271 const api = useAtomValue ( apiUrlAtom )
7372 const chainId = useAtomValue ( chainIdAtom )
@@ -195,20 +194,6 @@ const useZapSwapQuery = ({
195194 let priceImpactAttempt = 0
196195 let lastData : ZapResponse
197196
198- if (
199- inputPrice < MIN_INPUT_PRICE_FOR_ZAP &&
200- DTFS_WITH_MIN_INPUT_PRICE_FOR_ZAP [ chainId ] ?. includes (
201- dtf ?. id ?. toLowerCase ( ) ?? ''
202- )
203- ) {
204- throw new Error (
205- `Minimum input price for Zap is $${ formatCurrency (
206- MIN_INPUT_PRICE_FOR_ZAP ,
207- 0
208- ) } `
209- )
210- }
211-
212197 // eslint-disable-next-line no-constant-condition
213198 while ( true ) {
214199 // currently no retries for zap
@@ -436,8 +421,19 @@ const useZapSwapQuery = ({
436421 return zapQuote
437422 }
438423
424+ const shouldSkipZapper =
425+ DTFS_WITH_MIN_INPUT_VALUE_FOR_ZAP [ chainId ] ?. includes (
426+ dtf ?. id ?. toLowerCase ( ) ?? ''
427+ ) && inputValue < MIN_INPUT_VALUE_FOR_ZAP
428+
439429 return useQuery ( {
440- queryKey : [ 'zapDeploy' , zapEndpoint , odosEndpoint , quoteSource ] ,
430+ queryKey : [
431+ 'zapDeploy' ,
432+ zapEndpoint ,
433+ odosEndpoint ,
434+ quoteSource ,
435+ shouldSkipZapper ,
436+ ] ,
441437 queryFn : async ( ) : Promise < ZapResponse & { source : 'zap' | 'odos' } > => {
442438 if ( ! tokenIn || ! tokenOut ) {
443439 throw new Error ( 'Invalid tokenIn, tokenOut' )
@@ -466,31 +462,42 @@ const useZapSwapQuery = ({
466462 } else if ( quoteSource === 'odos' ) {
467463 result = await fetchOdosQuote ( newQuoteId , newRetryId )
468464 } else {
469- // 'best' - fetch both in parallel and select the best
470- const results = await Promise . allSettled ( [
471- fetchZapQuote ( newQuoteId , newRetryId ) ,
472- fetchOdosQuote ( newQuoteId , newRetryId ) ,
473- ] )
474-
475- const zapResult =
476- results [ 0 ] . status === 'fulfilled' ? results [ 0 ] . value : undefined
477- const odosResult =
478- results [ 1 ] . status === 'fulfilled' ? results [ 1 ] . value : undefined
479-
480- const bestQuote = selectBestQuote ( zapResult , odosResult )
481-
482- if ( ! bestQuote ) {
483- // Both failed, throw the first error
484- if ( results [ 0 ] . status === 'rejected' ) {
485- throw results [ 0 ] . reason
465+ // 'best' - handle minimum value logic
466+ if ( shouldSkipZapper ) {
467+ // Below minimum for specific DTFs - try Odos first, fallback to Zapper if it fails
468+ try {
469+ result = await fetchOdosQuote ( newQuoteId , newRetryId )
470+ } catch {
471+ // Odos failed, fallback to Zapper
472+ result = await fetchZapQuote ( newQuoteId , newRetryId )
486473 }
487- if ( results [ 1 ] . status === 'rejected' ) {
488- throw results [ 1 ] . reason
474+ } else {
475+ // Above minimum or not applicable - try both in parallel
476+ const results = await Promise . allSettled ( [
477+ fetchZapQuote ( newQuoteId , newRetryId ) ,
478+ fetchOdosQuote ( newQuoteId , newRetryId ) ,
479+ ] )
480+
481+ const zapResult =
482+ results [ 0 ] . status === 'fulfilled' ? results [ 0 ] . value : undefined
483+ const odosResult =
484+ results [ 1 ] . status === 'fulfilled' ? results [ 1 ] . value : undefined
485+
486+ const bestQuote = selectBestQuote ( zapResult , odosResult )
487+
488+ if ( ! bestQuote ) {
489+ // Both failed, throw the first error
490+ if ( results [ 0 ] . status === 'rejected' ) {
491+ throw results [ 0 ] . reason
492+ }
493+ if ( results [ 1 ] . status === 'rejected' ) {
494+ throw results [ 1 ] . reason
495+ }
496+ throw new Error ( 'No quotes available' )
489497 }
490- throw new Error ( 'No quotes available' )
491- }
492498
493- result = bestQuote
499+ result = bestQuote
500+ }
494501 }
495502
496503 const newSourceId = generateSourceId ( result . source )
@@ -511,11 +518,12 @@ const useZapSwapQuery = ({
511518 return result
512519 } ,
513520 enabled :
521+ ! disabled &&
514522 ( quoteSource === 'best'
515523 ? ! ! zapEndpoint || ! ! odosEndpoint
516524 : quoteSource === 'zap'
517525 ? ! ! zapEndpoint
518- : ! ! odosEndpoint ) && ! disabled ,
526+ : ! ! odosEndpoint ) ,
519527 refetchInterval : 12000 ,
520528 retry : 3 ,
521529 retryDelay : ( attempt ) => Math . min ( 1000 * Math . pow ( 2 , attempt ) , 10000 ) ,
0 commit comments