From bf563154ca9ffd5551828d1ab4798377f9616bf8 Mon Sep 17 00:00:00 2001 From: Shreyaschorge Date: Wed, 16 Jul 2025 17:50:03 +0530 Subject: [PATCH] Fix merge conflict issues --- src/components/ui/NeynarAuthButton/index.tsx | 166 ++----------------- src/components/ui/tabs/ActionsTab.tsx | 40 ++--- 2 files changed, 36 insertions(+), 170 deletions(-) diff --git a/src/components/ui/NeynarAuthButton/index.tsx b/src/components/ui/NeynarAuthButton/index.tsx index 0eb1605..33e9a2d 100644 --- a/src/components/ui/NeynarAuthButton/index.tsx +++ b/src/components/ui/NeynarAuthButton/index.tsx @@ -5,8 +5,8 @@ import { useSignIn, UseSignInData } from '@farcaster/auth-kit'; import { useCallback, useEffect, useState, useRef } from 'react'; import { cn } from '~/lib/utils'; import { Button } from '~/components/ui/Button'; -import { AuthDialog } from '~/components/ui/NeynarAuthButton/AuthDialog'; import { ProfileButton } from '~/components/ui/NeynarAuthButton/ProfileButton'; +import { AuthDialog } from '~/components/ui/NeynarAuthButton/AuthDialog'; import { getItem, removeItem, setItem } from '~/lib/localStorage'; import { useMiniApp } from '@neynar/react'; import { @@ -141,7 +141,7 @@ export function NeynarAuthButton() { const updateSessionWithSigners = useCallback( async ( signers: StoredAuthState['signers'], - user: StoredAuthState['user'], + user: StoredAuthState['user'] ) => { if (!useBackendFlow) return; @@ -308,7 +308,7 @@ export function NeynarAuthButton() { setPollingInterval(null); return; } - + try { const response = await fetch( `/api/auth/signer?signerUuid=${signerUuid}` @@ -321,7 +321,7 @@ export function NeynarAuthButton() { setPollingInterval(null); return; } - + // Increment retry count for other errors retryCount++; if (retryCount >= maxRetries) { @@ -329,7 +329,7 @@ export function NeynarAuthButton() { setPollingInterval(null); return; } - + throw new Error(`Failed to poll signer status: ${response.status}`); } @@ -384,146 +384,7 @@ export function NeynarAuthButton() { generateNonce(); }, []); - // Backend flow using QuickAuth - const handleBackendSignIn = useCallback(async () => { - if (!nonce) { - console.error('❌ No nonce available for backend sign-in'); - return; - } - - try { - setSignersLoading(true); - const result = await sdk.actions.signIn({ nonce }); - - setMessage(result.message); - setSignature(result.signature); - // Use QuickAuth to sign in - const signInResult = await quickAuthSignIn(); - // Fetch user profile after sign in - if (quickAuthUser?.fid) { - const user = await fetchUserData(quickAuthUser.fid); - setBackendUserProfile({ - username: user?.username || '', - pfpUrl: user?.pfp_url || '', - }); - } - } catch (e) { - if (e instanceof SignInCore.RejectedByUser) { - console.log('ℹ️ Sign-in rejected by user'); - } else { - console.error('❌ Backend sign-in error:', e); - } - } - }, [useBackendFlow]); - - // Auth Kit data synchronization (only for browser flow) - useEffect(() => { - if (!useBackendFlow) { - setMessage(data?.message || null); - setSignature(data?.signature || null); - - // Reset the signer flow flag when message/signature change - if (data?.message && data?.signature) { - signerFlowStartedRef.current = false; - } - } - }, [useBackendFlow, data?.message, data?.signature]); - - // Connect for frontend flow when nonce is available (only for browser flow) - useEffect(() => { - if (!useBackendFlow && nonce && !channelToken) { - connect(); - } - }, [useBackendFlow, quickAuthUser?.fid, fetchUserData]); - - const handleFrontEndSignIn = useCallback(async () => { - try { - setSignersLoading(true); - const result = await sdk.actions.signIn({ nonce: nonce || '' }); - - setMessage(result.message); - setSignature(result.signature); - - // For frontend flow, we'll handle the signer flow in the useEffect - } catch (e) { - if (e instanceof SignInCore.RejectedByUser) { - console.log('ℹ️ Sign-in rejected by user'); - } else { - console.error('❌ Frontend sign-in error:', e); - } - } finally { - setSignersLoading(false); - } - }, [nonce]); - - const handleSignOut = useCallback(async () => { - try { - setSignersLoading(true); - - if (useBackendFlow) { - // Use QuickAuth sign out - await quickAuthSignOut(); - } else { - // Frontend flow sign out - setStoredAuth(null); - } - - // Common cleanup for both flows - setShowDialog(false); - setDialogStep('signin'); - setSignerApprovalUrl(null); - setMessage(null); - setSignature(null); - - // Reset polling interval - if (pollingInterval) { - clearInterval(pollingInterval); - setPollingInterval(null); - } - - // Reset signer flow flag - signerFlowStartedRef.current = false; - } catch (error) { - console.error('❌ Error during sign out:', error); - // Optionally handle error state - } finally { - setSignersLoading(false); - } - }, [useBackendFlow, pollingInterval, quickAuthSignOut]); - - // Backend flow using QuickAuth - const handleBackendSignIn = useCallback(async () => { - if (!nonce) { - console.error('❌ No nonce available for backend sign-in'); - return; - } - - try { - setSignersLoading(true); - const result = await sdk.actions.signIn({ nonce }); - - setMessage(result.message); - setSignature(result.signature); - // Use QuickAuth to sign in - const signInResult = await quickAuthSignIn(); - // Fetch user profile after sign in - if (quickAuthUser?.fid) { - const user = await fetchUserData(quickAuthUser.fid); - setBackendUserProfile({ - username: user?.username || '', - pfpUrl: user?.pfp_url || '', - }); - } - } catch (e) { - if (e instanceof SignInCore.RejectedByUser) { - console.log('ℹ️ Sign-in rejected by user'); - } else { - console.error('❌ Backend sign-in error:', e); - } - } - }, [nonce, quickAuthSignIn, quickAuthUser, fetchUserData]); - - // Fetch user profile when quickAuthUser.fid changes (for backend flow) + // Load stored auth state on mount (only for frontend flow) useEffect(() => { if (!useBackendFlow) { const stored = getItem(STORAGE_KEY); @@ -582,7 +443,7 @@ export function NeynarAuthButton() { useEffect(() => { setMessage(data?.message || null); setSignature(data?.signature || null); - + // Reset the signer flow flag when message/signature change if (data?.message && data?.signature) { signerFlowStartedRef.current = false; @@ -598,9 +459,14 @@ export function NeynarAuthButton() { // Handle fetching signers after successful authentication useEffect(() => { - if (message && signature && !isSignerFlowRunning && !signerFlowStartedRef.current) { + if ( + message && + signature && + !isSignerFlowRunning && + !signerFlowStartedRef.current + ) { signerFlowStartedRef.current = true; - + const handleSignerFlow = async () => { setIsSignerFlowRunning(true); try { @@ -618,7 +484,7 @@ export function NeynarAuthButton() { // First, fetch existing signers const signers = await fetchAllSigners(message, signature); - + if (useBackendFlow && isMobileContext) setSignersLoading(true); // Check if no signers exist or if we have empty signers @@ -743,7 +609,7 @@ export function NeynarAuthButton() { clearInterval(pollingInterval); setPollingInterval(null); } - + // Reset signer flow flag signerFlowStartedRef.current = false; } catch (error) { diff --git a/src/components/ui/tabs/ActionsTab.tsx b/src/components/ui/tabs/ActionsTab.tsx index 4c345cc..cc072d1 100644 --- a/src/components/ui/tabs/ActionsTab.tsx +++ b/src/components/ui/tabs/ActionsTab.tsx @@ -1,12 +1,12 @@ 'use client'; -import { useCallback, useState } from "react"; -import { useMiniApp } from "@neynar/react"; -import { ShareButton } from "../Share"; -import { Button } from "../Button"; -import { SignIn } from "../wallet/SignIn"; -import { type Haptics } from "@farcaster/miniapp-sdk"; -import { APP_URL } from "~/lib/constants"; +import { useCallback, useState } from 'react'; +import { useMiniApp } from '@neynar/react'; +import { ShareButton } from '../Share'; +import { Button } from '../Button'; +import { SignIn } from '../wallet/SignIn'; +import { type Haptics } from '@farcaster/miniapp-sdk'; +import { APP_URL } from '~/lib/constants'; import { NeynarAuthButton } from '../NeynarAuthButton/index'; /** @@ -124,16 +124,16 @@ export function ActionsTab() { // --- Render --- return ( -
+
{/* Share functionality */} {/* Authentication */} @@ -147,25 +147,25 @@ export function ActionsTab() { onClick={() => actions.openUrl('https://www.youtube.com/watch?v=dQw4w9WgXcQ') } - className='w-full' + className="w-full" > Open Link - {/* Notification functionality */} {notificationState.sendStatus && ( -
+
Send notification result: {notificationState.sendStatus}
)} @@ -174,14 +174,14 @@ export function ActionsTab() { {/* Haptic feedback controls */} -
-