Skip to content

fix: fix ui based off of feedback#18

Merged
luu-alex merged 3 commits intoprodfrom
fix-ui
Apr 10, 2026
Merged

fix: fix ui based off of feedback#18
luu-alex merged 3 commits intoprodfrom
fix-ui

Conversation

@luu-alex
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a "Referrals" menu item to the user interface and updates the auto-registration hook to incorporate authentication status from Privy. A review comment identified potential race conditions where registration might occur before the user ID is available, as well as an issue where account switching wouldn't trigger a re-registration due to the persistent ref state.

Comment thread src/hooks/use-referral.ts Outdated
useEffect(() => {
async function autoRegister() {
if (!isConnected || !address || registeredRef.current) return;
if (!isConnected || !authenticated || !address || registeredRef.current) return;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The auto-registration logic has two potential issues:

  1. Race Condition: There is a possibility that authenticated becomes true before the user object (and thus user.id) is fully loaded. If the effect runs at this moment, it will register the user without their privyUserId. Since registeredRef.current is set to true immediately (on line 43), the hook won't retry once user.id becomes available.
  2. Account Switching: The registeredRef persists as true even if the wallet address changes. If a user switches accounts in their wallet without a page refresh, the new address will not be auto-registered because the guard clause will return early.

Consider waiting for user?.id when authenticated and ensuring the registration logic accounts for address changes.

Suggested change
if (!isConnected || !authenticated || !address || registeredRef.current) return;
if (!isConnected || !authenticated || !address || !user?.id || registeredRef.current) return;

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 10, 2026

Deploying hyperterminal with  Cloudflare Pages  Cloudflare Pages

Latest commit: d16ccf5
Status: ✅  Deploy successful!
Preview URL: https://2d043c42.hyperterminal.pages.dev
Branch Preview URL: https://fix-ui.hyperterminal.pages.dev

View logs

@luu-alex
Copy link
Copy Markdown
Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a 'Referrals' menu item to the user menu and refactors the referral auto-registration hook to improve reliability. Key changes include updating the logout flow to ensure the wallet disconnects correctly and enhancing the registration tracking logic in useAutoRegisterReferral. Review feedback suggests awaiting the asynchronous logout call to avoid race conditions and using a composite key of address and user ID for registration tracking to handle account switching.

Comment on lines 66 to 71
function handleLogout() {
if (authenticated) {
logout();
} else {
disconnect();
}
disconnect();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logout function from Privy is asynchronous. It is recommended to await it before disconnecting the wallet to ensure the authentication session is properly cleared and to avoid potential race conditions where the wallet is disconnected while Privy is still processing the logout.

Suggested change
function handleLogout() {
if (authenticated) {
logout();
} else {
disconnect();
}
disconnect();
}
async function handleLogout() {
if (authenticated) {
await logout();
}
disconnect();
}

Comment thread src/hooks/use-referral.ts
Comment on lines +37 to +45
const registeredAddressRef = useRef<string | null>(null);

useEffect(() => {
async function autoRegister() {
if (!isConnected || !address || registeredRef.current) return;
if (!isConnected || !authenticated || !address) return;
if (authenticated && !user?.id) return;
if (registeredAddressRef.current === address) return;

registeredRef.current = true;
registeredAddressRef.current = address;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation only tracks the wallet address to prevent redundant registration calls. However, if a user switches their Privy account while using the same wallet address, the registration check will be skipped. Additionally, it's safer to check for the presence of API_URL before attempting to fetch. Using a composite key of address and user ID in the ref provides better tracking.

Suggested change
const registeredAddressRef = useRef<string | null>(null);
useEffect(() => {
async function autoRegister() {
if (!isConnected || !address || registeredRef.current) return;
if (!isConnected || !authenticated || !address) return;
if (authenticated && !user?.id) return;
if (registeredAddressRef.current === address) return;
registeredRef.current = true;
registeredAddressRef.current = address;
const registeredAddressRef = useRef<string | null>(null);
useEffect(() => {
async function autoRegister() {
if (!isConnected || !authenticated || !address || !user?.id || !API_URL) return;
const key = address + "-" + user.id;
if (registeredAddressRef.current === key) return;
registeredAddressRef.current = key;

@luu-alex luu-alex merged commit f78f65d into prod Apr 10, 2026
4 checks passed
@luu-alex luu-alex deleted the fix-ui branch April 10, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant