Skip to content

Commit 2ff51ae

Browse files
authored
fix: swap quotes (#1833)
* fix tx review no opening for swap * remove base support for swap
1 parent 7a6b580 commit 2ff51ae

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
lines changed

src/app/store/trade-machine.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { atomWithMachine } from 'jotai-xstate'
2-
import { TransactionReceipt } from 'viem'
32
import { assertEvent, assign, createMachine } from 'xstate'
43

5-
import { TransactionReview } from '@/components/swap/components/transaction-review/types'
6-
import { QuoteResult, QuoteType } from '@/lib/hooks/use-best-quote/types'
7-
4+
import type { TransactionReview } from '@/components/swap/components/transaction-review/types'
85
import type { PostApiV2Trade200 } from '@/gen'
6+
import type { QuoteResult, QuoteType } from '@/lib/hooks/use-best-quote/types'
7+
import type { TransactionReceipt } from 'viem'
98

109
// Define the context type for our state machine
1110
export interface TradeMachineContext {

src/components/smart-trade-button/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import {
88
useTradeButtonState,
99
} from '@/components/swap/hooks/use-trade-button-state'
1010
import { TradeButton } from '@/components/trade-button'
11-
import { Token } from '@/constants/tokens'
1211
import { useApproval } from '@/lib/hooks/use-approval'
1312
import { useIsTokenPairTradable } from '@/lib/hooks/use-is-token-pair-tradable'
1413
import { useNetwork } from '@/lib/hooks/use-network'
1514
import { useProtectionContext } from '@/lib/providers/protection'
1615
import { useSlippage } from '@/lib/providers/slippage'
1716
import { getNativeToken } from '@/lib/utils/tokens'
1817

18+
import type { Token } from '@/constants/tokens'
19+
1920
type SmartTradeButtonProps = {
2021
inputToken: Token
2122
outputToken: Token

src/components/swap/index.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { useDebounce } from 'use-debounce'
77
import { tradeMachineAtom } from '@/app/store/trade-machine'
88
import { SmartTradeButton } from '@/components/smart-trade-button'
99
import { SwapNavigation } from '@/components/swap/components/navigation'
10-
import { ARBITRUM, BASE, MAINNET } from '@/constants/chains'
11-
import { Token } from '@/constants/tokens'
10+
import { ARBITRUM, MAINNET } from '@/constants/chains'
1211
import { useBestQuote } from '@/lib/hooks/use-best-quote'
1312
import { QuoteType } from '@/lib/hooks/use-best-quote/types'
1413
import { useDisclosure } from '@/lib/hooks/use-disclosure'
@@ -27,14 +26,16 @@ import { getTokenBySymbol } from '@/lib/utils/tokens'
2726
import { SelectTokenModal } from './components/select-token-modal'
2827
import { TradeDetails } from './components/trade-details'
2928
import {
30-
InputSelectorToken,
29+
type InputSelectorToken,
3130
TradeInputSelector,
3231
} from './components/trade-input-selector'
3332
import { TradeOutput } from './components/trade-output'
3433
import { TransactionReviewModal } from './components/transaction-review'
3534
import { useSwap } from './hooks/use-swap'
3635
import { useTokenlists } from './hooks/use-tokenlists'
3736

37+
import type { Token } from '@/constants/tokens'
38+
3839
type SwapProps = {
3940
isBuying: boolean
4041
inputToken: Token
@@ -47,7 +48,6 @@ export const Swap = (props: SwapProps) => {
4748
const isSupportedNetwork = useSupportedNetworks([
4849
MAINNET.chainId,
4950
ARBITRUM.chainId,
50-
BASE.chainId,
5151
])
5252
const { chainId } = useNetwork()
5353
const { slippage } = useSlippage()
@@ -119,6 +119,16 @@ export const Swap = (props: SwapProps) => {
119119
setSelectedQuote(quoteResults?.bestQuote)
120120
}, [quoteResults])
121121

122+
useEffect(() => {
123+
const quote = quoteResults?.results[selectedQuote ?? QuoteType.index]
124+
if (!quote) return
125+
sendTradeEvent({
126+
type: 'QUOTE',
127+
quoteResult: quote,
128+
quoteType: quote.type,
129+
})
130+
}, [quoteResults, selectedQuote, sendTradeEvent])
131+
122132
const resetTradeData = useCallback(() => {
123133
setInputTokenAmountFormatted('')
124134
setSellTokenAmount('0')

src/lib/hooks/use-best-quote/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useCallback, useEffect, useMemo, useState } from 'react'
22
import { usePublicClient } from 'wagmi'
33

44
import { ARBITRUM } from '@/constants/chains'
5-
import { Token } from '@/constants/tokens'
65
import {
76
isAvailableForFlashMint,
87
isAvailableForSwap,
@@ -15,11 +14,18 @@ import { getAddressForToken } from '@/lib/utils/tokens'
1514
import { formatQuoteAnalytics, useAnalytics } from '../use-analytics'
1615
import { getTokenPrice, useNativeTokenPrice } from '../use-token-price'
1716

18-
import { Quote, QuoteResults, QuoteType, ZeroExQuote } from './types'
17+
import {
18+
type Quote,
19+
type QuoteResults,
20+
QuoteType,
21+
type ZeroExQuote,
22+
} from './types'
1923
import { getBestQuote } from './utils/best-quote'
2024
import { getFlashMintQuote } from './utils/flashmint'
2125
import { getIndexQuote } from './utils/index-quote'
2226

27+
import type { Token } from '@/constants/tokens'
28+
2329
export interface FetchQuoteRequest {
2430
isMinting: boolean
2531
inputToken: Token

src/lib/hooks/use-quote-result/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { useEffect, useState } from 'react'
44
import { usePublicClient } from 'wagmi'
55

66
import { tradeMachineAtom } from '@/app/store/trade-machine'
7-
import { Token } from '@/constants/tokens'
87
import { formatQuoteAnalytics, useAnalytics } from '@/lib/hooks/use-analytics'
9-
import { QuoteResult, QuoteType } from '@/lib/hooks/use-best-quote/types'
8+
import { type QuoteResult, QuoteType } from '@/lib/hooks/use-best-quote/types'
109
import { getFlashMintQuote } from '@/lib/hooks/use-best-quote/utils/flashmint'
1110
import { getIndexQuote } from '@/lib/hooks/use-best-quote/utils/index-quote'
1211
import { getBestYieldQuote } from '@/lib/hooks/use-quote-result/best-quote'
1312
import { getTokenPrice, useNativeTokenPrice } from '@/lib/hooks/use-token-price'
1413

14+
import type { Token } from '@/constants/tokens'
15+
1516
type QuoteRequest = {
1617
address: string | undefined
1718
chainId: number

0 commit comments

Comments
 (0)