1- import { ChainId } from '@aave/contract-helpers' ;
1+ import { ChainId , ProtocolAction } from '@aave/contract-helpers' ;
22import { normalize , UserIncentiveData } from '@aave/math-utils' ;
33import { useMeritClaimRewards } from '@aave/react' ;
44import { Trans } from '@lingui/macro' ;
55import { Box , Typography } from '@mui/material' ;
6- import { useEffect , useState } from 'react' ;
6+ import { useEffect , useRef , useState } from 'react' ;
77import { FormattedNumber } from 'src/components/primitives/FormattedNumber' ;
88import { Row } from 'src/components/primitives/Row' ;
99import { TokenIcon } from 'src/components/primitives/TokenIcon' ;
@@ -15,6 +15,7 @@ import {
1515import { useModalContext } from 'src/hooks/useModal' ;
1616import { useWeb3Context } from 'src/libs/hooks/useWeb3Context' ;
1717import { useRootStore } from 'src/store/root' ;
18+ import { REWARDS } from 'src/utils/events' ;
1819import { getNetworkConfig } from 'src/utils/marketsAndNetworksConfig' ;
1920import { useShallow } from 'zustand/shallow' ;
2021
@@ -42,8 +43,8 @@ interface ClaimRewardsModalContentProps {
4243
4344export const ClaimRewardsModalContent = ( { user, reserves } : ClaimRewardsModalContentProps ) => {
4445 const { gasLimit, mainTxState : claimRewardsTxState , txError } = useModalContext ( ) ;
45- const [ currentChainId , currentMarketData ] = useRootStore (
46- useShallow ( ( store ) => [ store . currentChainId , store . currentMarketData ] )
46+ const [ currentChainId , currentMarketData , trackEvent ] = useRootStore (
47+ useShallow ( ( store ) => [ store . currentChainId , store . currentMarketData , store . trackEvent ] )
4748 ) ;
4849 const { chainId : connectedChainId , readOnlyModeAddress, currentAccount } = useWeb3Context ( ) ;
4950 const [ claimableUsd , setClaimableUsd ] = useState ( '0' ) ;
@@ -259,6 +260,81 @@ export const ClaimRewardsModalContent = ({ user, reserves }: ClaimRewardsModalCo
259260 : rewards . find ( ( r ) => r . symbol === selectedRewardSymbol ) ||
260261 meritRewardsForSelect . find ( ( r ) => r . symbol === selectedRewardSymbol ) ;
261262
263+ // Track analytics when claim transaction succeeds
264+ const hasTrackedRef = useRef ( false ) ;
265+
266+ // Reset tracking flag when starting a new transaction
267+ useEffect ( ( ) => {
268+ if ( ! claimRewardsTxState . success ) {
269+ hasTrackedRef . current = false ;
270+ }
271+ } , [ claimRewardsTxState . success ] ) ;
272+
273+ useEffect ( ( ) => {
274+ if ( claimRewardsTxState . success && selectedReward && ! hasTrackedRef . current ) {
275+ hasTrackedRef . current = true ;
276+
277+ const networkConfig = getNetworkConfig ( currentChainId ) ;
278+
279+ let eventName : string ;
280+ const baseEventProps = {
281+ chainId : currentChainId ,
282+ chainName : networkConfig . displayName || networkConfig . name ,
283+ totalClaimableUsd : claimableUsd ,
284+ txHash : claimRewardsTxState . txHash ,
285+ market : currentMarketData . market ,
286+ transactiontype : ProtocolAction . claimRewards ,
287+ } ;
288+
289+ // Determine event type and specific properties based on claim type
290+ if ( selectedRewardSymbol === 'all' ) {
291+ eventName = REWARDS . CLAIM_ALL_REWARDS ;
292+ const protocolRewardsCount = rewards . length ;
293+ const meritRewardsCount = meritClaimRewards ?. rewards ?. length || 0 ;
294+
295+ trackEvent ( eventName , {
296+ ...baseEventProps ,
297+ claimType : 'all' ,
298+ protocolRewardsCount,
299+ meritRewardsCount,
300+ totalRewardsCount : protocolRewardsCount + meritRewardsCount ,
301+ } ) ;
302+ } else if (
303+ selectedRewardSymbol === 'merit-all' ||
304+ selectedRewardSymbol . startsWith ( 'merit-display-' )
305+ ) {
306+ eventName = REWARDS . CLAIM_MERIT_REWARDS ;
307+
308+ trackEvent ( eventName , {
309+ ...baseEventProps ,
310+ claimType : 'merit-all' ,
311+ meritRewardsCount : meritClaimRewards ?. rewards ?. length || 0 ,
312+ claimableUsd : selectedReward . balanceUsd ,
313+ } ) ;
314+ } else if ( selectedRewardSymbol === 'protocol-all' ) {
315+ eventName = REWARDS . CLAIM_PROTOCOL_REWARDS ;
316+
317+ trackEvent ( eventName , {
318+ ...baseEventProps ,
319+ claimType : 'protocol-all' ,
320+ protocolRewardsCount : rewards . length ,
321+ claimableUsd : selectedReward . balanceUsd ,
322+ } ) ;
323+ } else {
324+ eventName = REWARDS . CLAIM_INDIVIDUAL_REWARD ;
325+
326+ trackEvent ( eventName , {
327+ ...baseEventProps ,
328+ claimType : 'individual' ,
329+ rewardSymbol : selectedReward . symbol ,
330+ rewardBalance : selectedReward . balance ,
331+ claimableUsd : selectedReward . balanceUsd ,
332+ rewardTokenAddress : selectedReward . rewardTokenAddress ,
333+ } ) ;
334+ }
335+ }
336+ } , [ claimRewardsTxState . success ] ) ;
337+
262338 if ( txError && txError . blocking ) {
263339 return < TxErrorView txError = { txError } /> ;
264340 }
0 commit comments