diff --git a/src/components/transactions/Swap/actions/CollateralSwap/CollateralSwapActionsViaParaswapAdapters.tsx b/src/components/transactions/Swap/actions/CollateralSwap/CollateralSwapActionsViaParaswapAdapters.tsx index d532555929..958e435464 100644 --- a/src/components/transactions/Swap/actions/CollateralSwap/CollateralSwapActionsViaParaswapAdapters.tsx +++ b/src/components/transactions/Swap/actions/CollateralSwap/CollateralSwapActionsViaParaswapAdapters.tsx @@ -228,6 +228,7 @@ export const CollateralSwapActionsViaParaswapAdapters = ({ ], error: undefined, // Clear any existing errors }); + trackingHandlers.trackGasEstimationError(error); } else { // For other errors, handle normally setTxError(parsedError); @@ -239,14 +240,13 @@ export const CollateralSwapActionsViaParaswapAdapters = ({ actionBlocked: parsedError.actionBlocked, }, }); + const reason = error instanceof Error ? error.message : 'Swap failed'; + trackingHandlers.trackSwapFailed(reason); } setMainTxState({ loading: false, }); - - const reason = error instanceof Error ? error.message : 'Swap failed'; - trackingHandlers.trackSwapFailed(reason); } }; diff --git a/src/components/transactions/Swap/actions/DebtSwap/DebtSwapActionsViaParaswap.tsx b/src/components/transactions/Swap/actions/DebtSwap/DebtSwapActionsViaParaswap.tsx index 951fab2e26..6c60b968dc 100644 --- a/src/components/transactions/Swap/actions/DebtSwap/DebtSwapActionsViaParaswap.tsx +++ b/src/components/transactions/Swap/actions/DebtSwap/DebtSwapActionsViaParaswap.tsx @@ -212,21 +212,22 @@ export const DebtSwapActionsViaParaswap = ({ ], error: undefined, // Clear any existing errors }); + trackingHandlers.trackGasEstimationError(error); } else { // For other errors, handle normally setTxError(parsedError); setState({ actionsLoading: false, }); + + const reason = error instanceof Error ? error.message : 'Swap failed'; + trackingHandlers.trackSwapFailed(reason); } setMainTxState({ txHash: undefined, loading: false, }); - - const reason = error instanceof Error ? error.message : 'Swap failed'; - trackingHandlers.trackSwapFailed(reason); } }; diff --git a/src/components/transactions/Swap/actions/RepayWithCollateral/RepayWithCollateralActionsViaParaswap.tsx b/src/components/transactions/Swap/actions/RepayWithCollateral/RepayWithCollateralActionsViaParaswap.tsx index 3f0d8bce67..d8b6625dec 100644 --- a/src/components/transactions/Swap/actions/RepayWithCollateral/RepayWithCollateralActionsViaParaswap.tsx +++ b/src/components/transactions/Swap/actions/RepayWithCollateral/RepayWithCollateralActionsViaParaswap.tsx @@ -249,20 +249,20 @@ export const RepayWithCollateralActionsViaParaswap = ({ ], error: undefined, // Clear any existing errors }); + trackingHandlers.trackGasEstimationError(error); } else { // For other errors, handle normally setTxError(parsedError); setState({ actionsLoading: false, }); + const reason = error instanceof Error ? error.message : undefined; + trackingHandlers.trackSwapFailed(reason); } setMainTxState({ loading: false, }); - - const reason = error instanceof Error ? error.message : undefined; - trackingHandlers.trackSwapFailed(reason); } }; diff --git a/src/components/transactions/Swap/actions/SwapActions/SwapActionsViaParaswap.tsx b/src/components/transactions/Swap/actions/SwapActions/SwapActionsViaParaswap.tsx index f218f1f583..e8b9f258ee 100644 --- a/src/components/transactions/Swap/actions/SwapActions/SwapActionsViaParaswap.tsx +++ b/src/components/transactions/Swap/actions/SwapActions/SwapActionsViaParaswap.tsx @@ -187,21 +187,21 @@ export const SwapActionsViaParaswap = ({ ], error: undefined, // Clear any existing errors }); + trackingHandlers.trackGasEstimationError(error); } else { // For other errors, handle normally setTxError(parsedError); setState({ actionsLoading: false, }); + const reason = error instanceof Error ? error.message : 'Swap failed'; + trackingHandlers.trackSwapFailed(reason); } setMainTxState({ txHash: undefined, loading: false, }); - - const reason = error instanceof Error ? error.message : 'Swap failed'; - trackingHandlers.trackSwapFailed(reason); } } else { setTxError( diff --git a/src/components/transactions/Swap/actions/WithdrawAndSwap/WithdrawAndSwapActionsViaParaswap.tsx b/src/components/transactions/Swap/actions/WithdrawAndSwap/WithdrawAndSwapActionsViaParaswap.tsx index 04ace480a6..df69e53bad 100644 --- a/src/components/transactions/Swap/actions/WithdrawAndSwap/WithdrawAndSwapActionsViaParaswap.tsx +++ b/src/components/transactions/Swap/actions/WithdrawAndSwap/WithdrawAndSwapActionsViaParaswap.tsx @@ -169,20 +169,21 @@ export const WithdrawAndSwapActionsViaParaswap = ({ ], error: undefined, // Clear any existing errors }); + trackingHandlers.trackGasEstimationError(error); } else { // For other errors, handle normally setTxError(parsedError); setState({ actionsLoading: false, }); + const reason = error instanceof Error ? error.message : undefined; + trackingHandlers.trackSwapFailed(reason); } setMainTxState({ txHash: undefined, loading: false, }); - const reason = error instanceof Error ? error.message : undefined; - trackingHandlers.trackSwapFailed(reason); } }; diff --git a/src/components/transactions/Swap/analytics/state.helpers.ts b/src/components/transactions/Swap/analytics/state.helpers.ts index 1479685163..3558b8426c 100644 --- a/src/components/transactions/Swap/analytics/state.helpers.ts +++ b/src/components/transactions/Swap/analytics/state.helpers.ts @@ -135,3 +135,12 @@ export const swapUserDeniedToAnalyticsEventParams = (state: SwapState): TrackEve ...swapStateToAnalyticsEventParams(state), }; }; + +export const swapTrackGasEstimationErrorToAnalyticsEventParams = ( + state: SwapState +): TrackEventProperties => { + return { + ...swapStateToAnalyticsEventParams(state), + errorMessage: 'Gas estimation error', + }; +}; diff --git a/src/components/transactions/Swap/analytics/useTrackAnalytics.ts b/src/components/transactions/Swap/analytics/useTrackAnalytics.ts index 487b641180..a7531cccf8 100644 --- a/src/components/transactions/Swap/analytics/useTrackAnalytics.ts +++ b/src/components/transactions/Swap/analytics/useTrackAnalytics.ts @@ -7,6 +7,7 @@ import { swapInputChangeToAnalyticsEventParams, swapQuoteToAnalyticsEventParams, swapTrackApprovalToAnalyticsEventParams, + swapTrackGasEstimationErrorToAnalyticsEventParams, swapTrackSwapFailedToAnalyticsEventParams, swapTrackSwapFilledToAnalyticsEventParams, swapTrackSwapToAnalyticsEventParams, @@ -22,6 +23,7 @@ export type TrackAnalyticsHandlers = { trackSwap: () => void; trackSwapFilled: (executedSellAmount: string, executedBuyAmount: string) => void; trackSwapFailed: (reason?: string) => void; + trackGasEstimationError: (error: SwapError) => void; }; /* @@ -59,5 +61,10 @@ export const useHandleAnalytics = ({ state }: { state: SwapState }) => { ), trackSwapFailed: (reason?: string) => trackEvent(SWAP.SWAP_FAILED, swapTrackSwapFailedToAnalyticsEventParams(state, reason)), + trackGasEstimationError: () => + trackEvent( + SWAP.GAS_ESTIMATION_ERROR, + swapTrackGasEstimationErrorToAnalyticsEventParams(state) + ), }; }; diff --git a/src/components/transactions/Swap/details/CowCostsDetails.tsx b/src/components/transactions/Swap/details/CowCostsDetails.tsx index 4b4e35c827..a04d52d784 100644 --- a/src/components/transactions/Swap/details/CowCostsDetails.tsx +++ b/src/components/transactions/Swap/details/CowCostsDetails.tsx @@ -37,6 +37,7 @@ export const CowCostsDetails = ({ state }: { state: SwapState }) => { .toNumber(); const flashloanFeeUsd = Number(flashloanFeeFormatted) * flashLoanFeeTokenPriceUnitUsd; const flashloanFeeToken = state.sellAmountToken; + const isFlashloanUsed = state.useFlashloan; if (!state.buyAmountToken || !state.sellAmountToken) return null; @@ -74,7 +75,8 @@ export const CowCostsDetails = ({ state }: { state: SwapState }) => { partnerFeeToken = state.buyAmountToken; } - const totalCostsInUsd = networkFeeUsd + partnerFeeUsd + (flashloanFeeUsd ?? 0); // + costs.slippageInUsd; + const totalCostsInUsd = + networkFeeUsd + partnerFeeUsd + (isFlashloanUsed ? flashloanFeeUsd ?? 0 : 0); // + costs.slippageInUsd; return ( { /> - {!!(flashloanFeeFormatted && flashloanFeeToken && flashloanFeeUsd) && ( + {!!(flashloanFeeFormatted && flashloanFeeToken && flashloanFeeUsd && isFlashloanUsed) && ( - {!state.actionsBlocked[ActionsBlockedReason.LOW_HEALTH_FACTOR] && ( + {!state.actionsBlocked[ActionsBlockedReason.IS_LIQUIDATABLE] && (