mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-12-07 01:42:31 -05:00
Format after fixing conflicts
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import React, { createContext, useEffect, useState } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
import React, { createContext, useEffect, useState } from 'react';
|
||||
import dynamic from 'next/dynamic';
|
||||
import { sdk } from '@farcaster/miniapp-sdk';
|
||||
|
||||
const FarcasterSolanaProvider = dynamic(
|
||||
() => import('@farcaster/mini-app-solana').then(mod => mod.FarcasterSolanaProvider),
|
||||
{ ssr: false }
|
||||
() =>
|
||||
import('@farcaster/mini-app-solana').then(
|
||||
mod => mod.FarcasterSolanaProvider,
|
||||
),
|
||||
{ ssr: false },
|
||||
);
|
||||
|
||||
type SafeFarcasterSolanaProviderProps = {
|
||||
@@ -12,10 +15,15 @@ type SafeFarcasterSolanaProviderProps = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
const SolanaProviderContext = createContext<{ hasSolanaProvider: boolean }>({ hasSolanaProvider: false });
|
||||
const SolanaProviderContext = createContext<{ hasSolanaProvider: boolean }>({
|
||||
hasSolanaProvider: false,
|
||||
});
|
||||
|
||||
export function SafeFarcasterSolanaProvider({ endpoint, children }: SafeFarcasterSolanaProviderProps) {
|
||||
const isClient = typeof window !== "undefined";
|
||||
export function SafeFarcasterSolanaProvider({
|
||||
endpoint,
|
||||
children,
|
||||
}: SafeFarcasterSolanaProviderProps) {
|
||||
const isClient = typeof window !== 'undefined';
|
||||
const [hasSolanaProvider, setHasSolanaProvider] = useState<boolean>(false);
|
||||
const [checked, setChecked] = useState<boolean>(false);
|
||||
|
||||
@@ -48,8 +56,8 @@ export function SafeFarcasterSolanaProvider({ endpoint, children }: SafeFarcaste
|
||||
const origError = console.error;
|
||||
console.error = (...args) => {
|
||||
if (
|
||||
typeof args[0] === "string" &&
|
||||
args[0].includes("WalletConnectionError: could not get Solana provider")
|
||||
typeof args[0] === 'string' &&
|
||||
args[0].includes('WalletConnectionError: could not get Solana provider')
|
||||
) {
|
||||
if (!errorShown) {
|
||||
origError(...args);
|
||||
@@ -83,4 +91,4 @@ export function SafeFarcasterSolanaProvider({ endpoint, children }: SafeFarcaste
|
||||
|
||||
export function useHasSolanaProvider() {
|
||||
return React.useContext(SolanaProviderContext).hasSolanaProvider;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { createConfig, http, WagmiProvider } from "wagmi";
|
||||
import { base, degen, mainnet, optimism, unichain, celo } from "wagmi/chains";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { farcasterFrame } from "@farcaster/miniapp-wagmi-connector";
|
||||
import React from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { farcasterFrame } from '@farcaster/miniapp-wagmi-connector';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { createConfig, http, WagmiProvider } from 'wagmi';
|
||||
import { useConnect, useAccount } from 'wagmi';
|
||||
import { base, degen, mainnet, optimism, unichain, celo } from 'wagmi/chains';
|
||||
import { coinbaseWallet, metaMask } from 'wagmi/connectors';
|
||||
import { APP_NAME, APP_ICON_URL, APP_URL } from "~/lib/constants";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useConnect, useAccount } from "wagmi";
|
||||
import React from "react";
|
||||
import { APP_NAME, APP_ICON_URL, APP_URL } from '~/lib/constants';
|
||||
|
||||
// Custom hook for Coinbase Wallet detection and auto-connection
|
||||
function useCoinbaseWalletAutoConnect() {
|
||||
@@ -17,15 +17,16 @@ function useCoinbaseWalletAutoConnect() {
|
||||
useEffect(() => {
|
||||
// Check if we're running in Coinbase Wallet
|
||||
const checkCoinbaseWallet = () => {
|
||||
const isInCoinbaseWallet = window.ethereum?.isCoinbaseWallet ||
|
||||
const isInCoinbaseWallet =
|
||||
window.ethereum?.isCoinbaseWallet ||
|
||||
window.ethereum?.isCoinbaseWalletExtension ||
|
||||
window.ethereum?.isCoinbaseWalletBrowser;
|
||||
setIsCoinbaseWallet(!!isInCoinbaseWallet);
|
||||
};
|
||||
|
||||
|
||||
checkCoinbaseWallet();
|
||||
window.addEventListener('ethereum#initialized', checkCoinbaseWallet);
|
||||
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('ethereum#initialized', checkCoinbaseWallet);
|
||||
};
|
||||
@@ -70,7 +71,11 @@ export const config = createConfig({
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
// Wrapper component that provides Coinbase Wallet auto-connection
|
||||
function CoinbaseWalletAutoConnect({ children }: { children: React.ReactNode }) {
|
||||
function CoinbaseWalletAutoConnect({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
useCoinbaseWalletAutoConnect();
|
||||
return <>{children}</>;
|
||||
}
|
||||
@@ -79,10 +84,8 @@ export default function Provider({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<WagmiProvider config={config}>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<CoinbaseWalletAutoConnect>
|
||||
{children}
|
||||
</CoinbaseWalletAutoConnect>
|
||||
<CoinbaseWalletAutoConnect>{children}</CoinbaseWalletAutoConnect>
|
||||
</QueryClientProvider>
|
||||
</WagmiProvider>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"use client";
|
||||
'use client';
|
||||
|
||||
import { useState } from "react";
|
||||
import { APP_NAME } from "~/lib/constants";
|
||||
import sdk from "@farcaster/miniapp-sdk";
|
||||
import { useMiniApp } from "@neynar/react";
|
||||
import { useState } from 'react';
|
||||
import sdk from '@farcaster/miniapp-sdk';
|
||||
import { useMiniApp } from '@neynar/react';
|
||||
import { APP_NAME } from '~/lib/constants';
|
||||
|
||||
type HeaderProps = {
|
||||
neynarUser?: {
|
||||
@@ -18,23 +18,19 @@ export function Header({ neynarUser }: HeaderProps) {
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<div
|
||||
className="mt-4 mb-4 mx-4 px-2 py-2 bg-gray-100 dark:bg-gray-800 rounded-lg flex items-center justify-between border-[3px] border-double border-primary"
|
||||
>
|
||||
<div className="text-lg font-light">
|
||||
Welcome to {APP_NAME}!
|
||||
</div>
|
||||
<div className="mt-4 mb-4 mx-4 px-2 py-2 bg-gray-100 dark:bg-gray-800 rounded-lg flex items-center justify-between border-[3px] border-double border-primary">
|
||||
<div className="text-lg font-light">Welcome to {APP_NAME}!</div>
|
||||
{context?.user && (
|
||||
<div
|
||||
<div
|
||||
className="cursor-pointer"
|
||||
onClick={() => {
|
||||
setIsUserDropdownOpen(!isUserDropdownOpen);
|
||||
}}
|
||||
>
|
||||
{context.user.pfpUrl && (
|
||||
<img
|
||||
src={context.user.pfpUrl}
|
||||
alt="Profile"
|
||||
<img
|
||||
src={context.user.pfpUrl}
|
||||
alt="Profile"
|
||||
className="w-10 h-10 rounded-full border-2 border-primary"
|
||||
/>
|
||||
)}
|
||||
@@ -42,14 +38,16 @@ export function Header({ neynarUser }: HeaderProps) {
|
||||
)}
|
||||
</div>
|
||||
{context?.user && (
|
||||
<>
|
||||
<>
|
||||
{isUserDropdownOpen && (
|
||||
<div className="absolute top-full right-0 z-50 w-fit mt-1 mx-4 bg-white dark:bg-gray-800 rounded-lg shadow-lg border border-gray-200 dark:border-gray-700">
|
||||
<div className="p-3 space-y-2">
|
||||
<div className="text-right">
|
||||
<h3
|
||||
<h3
|
||||
className="font-bold text-sm hover:underline cursor-pointer inline-block"
|
||||
onClick={() => sdk.actions.viewProfile({ fid: context.user.fid })}
|
||||
onClick={() =>
|
||||
sdk.actions.viewProfile({ fid: context.user.fid })
|
||||
}
|
||||
>
|
||||
{context.user.displayName || context.user.username}
|
||||
</h3>
|
||||
@@ -74,4 +72,4 @@ export function Header({ neynarUser }: HeaderProps) {
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ export function AuthDialog({
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
src={`https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(
|
||||
content.qrUrl
|
||||
content.qrUrl,
|
||||
)}`}
|
||||
alt="QR Code"
|
||||
className="w-48 h-48"
|
||||
@@ -197,14 +197,14 @@ export function AuthDialog({
|
||||
content.qrUrl
|
||||
.replace(
|
||||
'https://farcaster.xyz/',
|
||||
'https://client.farcaster.xyz/deeplinks/'
|
||||
'https://client.farcaster.xyz/deeplinks/',
|
||||
)
|
||||
.replace(
|
||||
'https://client.farcaster.xyz/deeplinks/signed-key-request',
|
||||
'https://farcaster.xyz/~/connect'
|
||||
'https://farcaster.xyz/~/connect',
|
||||
),
|
||||
'_blank'
|
||||
)
|
||||
'_blank',
|
||||
);
|
||||
}
|
||||
}}
|
||||
className="btn btn-outline flex items-center justify-center gap-2 w-full"
|
||||
|
||||
@@ -27,7 +27,7 @@ export function ProfileButton({
|
||||
'flex items-center gap-3 px-4 py-2 min-w-0 rounded-lg',
|
||||
'bg-transparent border border-gray-300 dark:border-gray-600 text-gray-900 dark:text-gray-100',
|
||||
'hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors',
|
||||
'focus:outline-none focus:ring-1 focus:ring-primary'
|
||||
'focus:outline-none focus:ring-1 focus:ring-primary',
|
||||
)}
|
||||
>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
@@ -35,7 +35,7 @@ export function ProfileButton({
|
||||
src={pfpUrl}
|
||||
alt="Profile"
|
||||
className="w-6 h-6 rounded-full object-cover flex-shrink-0"
|
||||
onError={(e) => {
|
||||
onError={e => {
|
||||
(e.target as HTMLImageElement).src =
|
||||
'https://farcaster.xyz/avatar.png';
|
||||
}}
|
||||
@@ -46,7 +46,7 @@ export function ProfileButton({
|
||||
<svg
|
||||
className={cn(
|
||||
'w-4 h-4 transition-transform flex-shrink-0',
|
||||
showDropdown && 'rotate-180'
|
||||
showDropdown && 'rotate-180',
|
||||
)}
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
'use client';
|
||||
|
||||
import '@farcaster/auth-kit/styles.css';
|
||||
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 { ProfileButton } from '~/components/ui/NeynarAuthButton/ProfileButton';
|
||||
import { AuthDialog } from '~/components/ui/NeynarAuthButton/AuthDialog';
|
||||
import { getItem, removeItem, setItem } from '~/lib/localStorage';
|
||||
import { useSignIn, UseSignInData } from '@farcaster/auth-kit';
|
||||
import sdk, { SignIn as SignInCore } from '@farcaster/frame-sdk';
|
||||
import { useMiniApp } from '@neynar/react';
|
||||
import {
|
||||
signIn as backendSignIn,
|
||||
signOut as backendSignOut,
|
||||
useSession,
|
||||
} from 'next-auth/react';
|
||||
import sdk, { SignIn as SignInCore } from '@farcaster/frame-sdk';
|
||||
import { Button } from '~/components/ui/Button';
|
||||
import { AuthDialog } from '~/components/ui/NeynarAuthButton/AuthDialog';
|
||||
import { ProfileButton } from '~/components/ui/NeynarAuthButton/ProfileButton';
|
||||
import { getItem, removeItem, setItem } from '~/lib/localStorage';
|
||||
import { cn } from '~/lib/utils';
|
||||
|
||||
type User = {
|
||||
fid: number;
|
||||
@@ -102,13 +102,13 @@ export function NeynarAuthButton() {
|
||||
// New state for unified dialog flow
|
||||
const [showDialog, setShowDialog] = useState(false);
|
||||
const [dialogStep, setDialogStep] = useState<'signin' | 'access' | 'loading'>(
|
||||
'loading'
|
||||
'loading',
|
||||
);
|
||||
const [signerApprovalUrl, setSignerApprovalUrl] = useState<string | null>(
|
||||
null
|
||||
null,
|
||||
);
|
||||
const [pollingInterval, setPollingInterval] = useState<NodeJS.Timeout | null>(
|
||||
null
|
||||
null,
|
||||
);
|
||||
const [message, setMessage] = useState<string | null>(null);
|
||||
const [signature, setSignature] = useState<string | null>(null);
|
||||
@@ -141,7 +141,7 @@ export function NeynarAuthButton() {
|
||||
const updateSessionWithSigners = useCallback(
|
||||
async (
|
||||
signers: StoredAuthState['signers'],
|
||||
user: StoredAuthState['user']
|
||||
user: StoredAuthState['user'],
|
||||
) => {
|
||||
if (!useBackendFlow) return;
|
||||
|
||||
@@ -164,7 +164,7 @@ export function NeynarAuthButton() {
|
||||
console.error('❌ Error updating session with signers:', error);
|
||||
}
|
||||
},
|
||||
[useBackendFlow, message, signature, nonce]
|
||||
[useBackendFlow, message, signature, nonce],
|
||||
);
|
||||
|
||||
// Helper function to fetch user data from Neynar API
|
||||
@@ -182,7 +182,7 @@ export function NeynarAuthButton() {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
[]
|
||||
[],
|
||||
);
|
||||
|
||||
// Helper function to generate signed key request
|
||||
@@ -210,7 +210,7 @@ export function NeynarAuthButton() {
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(
|
||||
`Failed to generate signed key request: ${errorData.error}`
|
||||
`Failed to generate signed key request: ${errorData.error}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ export function NeynarAuthButton() {
|
||||
// throw error;
|
||||
}
|
||||
},
|
||||
[]
|
||||
[],
|
||||
);
|
||||
|
||||
// Helper function to fetch all signers
|
||||
@@ -233,10 +233,10 @@ export function NeynarAuthButton() {
|
||||
|
||||
const endpoint = useBackendFlow
|
||||
? `/api/auth/session-signers?message=${encodeURIComponent(
|
||||
message
|
||||
message,
|
||||
)}&signature=${signature}`
|
||||
: `/api/auth/signers?message=${encodeURIComponent(
|
||||
message
|
||||
message,
|
||||
)}&signature=${signature}`;
|
||||
|
||||
const response = await fetch(endpoint);
|
||||
@@ -258,7 +258,7 @@ export function NeynarAuthButton() {
|
||||
|
||||
if (signerData.signers && signerData.signers.length > 0) {
|
||||
const fetchedUser = (await fetchUserData(
|
||||
signerData.signers[0].fid
|
||||
signerData.signers[0].fid,
|
||||
)) as StoredAuthState['user'];
|
||||
user = fetchedUser;
|
||||
}
|
||||
@@ -285,7 +285,7 @@ export function NeynarAuthButton() {
|
||||
setSignersLoading(false);
|
||||
}
|
||||
},
|
||||
[useBackendFlow, fetchUserData, updateSessionWithSigners]
|
||||
[useBackendFlow, fetchUserData, updateSessionWithSigners],
|
||||
);
|
||||
|
||||
// Helper function to poll signer status
|
||||
@@ -308,10 +308,10 @@ export function NeynarAuthButton() {
|
||||
setPollingInterval(null);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`/api/auth/signer?signerUuid=${signerUuid}`
|
||||
`/api/auth/signer?signerUuid=${signerUuid}`,
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -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}`);
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ export function NeynarAuthButton() {
|
||||
|
||||
setPollingInterval(interval);
|
||||
},
|
||||
[fetchAllSigners, pollingInterval]
|
||||
[fetchAllSigners, pollingInterval],
|
||||
);
|
||||
|
||||
// Cleanup polling on unmount
|
||||
@@ -412,7 +412,7 @@ export function NeynarAuthButton() {
|
||||
}
|
||||
// For backend flow, the session will be handled by NextAuth
|
||||
},
|
||||
[useBackendFlow, fetchUserData]
|
||||
[useBackendFlow, fetchUserData],
|
||||
);
|
||||
|
||||
// Error callback
|
||||
@@ -443,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;
|
||||
@@ -459,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 {
|
||||
@@ -479,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
|
||||
@@ -490,7 +495,7 @@ export function NeynarAuthButton() {
|
||||
// Step 2: Generate signed key request
|
||||
const signedKeyData = await generateSignedKeyRequest(
|
||||
newSigner.signer_uuid,
|
||||
newSigner.public_key
|
||||
newSigner.public_key,
|
||||
);
|
||||
|
||||
// Step 3: Show QR code in access dialog for signer approval
|
||||
@@ -501,8 +506,8 @@ export function NeynarAuthButton() {
|
||||
await sdk.actions.openUrl(
|
||||
signedKeyData.signer_approval_url.replace(
|
||||
'https://client.farcaster.xyz/deeplinks/signed-key-request',
|
||||
'https://farcaster.xyz/~/connect'
|
||||
)
|
||||
'https://farcaster.xyz/~/connect',
|
||||
),
|
||||
);
|
||||
} else {
|
||||
setShowDialog(true); // Ensure dialog is shown during loading
|
||||
@@ -604,7 +609,7 @@ export function NeynarAuthButton() {
|
||||
clearInterval(pollingInterval);
|
||||
setPollingInterval(null);
|
||||
}
|
||||
|
||||
|
||||
// Reset signer flow flag
|
||||
signerFlowStartedRef.current = false;
|
||||
} catch (error) {
|
||||
@@ -663,7 +668,7 @@ export function NeynarAuthButton() {
|
||||
'btn btn-primary flex items-center gap-3',
|
||||
'disabled:opacity-50 disabled:cursor-not-allowed',
|
||||
'transform transition-all duration-200 active:scale-[0.98]',
|
||||
!url && !useBackendFlow && 'cursor-not-allowed'
|
||||
!url && !useBackendFlow && 'cursor-not-allowed',
|
||||
)}
|
||||
>
|
||||
{!useBackendFlow && !url ? (
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
'use client';
|
||||
|
||||
import { useCallback, useState, useEffect } from 'react';
|
||||
import { Button } from './Button';
|
||||
import { type ComposeCast } from '@farcaster/miniapp-sdk';
|
||||
import { useMiniApp } from '@neynar/react';
|
||||
import { type ComposeCast } from "@farcaster/miniapp-sdk";
|
||||
import { Button } from './Button';
|
||||
|
||||
interface EmbedConfig {
|
||||
path?: string;
|
||||
@@ -23,9 +23,16 @@ interface ShareButtonProps {
|
||||
isLoading?: boolean;
|
||||
}
|
||||
|
||||
export function ShareButton({ buttonText, cast, className = '', isLoading = false }: ShareButtonProps) {
|
||||
export function ShareButton({
|
||||
buttonText,
|
||||
cast,
|
||||
className = '',
|
||||
isLoading = false,
|
||||
}: ShareButtonProps) {
|
||||
const [isProcessing, setIsProcessing] = useState(false);
|
||||
const [bestFriends, setBestFriends] = useState<{ fid: number; username: string; }[] | null>(null);
|
||||
const [bestFriends, setBestFriends] = useState<
|
||||
{ fid: number; username: string }[] | null
|
||||
>(null);
|
||||
const [isLoadingBestFriends, setIsLoadingBestFriends] = useState(false);
|
||||
const { context, actions } = useMiniApp();
|
||||
|
||||
@@ -51,7 +58,7 @@ export function ShareButton({ buttonText, cast, className = '', isLoading = fals
|
||||
if (cast.bestFriends) {
|
||||
if (bestFriends) {
|
||||
// Replace @N with usernames, or remove if no matching friend
|
||||
finalText = finalText.replace(/@\d+/g, (match) => {
|
||||
finalText = finalText.replace(/@\d+/g, match => {
|
||||
const friendIndex = parseInt(match.slice(1)) - 1;
|
||||
const friend = bestFriends[friendIndex];
|
||||
if (friend) {
|
||||
@@ -67,16 +74,20 @@ export function ShareButton({ buttonText, cast, className = '', isLoading = fals
|
||||
|
||||
// Process embeds
|
||||
const processedEmbeds = await Promise.all(
|
||||
(cast.embeds || []).map(async (embed) => {
|
||||
(cast.embeds || []).map(async embed => {
|
||||
if (typeof embed === 'string') {
|
||||
return embed;
|
||||
}
|
||||
if (embed.path) {
|
||||
const baseUrl = process.env.NEXT_PUBLIC_URL || window.location.origin;
|
||||
const baseUrl =
|
||||
process.env.NEXT_PUBLIC_URL || window.location.origin;
|
||||
const url = new URL(`${baseUrl}${embed.path}`);
|
||||
|
||||
// Add UTM parameters
|
||||
url.searchParams.set('utm_source', `share-cast-${context?.user?.fid || 'unknown'}`);
|
||||
url.searchParams.set(
|
||||
'utm_source',
|
||||
`share-cast-${context?.user?.fid || 'unknown'}`,
|
||||
);
|
||||
|
||||
// If custom image generator is provided, use it
|
||||
if (embed.imageUrl) {
|
||||
@@ -87,7 +98,7 @@ export function ShareButton({ buttonText, cast, className = '', isLoading = fals
|
||||
return url.toString();
|
||||
}
|
||||
return embed.url || '';
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
// Open cast composer with all supported intents
|
||||
@@ -115,4 +126,4 @@ export function ShareButton({ buttonText, cast, className = '', isLoading = fals
|
||||
{buttonText}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 { useCallback, useState } from 'react';
|
||||
import { type Haptics } from '@farcaster/miniapp-sdk';
|
||||
import { useMiniApp } from '@neynar/react';
|
||||
import { Button } from '../Button';
|
||||
import { NeynarAuthButton } from '../NeynarAuthButton/index';
|
||||
import { ShareButton } from '../Share';
|
||||
import { SignIn } from '../wallet/SignIn';
|
||||
|
||||
/**
|
||||
* ActionsTab component handles mini app actions like sharing, notifications, and haptic feedback.
|
||||
@@ -51,7 +51,7 @@ export function ActionsTab() {
|
||||
* @returns Promise that resolves when the notification is sent or fails
|
||||
*/
|
||||
const sendFarcasterNotification = useCallback(async () => {
|
||||
setNotificationState((prev) => ({ ...prev, sendStatus: '' }));
|
||||
setNotificationState(prev => ({ ...prev, sendStatus: '' }));
|
||||
if (!notificationDetails || !context) {
|
||||
return;
|
||||
}
|
||||
@@ -66,22 +66,22 @@ export function ActionsTab() {
|
||||
}),
|
||||
});
|
||||
if (response.status === 200) {
|
||||
setNotificationState((prev) => ({ ...prev, sendStatus: 'Success' }));
|
||||
setNotificationState(prev => ({ ...prev, sendStatus: 'Success' }));
|
||||
return;
|
||||
} else if (response.status === 429) {
|
||||
setNotificationState((prev) => ({
|
||||
setNotificationState(prev => ({
|
||||
...prev,
|
||||
sendStatus: 'Rate limited',
|
||||
}));
|
||||
return;
|
||||
}
|
||||
const responseText = await response.text();
|
||||
setNotificationState((prev) => ({
|
||||
setNotificationState(prev => ({
|
||||
...prev,
|
||||
sendStatus: `Error: ${responseText}`,
|
||||
}));
|
||||
} catch (error) {
|
||||
setNotificationState((prev) => ({
|
||||
setNotificationState(prev => ({
|
||||
...prev,
|
||||
sendStatus: `Error: ${error}`,
|
||||
}));
|
||||
@@ -98,11 +98,11 @@ export function ActionsTab() {
|
||||
if (context?.user?.fid) {
|
||||
const userShareUrl = `${process.env.NEXT_PUBLIC_URL}/share/${context.user.fid}`;
|
||||
await navigator.clipboard.writeText(userShareUrl);
|
||||
setNotificationState((prev) => ({ ...prev, shareUrlCopied: true }));
|
||||
setNotificationState(prev => ({ ...prev, shareUrlCopied: true }));
|
||||
setTimeout(
|
||||
() =>
|
||||
setNotificationState((prev) => ({ ...prev, shareUrlCopied: false })),
|
||||
2000
|
||||
setNotificationState(prev => ({ ...prev, shareUrlCopied: false })),
|
||||
2000,
|
||||
);
|
||||
}
|
||||
}, [context?.user?.fid]);
|
||||
@@ -123,10 +123,10 @@ export function ActionsTab() {
|
||||
|
||||
// --- Render ---
|
||||
return (
|
||||
<div className='space-y-3 px-6 w-full max-w-md mx-auto'>
|
||||
<div className="space-y-3 px-6 w-full max-w-md mx-auto">
|
||||
{/* Share functionality */}
|
||||
<ShareButton
|
||||
buttonText='Share Mini App'
|
||||
buttonText="Share Mini App"
|
||||
cast={{
|
||||
text: 'Check out this awesome frame @1 @2 @3! 🚀🪐',
|
||||
bestFriends: true,
|
||||
@@ -134,7 +134,7 @@ export function ActionsTab() {
|
||||
`${process.env.NEXT_PUBLIC_URL}/share/${context?.user?.fid || ''}`,
|
||||
],
|
||||
}}
|
||||
className='w-full'
|
||||
className="w-full"
|
||||
/>
|
||||
|
||||
{/* Authentication */}
|
||||
@@ -148,25 +148,25 @@ export function ActionsTab() {
|
||||
onClick={() =>
|
||||
actions.openUrl('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
|
||||
}
|
||||
className='w-full'
|
||||
className="w-full"
|
||||
>
|
||||
Open Link
|
||||
</Button>
|
||||
|
||||
<Button onClick={actions.addMiniApp} disabled={added} className='w-full'>
|
||||
<Button onClick={actions.addMiniApp} disabled={added} className="w-full">
|
||||
Add Mini App to Client
|
||||
</Button>
|
||||
|
||||
{/* Notification functionality */}
|
||||
{notificationState.sendStatus && (
|
||||
<div className='text-sm w-full'>
|
||||
<div className="text-sm w-full">
|
||||
Send notification result: {notificationState.sendStatus}
|
||||
</div>
|
||||
)}
|
||||
<Button
|
||||
onClick={sendFarcasterNotification}
|
||||
disabled={!notificationDetails}
|
||||
className='w-full'
|
||||
className="w-full"
|
||||
>
|
||||
Send notification
|
||||
</Button>
|
||||
@@ -175,24 +175,24 @@ export function ActionsTab() {
|
||||
<Button
|
||||
onClick={copyUserShareUrl}
|
||||
disabled={!context?.user?.fid}
|
||||
className='w-full'
|
||||
className="w-full"
|
||||
>
|
||||
{notificationState.shareUrlCopied ? 'Copied!' : 'Copy share URL'}
|
||||
</Button>
|
||||
|
||||
{/* Haptic feedback controls */}
|
||||
<div className='space-y-2'>
|
||||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300'>
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||
Haptic Intensity
|
||||
</label>
|
||||
<select
|
||||
value={selectedHapticIntensity}
|
||||
onChange={(e) =>
|
||||
onChange={e =>
|
||||
setSelectedHapticIntensity(
|
||||
e.target.value as Haptics.ImpactOccurredType
|
||||
e.target.value as Haptics.ImpactOccurredType,
|
||||
)
|
||||
}
|
||||
className='w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-primary'
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-primary"
|
||||
>
|
||||
<option value={'light'}>Light</option>
|
||||
<option value={'medium'}>Medium</option>
|
||||
@@ -200,10 +200,10 @@ export function ActionsTab() {
|
||||
<option value={'soft'}>Soft</option>
|
||||
<option value={'rigid'}>Rigid</option>
|
||||
</select>
|
||||
<Button onClick={triggerHapticFeedback} className='w-full'>
|
||||
<Button onClick={triggerHapticFeedback} className="w-full">
|
||||
Trigger Haptic Feedback
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@ export function HomeTab() {
|
||||
<div className="flex items-center justify-center h-[calc(100vh-200px)] px-6">
|
||||
<div className="text-center w-full max-w-md mx-auto">
|
||||
<p className="text-lg mb-2">Put your content here!</p>
|
||||
<p className="text-sm text-gray-500 dark:text-gray-400">Powered by Neynar 🪐</p>
|
||||
<p className="text-sm text-gray-500 dark:text-gray-400">
|
||||
Powered by Neynar 🪐
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
'use client';
|
||||
|
||||
import { useCallback, useState } from "react";
|
||||
import { signIn, signOut, getCsrfToken } from "next-auth/react";
|
||||
import sdk, { SignIn as SignInCore } from "@farcaster/miniapp-sdk";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { Button } from "../Button";
|
||||
import { useCallback, useState } from 'react';
|
||||
import sdk, { SignIn as SignInCore } from '@farcaster/miniapp-sdk';
|
||||
import { signIn, signOut, getCsrfToken } from 'next-auth/react';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { Button } from '../Button';
|
||||
|
||||
/**
|
||||
* SignIn component handles Farcaster authentication using Sign-In with Farcaster (SIWF).
|
||||
@@ -72,7 +72,7 @@ export function SignIn() {
|
||||
*/
|
||||
const handleSignIn = useCallback(async () => {
|
||||
try {
|
||||
setAuthState((prev) => ({ ...prev, signingIn: true }));
|
||||
setAuthState(prev => ({ ...prev, signingIn: true }));
|
||||
setSignInFailure(undefined);
|
||||
const nonce = await getNonce();
|
||||
const result = await sdk.actions.signIn({ nonce });
|
||||
@@ -89,7 +89,7 @@ export function SignIn() {
|
||||
}
|
||||
setSignInFailure('Unknown error');
|
||||
} finally {
|
||||
setAuthState((prev) => ({ ...prev, signingIn: false }));
|
||||
setAuthState(prev => ({ ...prev, signingIn: false }));
|
||||
}
|
||||
}, [getNonce]);
|
||||
|
||||
@@ -103,14 +103,14 @@ export function SignIn() {
|
||||
*/
|
||||
const handleSignOut = useCallback(async () => {
|
||||
try {
|
||||
setAuthState((prev) => ({ ...prev, signingOut: true }));
|
||||
setAuthState(prev => ({ ...prev, signingOut: true }));
|
||||
// Only sign out if the current session is from Farcaster provider
|
||||
if (session?.provider === 'farcaster') {
|
||||
await signOut({ redirect: false });
|
||||
}
|
||||
setSignInResult(undefined);
|
||||
} finally {
|
||||
setAuthState((prev) => ({ ...prev, signingOut: false }));
|
||||
setAuthState(prev => ({ ...prev, signingOut: false }));
|
||||
}
|
||||
}, [session]);
|
||||
|
||||
@@ -132,7 +132,9 @@ export function SignIn() {
|
||||
{/* Session Information */}
|
||||
{session && (
|
||||
<div className="my-2 p-2 text-xs overflow-x-scroll bg-gray-100 dark:bg-gray-900 rounded-lg font-mono">
|
||||
<div className="font-semibold text-gray-500 dark:text-gray-300 mb-1">Session</div>
|
||||
<div className="font-semibold text-gray-500 dark:text-gray-300 mb-1">
|
||||
Session
|
||||
</div>
|
||||
<div className="whitespace-pre text-gray-700 dark:text-gray-200">
|
||||
{JSON.stringify(session, null, 2)}
|
||||
</div>
|
||||
@@ -142,15 +144,21 @@ export function SignIn() {
|
||||
{/* Error Display */}
|
||||
{signInFailure && !authState.signingIn && (
|
||||
<div className="my-2 p-2 text-xs overflow-x-scroll bg-gray-100 dark:bg-gray-900 rounded-lg font-mono">
|
||||
<div className="font-semibold text-gray-500 dark:text-gray-300 mb-1">SIWF Result</div>
|
||||
<div className="whitespace-pre text-gray-700 dark:text-gray-200">{signInFailure}</div>
|
||||
<div className="font-semibold text-gray-500 dark:text-gray-300 mb-1">
|
||||
SIWF Result
|
||||
</div>
|
||||
<div className="whitespace-pre text-gray-700 dark:text-gray-200">
|
||||
{signInFailure}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Success Result Display */}
|
||||
{signInResult && !authState.signingIn && (
|
||||
<div className="my-2 p-2 text-xs overflow-x-scroll bg-gray-100 dark:bg-gray-900 rounded-lg font-mono">
|
||||
<div className="font-semibold text-gray-500 dark:text-gray-300 mb-1">SIWF Result</div>
|
||||
<div className="font-semibold text-gray-500 dark:text-gray-300 mb-1">
|
||||
SIWF Result
|
||||
</div>
|
||||
<div className="whitespace-pre text-gray-700 dark:text-gray-200">
|
||||
{JSON.stringify(signInResult, null, 2)}
|
||||
</div>
|
||||
@@ -158,4 +166,4 @@ export function SignIn() {
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user