From b368a3e8348b676a8649e17508822f59281c3d82 Mon Sep 17 00:00:00 2001 From: Emily Drake Smith Date: Tue, 24 Mar 2026 18:45:25 -0400 Subject: [PATCH 1/3] fix invitee count --- .../affiliates/hooks/useAffiliateData.ts | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/packages/frontend/app/routes/affiliates/hooks/useAffiliateData.ts b/packages/frontend/app/routes/affiliates/hooks/useAffiliateData.ts index c55b38e15..4fb6475f7 100644 --- a/packages/frontend/app/routes/affiliates/hooks/useAffiliateData.ts +++ b/packages/frontend/app/routes/affiliates/hooks/useAffiliateData.ts @@ -232,6 +232,10 @@ export function useAffiliateInviteeCount( const inFlightRef = useRef(false); const hasLoadedOnceRef = useRef(false); + // Import and use useAffiliateCode hook to fetch the affiliate's actual referral code + const { data: affiliateCodeData, isLoading: isAffiliateCodeLoading } = + useAffiliateCode(walletAddress, enabled); + const fetchData = useCallback(async () => { if (!enabled || !walletAddress) return; if (inFlightRef.current) return; @@ -243,21 +247,43 @@ export function useAffiliateInviteeCount( setError(null); try { - const referralCodes = - await fetchAffiliateReferralCodes(walletAddress); + console.log( + 'useAffiliateInviteeCount: Starting fetch for wallet:', + walletAddress, + ); + console.log( + 'useAffiliateInviteeCount: Affiliate code data:', + affiliateCodeData, + ); + + // Use the affiliate code (affiliateCodeData?.code) instead of fetching from separate referral codes endpoint + const affiliateCode = affiliateCodeData?.code; - if (referralCodes.length === 0) { + if (!affiliateCode) { + console.log( + 'useAffiliateInviteeCount: No affiliate code found, setting count to 0', + ); setData(0); return; } + console.log( + 'useAffiliateInviteeCount: Using affiliate code:', + affiliateCode, + ); + const count = await fetchAttributedReferralCount({ referralKind: 1, - referralIdTexts: referralCodes, + referralIdTexts: [affiliateCode], }); + console.log('useAffiliateInviteeCount: Fetched count:', count); setData(count ?? 0); } catch (err) { + console.error( + 'useAffiliateInviteeCount: Error fetching count:', + err, + ); setError( err instanceof Error ? err @@ -268,11 +294,15 @@ export function useAffiliateInviteeCount( hasLoadedOnceRef.current = true; setIsLoading(false); } - }, [enabled, walletAddress]); + }, [enabled, walletAddress, affiliateCodeData?.code]); useEffect(() => { - if (!enabled || !walletAddress) return; + if (!enabled || !walletAddress || isAffiliateCodeLoading) return; + console.log( + 'useAffiliateInviteeCount: Setting up interval for wallet:', + walletAddress, + ); void fetchData(); const intervalId = window.setInterval(() => { void fetchData(); @@ -281,7 +311,7 @@ export function useAffiliateInviteeCount( return () => { window.clearInterval(intervalId); }; - }, [enabled, fetchData, walletAddress]); + }, [enabled, fetchData, walletAddress, isAffiliateCodeLoading]); useEffect(() => { window.addEventListener('affiliateDataUpdate', fetchData); From 062f3ebcc67e039606d2d01237f635727c6ddd88 Mon Sep 17 00:00:00 2001 From: Emily Drake Smith Date: Tue, 24 Mar 2026 18:46:02 -0400 Subject: [PATCH 2/3] remove logging --- .../affiliates/hooks/useAffiliateData.ts | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/packages/frontend/app/routes/affiliates/hooks/useAffiliateData.ts b/packages/frontend/app/routes/affiliates/hooks/useAffiliateData.ts index 4fb6475f7..5ac43a477 100644 --- a/packages/frontend/app/routes/affiliates/hooks/useAffiliateData.ts +++ b/packages/frontend/app/routes/affiliates/hooks/useAffiliateData.ts @@ -247,43 +247,21 @@ export function useAffiliateInviteeCount( setError(null); try { - console.log( - 'useAffiliateInviteeCount: Starting fetch for wallet:', - walletAddress, - ); - console.log( - 'useAffiliateInviteeCount: Affiliate code data:', - affiliateCodeData, - ); - // Use the affiliate code (affiliateCodeData?.code) instead of fetching from separate referral codes endpoint const affiliateCode = affiliateCodeData?.code; if (!affiliateCode) { - console.log( - 'useAffiliateInviteeCount: No affiliate code found, setting count to 0', - ); setData(0); return; } - console.log( - 'useAffiliateInviteeCount: Using affiliate code:', - affiliateCode, - ); - const count = await fetchAttributedReferralCount({ referralKind: 1, referralIdTexts: [affiliateCode], }); - console.log('useAffiliateInviteeCount: Fetched count:', count); setData(count ?? 0); } catch (err) { - console.error( - 'useAffiliateInviteeCount: Error fetching count:', - err, - ); setError( err instanceof Error ? err @@ -299,10 +277,6 @@ export function useAffiliateInviteeCount( useEffect(() => { if (!enabled || !walletAddress || isAffiliateCodeLoading) return; - console.log( - 'useAffiliateInviteeCount: Setting up interval for wallet:', - walletAddress, - ); void fetchData(); const intervalId = window.setInterval(() => { void fetchData(); From af083c290a28a51165ff8d09bef21778f66c5bba Mon Sep 17 00:00:00 2001 From: Emily Drake Smith Date: Wed, 25 Mar 2026 13:21:28 -0400 Subject: [PATCH 3/3] reduce `useEffect()` calls --- .../frontend/app/routes/affiliates/hooks/useAffiliateData.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/frontend/app/routes/affiliates/hooks/useAffiliateData.ts b/packages/frontend/app/routes/affiliates/hooks/useAffiliateData.ts index 5ac43a477..6c95640d5 100644 --- a/packages/frontend/app/routes/affiliates/hooks/useAffiliateData.ts +++ b/packages/frontend/app/routes/affiliates/hooks/useAffiliateData.ts @@ -142,7 +142,7 @@ export interface AffiliateStats { isRegistered: boolean; } -const INVITEE_COUNT_POLL_MS = 30_000; +const INVITEE_COUNT_POLL_MS = 120_000; // Hook for affiliate audience check export function useAffiliateAudience(userIdentifier: string, enabled = true) { @@ -272,7 +272,7 @@ export function useAffiliateInviteeCount( hasLoadedOnceRef.current = true; setIsLoading(false); } - }, [enabled, walletAddress, affiliateCodeData?.code]); + }, [enabled, walletAddress, affiliateCodeData]); useEffect(() => { if (!enabled || !walletAddress || isAffiliateCodeLoading) return;