Skip to content

Commit 5f58be5

Browse files
committed
fix(miles): header reads payouts directly so it leads the leaderboard
Settlement should drive: header updates first, then leaderboard. The per-user /payouts/totals/{address} endpoint reflects Fuul's indexed total as soon as the credit lands; their leaderboard data is computed on a slower cadence. Drop the leaderboard-entry override on the badge so it tracks payouts directly. Leaderboard tables still refresh on the same refetch-user-miles event and converge to the same value.
1 parent 24ed25f commit 5f58be5

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

src/hooks/use-user-points.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { useState, useEffect, useCallback, useRef } from "react"
22
import { useAccount } from "wagmi"
3-
import {
4-
useFuulMilesLeaderboard,
5-
findUserMilesEntry,
6-
} from "@/hooks/use-fuul-miles-leaderboard"
73
import { REFETCH_MILES_EVENT, refetchMiles } from "@/lib/miles-events"
84
import { getPendingSwapHashes, subscribeSwapSubmitted } from "@/lib/swap-events"
95

@@ -24,11 +20,11 @@ export function useUserPoints(): UseUserPointsReturn {
2420
const [payoutPoints, setPayoutPoints] = useState(0)
2521
const [isLoading, setIsLoading] = useState(false)
2622

27-
// Subscribe to the shared Fuul miles leaderboard so the header value
28-
// always matches the user's row on the leaderboard. The leaderboard
29-
// hook also refetches itself on REFETCH_MILES_EVENT.
30-
const { data: milesData, isLoading: isMilesLoading } = useFuulMilesLeaderboard()
31-
const leaderboardEntry = findUserMilesEntry(milesData, address)
23+
// The header reads from /payouts/totals/{address}, the per-user Fuul
24+
// endpoint that updates as soon as Fuul indexes the settlement. The
25+
// leaderboard data is computed on a slower cadence by Fuul, so we let
26+
// the badge update first and the leaderboard table catch up afterward
27+
// (both share refetch-user-miles, so they refresh in the same cycle).
3228

3329
const fetchPoints = useCallback((addr: string) => {
3430
let cancelled = false
@@ -76,7 +72,7 @@ export function useUserPoints(): UseUserPointsReturn {
7672

7773
// Track the latest points value so the post-swap poller can detect a
7874
// change without re-subscribing on every render.
79-
const points = leaderboardEntry ? leaderboardEntry.points : payoutPoints
75+
const points = payoutPoints
8076
const latestPointsRef = useRef(points)
8177
useEffect(() => {
8278
latestPointsRef.current = points
@@ -132,5 +128,5 @@ export function useUserPoints(): UseUserPointsReturn {
132128
}
133129
}, [address, startPolling, stopPolling])
134130

135-
return { points, isLoading: isLoading || isMilesLoading }
131+
return { points, isLoading }
136132
}

0 commit comments

Comments
 (0)