privy global

This commit is contained in:
Sewmina 2025-03-30 01:57:53 +05:30
parent 0e1ce871d8
commit ac8cc4db9e
3 changed files with 45 additions and 57 deletions

View File

@ -1,15 +1,41 @@
"use client";
import Footer from "@/components/Footer"; import Footer from "@/components/Footer";
import Header from "@/components/Header"; import Header from "@/components/Header";
import HeroSection from "@/components/Home"; import HeroSection from "@/components/Home";
import { PrivyProvider } from "@privy-io/react-auth";
import { toSolanaWalletConnectors } from "@privy-io/react-auth/solana";
export default function Home() { export default function Home() {
return ( return (
<div className="bg-[rgb(22,22,22)]"> <div className="bg-[rgb(22,22,22)]">
<PrivyProvider
appId="cm8spd7l600lfe4am1phq9qq8"
clientId="client-WY5i4HS6T7JP44iKMQUyZXwftzwKLFvEsGvMtFY1znXSj"
config={{
// Customize Privy's appearance in your app
appearance: {
theme: 'dark',
accentColor: '#f89016',
logo: 'https://your-logo-url'
},
// Create embedded wallets for users who don't have a wallet
embeddedWallets: {
createOnLogin: 'users-without-wallets'
},
externalWallets:{
solana:{connectors:toSolanaWalletConnectors()}
}
}}
>
<Header/> <Header/>
<HeroSection/> <HeroSection/>
<Footer/> <Footer/>
</PrivyProvider>
</div> </div>
); );
} }

View File

@ -4,9 +4,7 @@ import Link from "next/link";
import Image from "next/image"; import Image from "next/image";
import { FaTelegram, FaXTwitter } from "react-icons/fa6"; import { FaTelegram, FaXTwitter } from "react-icons/fa6";
import { useState } from "react"; import { useState } from "react";
import { PrivyProvider } from "@privy-io/react-auth";
import PrivyButton from "./PrivyButton"; import PrivyButton from "./PrivyButton";
import { toSolanaWalletConnectors } from "@privy-io/react-auth/solana";
export default function Header() { export default function Header() {
const [isDrawerOpen, setIsDrawerOpen] = useState(false); const [isDrawerOpen, setIsDrawerOpen] = useState(false);
@ -16,26 +14,7 @@ export default function Header() {
}; };
return ( return (
<><PrivyProvider <>
appId="cm8spd7l600lfe4am1phq9qq8"
clientId="client-WY5i4HS6T7JP44iKMQUyZXwftzwKLFvEsGvMtFY1znXSj"
config={{
// Customize Privy's appearance in your app
appearance: {
theme: 'dark',
accentColor: '#f89016',
logo: 'https://your-logo-url'
},
// Create embedded wallets for users who don't have a wallet
embeddedWallets: {
createOnLogin: 'users-without-wallets'
},
externalWallets:{
solana:{connectors:toSolanaWalletConnectors()}
}
}}
>
<header className="w-full bg-[rgb(22,22,22)] shadow-md"> <header className="w-full bg-[rgb(22,22,22)] shadow-md">
<div className="container mx-auto flex items-center justify-between p-12 max-w-screen-xl w-full"> <div className="container mx-auto flex items-center justify-between p-12 max-w-screen-xl w-full">
{/* Logo */} {/* Logo */}
@ -193,6 +172,6 @@ export default function Header() {
</div> </div>
)} )}
</header> </header>
</PrivyProvider></> </>
); );
} }

View File

@ -4,14 +4,15 @@ import { useState } from "react";
import Image from "next/image"; import Image from "next/image";
import OpenGames from "./OpenGames"; import OpenGames from "./OpenGames";
import { Game, games } from "../data/games"; import { Game, games } from "../data/games";
import { usePrivy } from "@privy-io/react-auth";
import { toast } from "react-toastify";
export default function HeroSection() { export default function HeroSection() {
const { ready, authenticated } = usePrivy();
const [isModalOpen, setIsModalOpen] = useState(false); const [isModalOpen, setIsModalOpen] = useState(false);
const [isGameModalOpen, setIsGameModalOpen] = useState(false); const [isGameModalOpen, setIsGameModalOpen] = useState(false);
const [selectedGame, setSelectedGame] = useState<Game | null>(null); const [selectedGame, setSelectedGame] = useState<Game | null>(null);
const [selectedPrice, setSelectedPrice] = useState<number | null>(null); const [selectedPrice, setSelectedPrice] = useState<number | null>(null);
const [isSignedIn, setIsSignedIn] = useState(false); // Replace with actual authentication logic
const [authMessage, setAuthMessage] = useState(""); // Message for sign-in prompt
const prices = [0.2, 0.5, 0.8]; const prices = [0.2, 0.5, 0.8];
@ -19,22 +20,19 @@ export default function HeroSection() {
const handlePriceSelect = (price: number) => setSelectedPrice(price); const handlePriceSelect = (price: number) => setSelectedPrice(price);
const handleCreateGame = () => { const handleCreateGame = () => {
if (!isSignedIn) { if (!authenticated) return; // Don't proceed if not signed in
setAuthMessage("Please sign in first.");
return;
}
if (selectedGame && selectedPrice !== null) { if (selectedGame && selectedPrice !== null) {
console.log(`Creating game: ${selectedGame.name} with price ${selectedPrice} SOL`); console.log(`Creating game: ${selectedGame.name} with price ${selectedPrice} SOL`);
setIsGameModalOpen(false); setIsGameModalOpen(false);
} else { } else {
console.log("Please select a game and a price."); toast.warn("Please select a game and a price.");
} }
}; };
const closeModals = () => { const closeModals = () => {
setIsModalOpen(false); setIsModalOpen(false);
setIsGameModalOpen(false); setIsGameModalOpen(false);
setAuthMessage(""); // Clear message when modal is closed
}; };
return ( return (
@ -55,13 +53,7 @@ export default function HeroSection() {
<button <button
className="mt-12 px-12 py-4 bg-[rgb(248,144,22)] hover:bg-white text-black text-sm font-semibold rounded-xl flex items-center gap-2 transition duration-300 hover:scale-110" className="mt-12 px-12 py-4 bg-[rgb(248,144,22)] hover:bg-white text-black text-sm font-semibold rounded-xl flex items-center gap-2 transition duration-300 hover:scale-110"
onClick={() => { onClick={() => setIsGameModalOpen(true)}
if (!isSignedIn) {
setAuthMessage("Please sign in first.");
} else {
setIsGameModalOpen(true);
}
}}
> >
Create a Game Create a Game
<svg <svg
@ -89,24 +81,6 @@ export default function HeroSection() {
<OpenGames /> <OpenGames />
</section> </section>
{/* Authentication Prompt */}
{authMessage && (
<div className="fixed inset-0 bg-black/70 flex justify-center items-center z-50" onClick={closeModals}>
<div
className="bg-[rgb(30,30,30)] text-white w-full max-w-sm p-6 rounded-2xl shadow-lg"
onClick={(e) => e.stopPropagation()}
>
<p className="text-center text-lg">{authMessage}</p>
<button
className="mt-4 w-full bg-[rgb(248,144,22)] text-black font-semibold py-2 rounded-xl transition hover:bg-white hover:scale-105"
onClick={closeModals}
>
Okay
</button>
</div>
</div>
)}
{/* Game Modal */} {/* Game Modal */}
{isGameModalOpen && ( {isGameModalOpen && (
<div className="fixed inset-0 bg-black/70 flex justify-center items-start pt-10 z-50" onClick={closeModals}> <div className="fixed inset-0 bg-black/70 flex justify-center items-start pt-10 z-50" onClick={closeModals}>
@ -159,12 +133,21 @@ export default function HeroSection() {
))} ))}
</div> </div>
{/* Create Game Button */}
<button <button
className="mt-6 w-full bg-[rgb(248,144,22)] text-black font-semibold py-2 rounded-xl transition hover:bg-white hover:scale-105" className={`mt-6 w-full py-2 rounded-xl font-semibold transition
${authenticated ? "bg-[rgb(248,144,22)] text-black hover:bg-white hover:scale-105" : "bg-gray-600 text-gray-400 cursor-not-allowed"}
`}
onClick={handleCreateGame} onClick={handleCreateGame}
disabled={!authenticated}
> >
Create Game Create Game
</button> </button>
{/* Warning if Not Signed In */}
{!authenticated && (
<p className="text-red-500 text-sm text-center mt-2">Please sign in first</p>
)}
</div> </div>
</div> </div>
)} )}