Merge branch 'main' into shreyas-formatting

This commit is contained in:
Shreyaschorge
2025-07-14 18:55:06 +05:30
34 changed files with 2479 additions and 829 deletions

View File

@@ -1,9 +1,9 @@
'use client';
import { useCallback, useState, useEffect } from 'react';
import { type ComposeCast } from '@farcaster/frame-sdk';
import { useMiniApp } from '@neynar/react';
import { Button } from './Button';
import { useMiniApp } from '@neynar/react';
import { type ComposeCast } from "@farcaster/miniapp-sdk";
interface EmbedConfig {
path?: string;
@@ -23,16 +23,9 @@ 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();
@@ -58,7 +51,7 @@ export function ShareButton({
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) {
@@ -74,20 +67,16 @@ export function ShareButton({
// 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) {
@@ -98,7 +87,7 @@ export function ShareButton({
return url.toString();
}
return embed.url || '';
}),
})
);
// Open cast composer with all supported intents
@@ -126,4 +115,4 @@ export function ShareButton({
{buttonText}
</Button>
);
}
}