Jackpot Page

This example will guide you through displaying the jackpot's size, ticket price, odds of winning and a countdown to the next drawing along with a section for claiming winnings and the last jackpot results.

This references our Jackpot Demo Integration Github Repo. You can find the code for the demo integration here or view the live demo here.

Jackpot Page

This is the entry point for the jackpot page.

// /app/jackpot/page.tsx

import { JackpotComponent } from '@/components/jackpot-component';

export default function JackpotPage() {
    return <JackpotComponent />;
}

Jackpot Component

  • This component will display the jackpot's size, ticket price, odds of winning and a countdown to the next drawing.

  • This component will also display a form to purchase tickets.

// /app/components/jackpot-component.tsx
'use client';

import { Card, CardContent } from '@/components/ui/card';
import { getUsersInfo } from '@/lib/contract';
import { useEffect, useState } from 'react';
import { useAccount } from 'wagmi';
import { BuyTickets } from './jackpot-components/buy-tickets';
import { Countdown } from './jackpot-components/countdown';
import { CurrentJackpot } from './jackpot-components/current-jackpot';
import { LastJackpot } from './jackpot-components/last-jackpot';
import { TicketPrice } from './jackpot-components/ticket-price';
import { WinningOdds } from './jackpot-components/winning-odds';
import { WithdrawWinnings } from './jackpot-components/withdraw-winnings';

export function JackpotComponent() {
    const { address, isConnected } = useAccount();

    const [winningsAvailable, setWinningsAvailable] = useState<number>(0);

    useEffect(() => {
        if (!address) return;
        const fetchWinningsAvailable = async () => {
            const usersInfo = await getUsersInfo(address);
            if (!usersInfo) return;
            const winningsAvailable = usersInfo.winningsClaimable;
            setWinningsAvailable(Number(winningsAvailable));
        };
        fetchWinningsAvailable();
    }, [address]);
    return (
        <div className="space-y-6">
            {winningsAvailable > 0 && (
                <WithdrawWinnings winningsAvailable={winningsAvailable} />
            )}

            <CurrentJackpot />

            <Countdown />

            <Card className="bg-white rounded-xl shadow-sm">
                <CardContent className="p-6">
                    <div className="text-center">
                        <TicketPrice />
                        <WinningOdds />
                        {isConnected && address && (
                            <BuyTickets walletAddress={address} />
                        )}
                    </div>
                </CardContent>
            </Card>

            <LastJackpot />
        </div>
    );
}

Buy Tickets

This component will display the current jackpot's size.

Countdown

This component will display a countdown to the next drawing.

Current Jackpot

This component will display the current jackpot's size.

Last Jackpot

This component will display the last jackpot's results.

Ticket Price

This component will display the current ticket price.

Winning Odds

This component will display the odds of winning.

Withdraw Winnings

This component will display the form to withdraw winnings.

API Route

This API route will fetch the past jackpot results from the contract using BaseScan's API.

Last updated