Commit cbefbba0 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

feat: send analytics for swaps modified in-wallet (#5212)

* build: upgrade analytics-events

* feat: better swap analytics
parent 3acbcbc6
// 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 { Currency, Percent, TradeType } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { SwapCallbackState, useSwapCallback as useLibSwapCallBack } from 'lib/hooks/swap/useSwapCallback'
import { formatSwapSignedAnalyticsEventProperties } from 'lib/utils/analytics'
import { ReactNode, useMemo } from 'react'
import { useTransactionAdder } from '../state/transactions/hooks'
......@@ -50,10 +47,6 @@ export function useSwapCallback(
}
return () =>
libCallback().then((response) => {
sendAnalyticsEvent(
EventName.SWAP_SIGNED,
formatSwapSignedAnalyticsEventProperties({ trade, txHash: response.hash })
)
addTransaction(
response,
trade.tradeType === TradeType.EXACT_INPUT
......
......@@ -2,8 +2,11 @@ import { BigNumber } from '@ethersproject/bignumber'
import type { JsonRpcProvider, TransactionResponse } from '@ethersproject/providers'
// eslint-disable-next-line no-restricted-imports
import { t, Trans } from '@lingui/macro'
import { sendAnalyticsEvent } from '@uniswap/analytics'
import { EventName } from '@uniswap/analytics-events'
import { Trade } from '@uniswap/router-sdk'
import { Currency, TradeType } from '@uniswap/sdk-core'
import { formatSwapSignedAnalyticsEventProperties } from 'lib/utils/analytics'
import { useMemo } from 'react'
import { calculateGasMargin } from 'utils/calculateGasMargin'
import isZero from 'utils/isZero'
......@@ -116,7 +119,12 @@ export default function useSendSwapTransaction(
...(value && !isZero(value) ? { value } : {}),
})
.then((response) => {
sendAnalyticsEvent(
EventName.SWAP_SIGNED,
formatSwapSignedAnalyticsEventProperties({ trade, txHash: response.hash })
)
if (calldata !== response.data) {
sendAnalyticsEvent(EventName.SWAP_MODIFIED_IN_WALLET, { txHash: response.hash })
throw new InvalidSwapError(
t`Your swap was modified through your wallet. If this was a mistake, please cancel immediately or risk losing your funds.`
)
......
......@@ -4122,10 +4122,10 @@
"@typescript-eslint/types" "4.33.0"
eslint-visitor-keys "^2.0.0"
"@uniswap/analytics-events@1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@uniswap/analytics-events/-/analytics-events-1.0.4.tgz#9f1133ceaa295cd6c72f716e7218d82616a5f463"
integrity sha512-HvDwT5q0uSBF9CutMyyK+tvSCoASLNhax44AB9RkU7MJB5g/YGTSg9J5w1BXpA8R611fdsHNfUHnqMft1s/pfA==
"@uniswap/analytics-events@1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@uniswap/analytics-events/-/analytics-events-1.1.0.tgz#459236d86f864039c3931d21ba80f41575d2ce4e"
integrity sha512-ZJ99dLhJ4q2c0g0PoMxDPbeC010DrdIBLf7jnUsTf/hYm2LfHryr31Sv204xNO7rWVWHi1dk6jdab8DdBnHgPA==
"@uniswap/analytics@1.0.3":
version "1.0.3"
......
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