Commit 6424fdfb authored by Tina's avatar Tina Committed by GitHub

fix: Simplify event logging for SWAP_QUOTE_RECEIVED (#6628)

* simplify event logging

* remove unused function parameter
parent 95814e32
......@@ -61,8 +61,7 @@ export const formatSwapSignedAnalyticsEventProperties = ({
export const formatSwapQuoteReceivedEventProperties = (
trade: Trade<Currency, Currency, TradeType>,
gasUseEstimateUSD?: string,
fetchingSwapQuoteStartTime?: Date
gasUseEstimateUSD?: string
) => {
return {
token_in_symbol: trade.inputAmount.currency.symbol,
......@@ -77,8 +76,5 @@ export const formatSwapQuoteReceivedEventProperties = (
: undefined,
token_in_amount: formatToDecimal(trade.inputAmount, trade.inputAmount.currency.decimals),
token_out_amount: formatToDecimal(trade.outputAmount, trade.outputAmount.currency.decimals),
quote_latency_milliseconds: fetchingSwapQuoteStartTime
? getDurationFromDateMilliseconds(fetchingSwapQuoteStartTime)
: undefined,
}
}
......@@ -177,8 +177,6 @@ export function Swap({
disableTokenInputs?: boolean
}) {
const { account, chainId: connectedChainId, connector } = useWeb3React()
const [newSwapQuoteNeedsLogging, setNewSwapQuoteNeedsLogging] = useState(true)
const [fetchingSwapQuoteStartTime, setFetchingSwapQuoteStartTime] = useState<Date | undefined>()
const trace = useTrace()
// token warning stuff
......@@ -526,42 +524,16 @@ export function Swap({
const priceImpactTooHigh = priceImpactSeverity > 3 && !isExpertMode
const showPriceImpactWarning = largerPriceImpact && priceImpactSeverity > 3
// Handle time based logging events and event properties.
const prevTrade = usePrevious(trade)
useEffect(() => {
const now = new Date()
// If a trade exists, and we need to log the receipt of this new swap quote:
if (newSwapQuoteNeedsLogging && !!trade) {
// Set the current datetime as the time of receipt of latest swap quote.
setSwapQuoteReceivedDate(now)
// Log swap quote.
if (!trade || prevTrade === trade) return // no new swap quote to log
setSwapQuoteReceivedDate(new Date())
sendAnalyticsEvent(SwapEventName.SWAP_QUOTE_RECEIVED, {
...formatSwapQuoteReceivedEventProperties(
trade,
trade.gasUseEstimateUSD ?? undefined,
fetchingSwapQuoteStartTime
),
...formatSwapQuoteReceivedEventProperties(trade, trade.gasUseEstimateUSD ?? undefined),
...trace,
})
// Latest swap quote has just been logged, so we don't need to log the current trade anymore
// unless user inputs change again and a new trade is in the process of being generated.
setNewSwapQuoteNeedsLogging(false)
// New quote is not being fetched, so set start time of quote fetch to undefined.
setFetchingSwapQuoteStartTime(undefined)
}
// If another swap quote is being loaded based on changed user inputs:
if (routeIsLoading) {
setNewSwapQuoteNeedsLogging(true)
if (!fetchingSwapQuoteStartTime) setFetchingSwapQuoteStartTime(now)
}
}, [
newSwapQuoteNeedsLogging,
routeIsSyncing,
routeIsLoading,
fetchingSwapQuoteStartTime,
trade,
setSwapQuoteReceivedDate,
trace,
])
}, [prevTrade, trade, trace])
const showDetailsDropdown = Boolean(
!showWrap && userHasSpecifiedInputOutput && (trade || routeIsLoading || routeIsSyncing)
......
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