forked from vipineth/hypeterminal
-
Notifications
You must be signed in to change notification settings - Fork 0
Points update #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
73b6035
feat: add privy
luu-alex cafd7fd
feat: update pnpm
luu-alex 1eb79a3
feat: update walet dialog
luu-alex 4e78e83
fix: update ci
luu-alex 56ab844
feat: update
luu-alex 2e6df0b
fix: remove flow
luu-alex 9d5c5fb
fix: build
luu-alex 95e2b95
fix: tests
luu-alex b26da97
fix(hooks): source nvm in lingui-extract to use correct node version
luu-alex e892e5d
feat: update the white color
luu-alex 21f8859
fix: revert lefthook
luu-alex 805085d
Merge pull request #4 from hyperodd/update-colors
luu-alex 2d11f8a
fix: update colors
luu-alex 079fec9
feat: support wallets
luu-alex b4d6d15
fix: remove dead code
luu-alex 49dae5c
Merge pull request #5 from hyperodd/update-colors
luu-alex 6f469a8
feat: add faucet
luu-alex ef1b36d
feat: add turnstil
luu-alex 3002876
feat: remove email signin
luu-alex 022cc78
feat: integrate points
luu-alex aa277cc
fix: merge branch 'prod' into integrate-points
luu-alex ba20b07
feat: update referral
luu-alex a05be17
fix: merge branch 'prod' into points-update
luu-alex 7b5da3b
fix: address feedback
luu-alex 9e59576
fix: addressfeedback
luu-alex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { usePrivy } from "@privy-io/react-auth"; | ||
| import { useEffect, useRef } from "react"; | ||
| import { useConnection } from "wagmi"; | ||
|
|
||
| const API_URL = import.meta.env.VITE_HYPERMILES_API_URL; | ||
| const STORAGE_KEY = "hyperterminal:referral"; | ||
|
|
||
| function getStoredReferral(): string | null { | ||
| if (typeof window === "undefined") return null; | ||
| return localStorage.getItem(STORAGE_KEY); | ||
| } | ||
|
|
||
| function clearStoredReferral() { | ||
| localStorage.removeItem(STORAGE_KEY); | ||
| } | ||
|
|
||
| export function useReferralCapture() { | ||
| useEffect(() => { | ||
| if (typeof window === "undefined") return; | ||
|
|
||
| const params = new URLSearchParams(window.location.search); | ||
| const referral = params.get("referral"); | ||
| if (!referral) return; | ||
|
|
||
| localStorage.setItem(STORAGE_KEY, referral); | ||
|
|
||
| params.delete("referral"); | ||
| const newSearch = params.toString(); | ||
| const newUrl = window.location.pathname + (newSearch ? `?${newSearch}` : "") + window.location.hash; | ||
| window.history.replaceState({}, "", newUrl); | ||
| }, []); | ||
| } | ||
|
|
||
| export function useAutoRegisterReferral() { | ||
| const { address, isConnected } = useConnection(); | ||
| const { user } = usePrivy(); | ||
| const registeredRef = useRef(false); | ||
|
|
||
| useEffect(() => { | ||
| async function autoRegister() { | ||
| if (!isConnected || !address || registeredRef.current) return; | ||
|
|
||
| registeredRef.current = true; | ||
|
|
||
| try { | ||
| const res = await fetch(`${API_URL}/user_points?user_address=${address}`); | ||
| if (res.ok) { | ||
| clearStoredReferral(); | ||
| return; | ||
| } | ||
|
|
||
| if (res.status === 404) { | ||
| const referral = getStoredReferral(); | ||
| const body: Record<string, string> = { walletAddress: address }; | ||
| if (referral) { | ||
| body.referralCode = referral; | ||
| } | ||
| if (user?.id) { | ||
| body.privyUserId = user.id; | ||
| } | ||
| await fetch(`${API_URL}/users`, { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify(body), | ||
| }); | ||
| clearStoredReferral(); | ||
| } | ||
| } catch (error) { | ||
| console.error("Auto-registration failed:", error); | ||
| registeredRef.current = false; | ||
| } | ||
| } | ||
|
|
||
| autoRegister(); | ||
| }, [isConnected, address, user?.id]); | ||
| } | ||
|
|
||
| export { getStoredReferral }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic inside this
useEffectcan be simplified and made more readable by usingasync/await. This also provides an opportunity to handle errors more explicitly by logging them in acatchblock. The current implementation swallows errors, which can make debugging difficult.