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 = ({ ...@@ -61,8 +61,7 @@ export const formatSwapSignedAnalyticsEventProperties = ({
export const formatSwapQuoteReceivedEventProperties = ( export const formatSwapQuoteReceivedEventProperties = (
trade: Trade<Currency, Currency, TradeType>, trade: Trade<Currency, Currency, TradeType>,
gasUseEstimateUSD?: string, gasUseEstimateUSD?: string
fetchingSwapQuoteStartTime?: Date
) => { ) => {
return { return {
token_in_symbol: trade.inputAmount.currency.symbol, token_in_symbol: trade.inputAmount.currency.symbol,
...@@ -77,8 +76,5 @@ export const formatSwapQuoteReceivedEventProperties = ( ...@@ -77,8 +76,5 @@ export const formatSwapQuoteReceivedEventProperties = (
: undefined, : undefined,
token_in_amount: formatToDecimal(trade.inputAmount, trade.inputAmount.currency.decimals), token_in_amount: formatToDecimal(trade.inputAmount, trade.inputAmount.currency.decimals),
token_out_amount: formatToDecimal(trade.outputAmount, trade.outputAmount.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({ ...@@ -177,8 +177,6 @@ export function Swap({
disableTokenInputs?: boolean disableTokenInputs?: boolean
}) { }) {
const { account, chainId: connectedChainId, connector } = useWeb3React() const { account, chainId: connectedChainId, connector } = useWeb3React()
const [newSwapQuoteNeedsLogging, setNewSwapQuoteNeedsLogging] = useState(true)
const [fetchingSwapQuoteStartTime, setFetchingSwapQuoteStartTime] = useState<Date | undefined>()
const trace = useTrace() const trace = useTrace()
// token warning stuff // token warning stuff
...@@ -526,42 +524,16 @@ export function Swap({ ...@@ -526,42 +524,16 @@ export function Swap({
const priceImpactTooHigh = priceImpactSeverity > 3 && !isExpertMode const priceImpactTooHigh = priceImpactSeverity > 3 && !isExpertMode
const showPriceImpactWarning = largerPriceImpact && priceImpactSeverity > 3 const showPriceImpactWarning = largerPriceImpact && priceImpactSeverity > 3
// Handle time based logging events and event properties. const prevTrade = usePrevious(trade)
useEffect(() => { useEffect(() => {
const now = new Date() if (!trade || prevTrade === trade) return // no new swap quote to log
// If a trade exists, and we need to log the receipt of this new swap quote:
if (newSwapQuoteNeedsLogging && !!trade) { setSwapQuoteReceivedDate(new Date())
// Set the current datetime as the time of receipt of latest swap quote. sendAnalyticsEvent(SwapEventName.SWAP_QUOTE_RECEIVED, {
setSwapQuoteReceivedDate(now) ...formatSwapQuoteReceivedEventProperties(trade, trade.gasUseEstimateUSD ?? undefined),
// Log swap quote. ...trace,
sendAnalyticsEvent(SwapEventName.SWAP_QUOTE_RECEIVED, { })
...formatSwapQuoteReceivedEventProperties( }, [prevTrade, trade, trace])
trade,
trade.gasUseEstimateUSD ?? undefined,
fetchingSwapQuoteStartTime
),
...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,
])
const showDetailsDropdown = Boolean( const showDetailsDropdown = Boolean(
!showWrap && userHasSpecifiedInputOutput && (trade || routeIsLoading || routeIsSyncing) !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