betfun-arena/apps/web/components/ShareToXButton.tsx

62 lines
1.8 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { Button } from "./ui/button";
import { TWITTER_SHARE_URL } from "../lib/constants";
import { generateShareText } from "../lib/utils";
interface ShareToXButtonProps {
type: "create" | "join" | "win";
arenaTitle: string;
arenaUrl: string;
amount?: number;
outcome?: string;
className?: string;
}
export function ShareToXButton({
type,
arenaTitle,
arenaUrl,
amount,
outcome,
className,
}: ShareToXButtonProps) {
const handleShare = () => {
// Generate share text based on type
let text = "";
switch (type) {
case "win":
text = `Just won ${amount?.toFixed(2) || "X"} SOL on BetFun Arena! ๐Ÿ’ฐ\n\n"${arenaTitle}"\n\nJoin the arena:`;
break;
case "create":
text = `I just created a prediction battle: "${arenaTitle}"\n\nโš”๏ธ Join the arena:`;
break;
case "join":
text = `Just bet ${amount?.toFixed(2) || "X"} SOL that ${outcome || "this"} will happen! Who's with me? ๐Ÿš€\n\n"${arenaTitle}"\n\nJoin the battle:`;
break;
default:
text = `Check out this prediction battle on BetFun Arena โš”๏ธ\n\n"${arenaTitle}"\n\n`;
}
// Add UTM params to URL
const urlWithParams = new URL(arenaUrl);
urlWithParams.searchParams.set("utm_source", "twitter");
urlWithParams.searchParams.set("utm_medium", "share");
urlWithParams.searchParams.set("utm_campaign", type);
const shareUrl = `${TWITTER_SHARE_URL}?text=${encodeURIComponent(
text
)}&url=${encodeURIComponent(urlWithParams.toString())}`;
window.open(shareUrl, "_blank", "width=550,height=420");
};
return (
<Button onClick={handleShare} variant="secondary" className={className}>
<span className="mr-2">๐•</span>
Share to X
</Button>
);
}