From 4dfb467f4a5886e33e1716c904066fdc298bc46d Mon Sep 17 00:00:00 2001 From: Apotheosis <0xapotheosis@gmail.com> Date: Mon, 31 Jul 2023 13:35:38 +1000 Subject: [PATCH] fix: only fire fail/success events once (#5002) --- .../components/TradeConfirm/TradeConfirm.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/MultiHopTrade/components/TradeConfirm/TradeConfirm.tsx b/src/components/MultiHopTrade/components/TradeConfirm/TradeConfirm.tsx index a5a637eccbe..a618cc8afe0 100644 --- a/src/components/MultiHopTrade/components/TradeConfirm/TradeConfirm.tsx +++ b/src/components/MultiHopTrade/components/TradeConfirm/TradeConfirm.tsx @@ -15,7 +15,7 @@ import { useColorModeValue, } from '@chakra-ui/react' import { TxStatus } from '@shapeshiftoss/unchained-client' -import { useCallback, useEffect, useMemo } from 'react' +import { useCallback, useEffect, useMemo, useState } from 'react' import { useFormContext } from 'react-hook-form' import { useTranslate } from 'react-polyglot' import { useHistory } from 'react-router-dom' @@ -72,6 +72,7 @@ export const TradeConfirm = () => { const borderColor = useColorModeValue('gray.100', 'gray.750') const alertColor = useColorModeValue('yellow.500', 'yellow.200') const warningColor = useColorModeValue('red.600', 'red.400') + const [hasMixpanelFired, setHasMixpanelFired] = useState(false) const { handleSubmit, formState: { isSubmitting }, @@ -155,14 +156,16 @@ export const TradeConfirm = () => { ) useEffect(() => { - if (!mixpanel || !eventData) return + if (!mixpanel || !eventData || hasMixpanelFired) return if (status === TxStatus.Confirmed) { mixpanel.track(MixPanelEvents.TradeSuccess, eventData) + setHasMixpanelFired(true) } if (status === TxStatus.Failed) { mixpanel.track(MixPanelEvents.TradeFailed, eventData) + setHasMixpanelFired(true) } - }, [eventData, mixpanel, status]) + }, [eventData, hasMixpanelFired, mixpanel, status]) const handleBack = useCallback(() => { if (sellTxHash) {