diff --git a/packages/common/src/api/index.ts b/packages/common/src/api/index.ts index 1425d427b33..abb83a28d15 100644 --- a/packages/common/src/api/index.ts +++ b/packages/common/src/api/index.ts @@ -180,6 +180,7 @@ export * from './tan-query/wallets/useWalletSolBalance' export * from './tan-query/jupiter/useSwapTokens' export * from './tan-query/jupiter/useTokenExchangeRate' export * from './tan-query/jupiter/utils' +export * from './tan-query/jupiter/types' // Saga fetch utils, remove when migration is complete export * from './tan-query/saga-utils' diff --git a/packages/mobile/src/screens/buy-sell-screen/ConfirmSwapScreen.tsx b/packages/mobile/src/screens/buy-sell-screen/ConfirmSwapScreen.tsx index 83e2177c816..5c294a4accc 100644 --- a/packages/mobile/src/screens/buy-sell-screen/ConfirmSwapScreen.tsx +++ b/packages/mobile/src/screens/buy-sell-screen/ConfirmSwapScreen.tsx @@ -1,6 +1,6 @@ import { useCallback, useEffect, useMemo } from 'react' -import { SLIPPAGE_BPS } from '@audius/common/api' +import { SLIPPAGE_BPS, SwapStatus } from '@audius/common/api' import { useBuySellAnalytics } from '@audius/common/hooks' import { buySellMessages as baseMessages } from '@audius/common/messages' import type { TokenInfo, TokenPair } from '@audius/common/store' @@ -28,6 +28,7 @@ import { ScreenContent } from 'app/components/core' import { useNavigation } from 'app/hooks/useNavigation' +import { useToast } from 'app/hooks/useToast' import { SwapBalanceSection } from '../../components/buy-sell' @@ -90,6 +91,7 @@ const LoadingScreen = () => ( export const ConfirmSwapScreen = ({ route }: ConfirmSwapScreenProps) => { const navigation = useNavigation() + const { toast } = useToast() const { trackSwapConfirmed, trackSwapSuccess, trackSwapFailure } = useBuySellAnalytics() @@ -135,7 +137,8 @@ export const ConfirmSwapScreen = ({ route }: ConfirmSwapScreenProps) => { isConfirmButtonLoading, swapStatus, swapError, - swapResult + swapResult, + swapData } = useBuySellSwap({ transactionData, currentScreen, @@ -191,9 +194,13 @@ export const ConfirmSwapScreen = ({ route }: ConfirmSwapScreenProps) => { trackSwapSuccess ]) - // Handle swap error + // Handle swap data errors (when swap returns error status) - navigate back and show toast useEffect(() => { - if (swapStatus === 'error' && swapError) { + if ( + (swapData?.status === SwapStatus.ERROR && swapData?.error) || + swapStatus === 'error' || + swapError + ) { trackSwapFailure( { activeTab, @@ -206,29 +213,30 @@ export const ConfirmSwapScreen = ({ route }: ConfirmSwapScreenProps) => { { errorType: 'swap_error', errorStage: 'transaction', - errorMessage: swapError?.message - ? swapError.message.substring(0, 500) + errorMessage: swapData?.error?.message + ? swapData?.error?.message.substring(0, 500) : 'Unknown error' } ) - navigation.navigate('TransactionResultScreen', { - result: { - status: 'error' as const, - error: swapError - } - }) + // Navigate back to input screen (matching web behavior) + navigation.navigate('BuySellMain') + + // Show toast notification + toast({ content: messages.transactionFailed, type: 'error' }) } }, [ - swapStatus, - swapError, - navigation, + swapData, activeTab, + swapTokens, payAmount, receiveAmount, - swapTokens, exchangeRate, - trackSwapFailure + trackSwapFailure, + navigation, + toast, + swapStatus, + swapError ]) // balance isn't needed so we pass 0 diff --git a/packages/web/src/components/buy-sell-modal/BuySellFlow.tsx b/packages/web/src/components/buy-sell-modal/BuySellFlow.tsx index 9c01e83e707..1120e5e7ae2 100644 --- a/packages/web/src/components/buy-sell-modal/BuySellFlow.tsx +++ b/packages/web/src/components/buy-sell-modal/BuySellFlow.tsx @@ -7,11 +7,15 @@ import { useState } from 'react' -import { useArtistCoin, useTokenPair, useTokens } from '@audius/common/api' +import { + SwapStatus, + useArtistCoin, + useTokenPair, + useTokens +} from '@audius/common/api' import { useBuySellAnalytics, useOwnedTokens } from '@audius/common/hooks' import { buySellMessages as messages } from '@audius/common/messages' import { FeatureFlags } from '@audius/common/services' -import { SwapStatus } from '@audius/common/src/api/tan-query/jupiter/types' import { ASSET_DETAIL_PAGE } from '@audius/common/src/utils/route' import { BuySellTab,