-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Description --- - cleaned up animation timeouts (couldn't repro the original issue but there was an issue of the animaions not actually going away which was reporoducable every time) - cleaned up the `useAirdropUserPointsListener` listener and how the zustand store was updated there: - biggest one being the check against the count from the payload vs the store - made sure to only update the store after - added triggers for the animations for very BASIC testing in the admin ui (not that helpful since it's not directly related to the points) Motivation and Context --- - resolves an issue picked up when checking #1238, but should also hopefully resolve that issue. couldn't reproduce but it's all related to the listener and the timeouts being weird 😬 How Has This Been Tested? --- - locally, pointing to airdrop dev BE and adding the referrals (and target for the extra animation!) manually to trigger the points listener: https://github.com/user-attachments/assets/db2b2049-d9f1-4398-a6f5-e1296430a56a What process can a PR reviewer use to test or verify this change? --- little bit tough if you don't have access to the BE (dev!) admin for testing, but you can also just make sure your local dev build is pointing to airdrop dev, then on a separate dev build use your referral code, and wait for the points to test
- Loading branch information
1 parent
bfb8de8
commit 3eebae1
Showing
9 changed files
with
87 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 1 addition & 11 deletions
12
...rop/AirdropGiftTracker/sections/LoggedIn/segments/Flare/FriendAccepted/FriendAccepted.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 24 additions & 37 deletions
61
src/hooks/airdrop/stateHelpers/useAirdropUserPointsListener.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,38 @@ | ||
import { useAirdropStore, UserPoints } from '@app/store/useAirdropStore'; | ||
import { listen } from '@tauri-apps/api/event'; | ||
import { useEffect } from 'react'; | ||
import { useCallback, useEffect } from 'react'; | ||
|
||
export const useAirdropUserPointsListener = () => { | ||
const setUserPoints = useAirdropStore((state) => state.setUserPoints); | ||
const referralCount = useAirdropStore((state) => state.referralCount); | ||
const setUserPoints = useAirdropStore((state) => state?.setUserPoints); | ||
const currentReferralData = useAirdropStore((state) => state?.referralCount); | ||
const bonusTiers = useAirdropStore((state) => state.bonusTiers); | ||
const setUserPointsReferralCount = useAirdropStore((state) => state.setReferralCount); | ||
const setFlareAnimationType = useAirdropStore((state) => state.setFlareAnimationType); | ||
|
||
useEffect(() => { | ||
let unListen: () => void = () => { | ||
//do nothing | ||
}; | ||
const handleAirdropPoints = useCallback( | ||
(pointsPayload: UserPoints) => { | ||
const incomingReferralData = pointsPayload?.referralCount; | ||
if (incomingReferralData?.count && incomingReferralData?.count !== currentReferralData?.count) { | ||
setFlareAnimationType('FriendAccepted'); | ||
|
||
listen('UserPoints', (event) => { | ||
if (event.payload) { | ||
const payload = event.payload as UserPoints; | ||
setUserPoints(payload); | ||
if (payload.referralCount) { | ||
if (referralCount?.count !== payload.referralCount.count) { | ||
if (referralCount?.count) { | ||
setFlareAnimationType('FriendAccepted'); | ||
if ( | ||
payload.referralCount.count && | ||
bonusTiers?.find((t) => t.target === payload?.referralCount?.count) | ||
) { | ||
setTimeout(() => { | ||
setFlareAnimationType('GoalComplete'); | ||
}, 2000); | ||
} | ||
} | ||
setUserPointsReferralCount(payload.referralCount); | ||
} | ||
const goalComplete = bonusTiers?.find((t) => t.target === incomingReferralData?.count); | ||
if (goalComplete) { | ||
setTimeout(() => setFlareAnimationType('GoalComplete'), 3000); | ||
} | ||
|
||
setUserPoints(pointsPayload); | ||
} | ||
}) | ||
.then((unListenFunction) => { | ||
unListen = unListenFunction; | ||
}) | ||
.catch((e) => { | ||
console.error('User points error: ', e); | ||
}); | ||
}, | ||
[bonusTiers, currentReferralData?.count, setFlareAnimationType, setUserPoints] | ||
); | ||
|
||
useEffect(() => { | ||
const ul = listen('UserPoints', ({ payload }) => { | ||
if (payload) { | ||
handleAirdropPoints(payload as UserPoints); | ||
} | ||
}); | ||
return () => { | ||
unListen(); | ||
ul.then((unlisten) => unlisten()); | ||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [bonusTiers, referralCount?.count]); | ||
}, [handleAirdropPoints]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters