Commit 77a6d158 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: imperatively send SwapSigned (#5207)

parent 28be15ef
import { Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { sendAnalyticsEvent, Trace } from '@uniswap/analytics' import { Trace } from '@uniswap/analytics'
import { EventName, ModalName } from '@uniswap/analytics-events' import { ModalName } from '@uniswap/analytics-events'
import { Trade } from '@uniswap/router-sdk' import { Trade } from '@uniswap/router-sdk'
import { Currency, CurrencyAmount, Percent, Token, TradeType } from '@uniswap/sdk-core' import { Currency, CurrencyAmount, Percent, Token, TradeType } from '@uniswap/sdk-core'
import { formatSwapSignedAnalyticsEventProperties } from 'lib/utils/analytics' import { ReactNode, useCallback, useMemo, useState } from 'react'
import { ReactNode, useCallback, useEffect, useMemo, useState } from 'react'
import { InterfaceTrade } from 'state/routing/types' import { InterfaceTrade } from 'state/routing/types'
import { tradeMeaningfullyDiffers } from 'utils/tradeMeaningFullyDiffer' import { tradeMeaningfullyDiffers } from 'utils/tradeMeaningFullyDiffer'
...@@ -49,7 +48,6 @@ export default function ConfirmSwapModal({ ...@@ -49,7 +48,6 @@ export default function ConfirmSwapModal({
// shouldLogModalCloseEvent lets the child SwapModalHeader component know when modal has been closed // shouldLogModalCloseEvent lets the child SwapModalHeader component know when modal has been closed
// and an event triggered by modal closing should be logged. // and an event triggered by modal closing should be logged.
const [shouldLogModalCloseEvent, setShouldLogModalCloseEvent] = useState(false) const [shouldLogModalCloseEvent, setShouldLogModalCloseEvent] = useState(false)
const [lastTxnHashLogged, setLastTxnHashLogged] = useState<string | null>(null)
const showAcceptChanges = useMemo( const showAcceptChanges = useMemo(
() => Boolean(trade && originalTrade && tradeMeaningfullyDiffers(trade, originalTrade)), () => Boolean(trade && originalTrade && tradeMeaningfullyDiffers(trade, originalTrade)),
[originalTrade, trade] [originalTrade, trade]
...@@ -123,13 +121,6 @@ export default function ConfirmSwapModal({ ...@@ -123,13 +121,6 @@ export default function ConfirmSwapModal({
[onModalDismiss, modalBottom, modalHeader, swapErrorMessage] [onModalDismiss, modalBottom, modalHeader, swapErrorMessage]
) )
useEffect(() => {
if (!attemptingTxn && isOpen && txHash && trade && txHash !== lastTxnHashLogged) {
sendAnalyticsEvent(EventName.SWAP_SIGNED, formatSwapSignedAnalyticsEventProperties({ trade, txHash }))
setLastTxnHashLogged(txHash)
}
}, [attemptingTxn, isOpen, txHash, trade, lastTxnHashLogged])
return ( return (
<Trace modal={ModalName.CONFIRM_SWAP}> <Trace modal={ModalName.CONFIRM_SWAP}>
<TransactionConfirmationModal <TransactionConfirmationModal
......
// eslint-disable-next-line no-restricted-imports // eslint-disable-next-line no-restricted-imports
import { sendAnalyticsEvent } from '@uniswap/analytics'
import { EventName } from '@uniswap/analytics-events'
import { Trade } from '@uniswap/router-sdk' import { Trade } from '@uniswap/router-sdk'
import { Currency, Percent, TradeType } from '@uniswap/sdk-core' import { Currency, Percent, TradeType } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core' import { useWeb3React } from '@web3-react/core'
import { SwapCallbackState, useSwapCallback as useLibSwapCallBack } from 'lib/hooks/swap/useSwapCallback' import { SwapCallbackState, useSwapCallback as useLibSwapCallBack } from 'lib/hooks/swap/useSwapCallback'
import { formatSwapSignedAnalyticsEventProperties } from 'lib/utils/analytics'
import { ReactNode, useMemo } from 'react' import { ReactNode, useMemo } from 'react'
import { useTransactionAdder } from '../state/transactions/hooks' import { useTransactionAdder } from '../state/transactions/hooks'
...@@ -47,6 +50,10 @@ export function useSwapCallback( ...@@ -47,6 +50,10 @@ export function useSwapCallback(
} }
return () => return () =>
libCallback().then((response) => { libCallback().then((response) => {
sendAnalyticsEvent(
EventName.SWAP_SIGNED,
formatSwapSignedAnalyticsEventProperties({ trade, txHash: response.hash })
)
addTransaction( addTransaction(
response, response,
trade.tradeType === TradeType.EXACT_INPUT trade.tradeType === TradeType.EXACT_INPUT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment