From 8f80d3c098b2b6740d1b74d37a7bc2bfb75a34ea Mon Sep 17 00:00:00 2001 From: warlock Date: Thu, 3 Apr 2025 04:45:57 +0530 Subject: [PATCH] more refactor --- src/components/GameModal.tsx | 12 +-- src/components/Home.tsx | 189 ----------------------------------- src/data/games.ts | 6 -- src/shared/solana_helpers.ts | 2 +- src/types/Game.ts | 6 ++ 5 files changed, 11 insertions(+), 204 deletions(-) delete mode 100644 src/components/Home.tsx create mode 100644 src/types/Game.ts diff --git a/src/components/GameModal.tsx b/src/components/GameModal.tsx index 692eb28..fda9399 100644 --- a/src/components/GameModal.tsx +++ b/src/components/GameModal.tsx @@ -1,17 +1,13 @@ "use client"; -import { useEffect, useState } from "react"; -import { ConnectedSolanaWallet, usePrivy, useSolanaWallets } from "@privy-io/react-auth"; -import { Connection, PublicKey } from "@solana/web3.js"; -import { AnchorProvider, Program, BN } from "@coral-xyz/anchor"; -import idl from "../idl/bets_idl.json"; // Ensure this is the correct IDL path +import { useState } from "react"; +import { usePrivy, useSolanaWallets } from "@privy-io/react-auth"; import { toast } from "sonner"; -import { Bets } from "@/idl/bets"; -import { Game, games } from "../data/games"; // Assuming you have a games data file +import { games } from "../data/games"; // Assuming you have a games data file import { PriceSelection } from "./PriceSelection"; import { GameSelection } from "./GameSelection"; -import { CLUSTER_URL } from "@/data/shared"; import { createBet } from "@/shared/solana_helpers"; +import { Game } from "@/types/Game"; // Change to Mainnet when deploying diff --git a/src/components/Home.tsx b/src/components/Home.tsx deleted file mode 100644 index d2df02d..0000000 --- a/src/components/Home.tsx +++ /dev/null @@ -1,189 +0,0 @@ -"use client"; - -import { useState } from "react"; -import Image from "next/image"; -import OpenGames from "./OpenGames"; -import { Game, games } from "../data/games"; -import { usePrivy } from "@privy-io/react-auth"; -import { toast } from "react-toastify"; - -export default function HeroSection() { - const { authenticated } = usePrivy(); - const [isModalOpen, setIsModalOpen] = useState(false); - const [isGameModalOpen, setIsGameModalOpen] = useState(false); - const [selectedGame, setSelectedGame] = useState(null); - const [selectedPrice, setSelectedPrice] = useState(null); - - const prices = [0.2, 0.5, 0.8]; - - const handleGameSelect = (game: Game) => setSelectedGame(game); - const handlePriceSelect = (price: number) => setSelectedPrice(price); - - const handleCreateGame = () => { - if (!authenticated) return; // Don't proceed if not signed in - - if (selectedGame && selectedPrice !== null) { - console.log(`Creating game: ${selectedGame.name} with price ${selectedPrice} SOL`); - setIsGameModalOpen(false); - } else { - toast.warn("Please select a game and a price."); - } - }; - - const closeModals = () => { - setIsModalOpen(false); - setIsGameModalOpen(false); - }; - - return ( - <> -
- DuelFi Hero - -

- Instant Duels, Instant{" "} - Wins -

- - - -

setIsModalOpen(true)} - > - How it works?.. -

- - -
- - {/* Game Modal */} - {isGameModalOpen && ( -
-
e.stopPropagation()} - > -

Create Game

- - {/* Game Selection */} -
- {games.map((game) => ( -
handleGameSelect(game)} - > - {game.name} -

{game.name}

-
- ))} -
- - {/* Price Selection */} -
- {prices.map((price) => ( -

handlePriceSelect(price)} - > - SOL - {price} SOL -

- ))} -
- - {/* Create Game Button */} - - - {/* Warning if Not Signed In */} - {!authenticated && ( -

Please sign in first

- )} -
-
- )} - - {/* How it Works Modal */} - {isModalOpen && ( -
-
e.stopPropagation()} - > -

How It Works

- -
- {[ - { step: "Connect Your Wallet", desc: "Start by linking your wallet securely." }, - { step: "Create or Join Game", desc: "Pick a game and set a wager, or join an existing match." }, - { step: "Place Your Bet", desc: "Confirm your wager and get ready to play." }, - { step: "Claim Your Winnings", desc: "Win the game and collect your rewards instantly!" }, - ].map(({ step, desc }, index) => ( -
-

{index + 1}. {step}

-

{desc}

-
- ))} -
- - -
-
- )} - - ); -} diff --git a/src/data/games.ts b/src/data/games.ts index 5ecac92..542ed26 100644 --- a/src/data/games.ts +++ b/src/data/games.ts @@ -19,9 +19,3 @@ export const games = [ }, ]; -export interface Game { - id: string; - name: string; - entryFee: string; - thumbnail: string; - } \ No newline at end of file diff --git a/src/shared/solana_helpers.ts b/src/shared/solana_helpers.ts index 79822ab..df4bce8 100644 --- a/src/shared/solana_helpers.ts +++ b/src/shared/solana_helpers.ts @@ -6,7 +6,7 @@ import { Connection, Keypair, LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.j import idl from "../idl/bets_idl.json"; import { Bet } from "@/types/Bet"; import { toast } from "sonner"; -import { Game } from "@/data/games"; +import { Game } from "@/types/Game"; export const fetchOpenBets = async (wallets: ConnectedSolanaWallet): Promise => { diff --git a/src/types/Game.ts b/src/types/Game.ts new file mode 100644 index 0000000..a68ff0c --- /dev/null +++ b/src/types/Game.ts @@ -0,0 +1,6 @@ +export interface Game { + id: string; + name: string; + entryFee: string; + thumbnail: string; + } \ No newline at end of file