Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 7 additions & 49 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,50 +1,8 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/blockchain/node_modules
/.pnp
.pnp.js

# vscode
.vscode

# hardhat
artifacts
cache
deployments
cache/
coverage*
blockchain/typechain-types/@chainlink
blockchain/typechain-types/@openzeppelin
blockchain/typechain-types/factories/@chainlink
blockchain/typechain-types/factories/@openzeppelin

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
node_modules/
.next/
dist/
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
*.log
.DS_Store
*.swp
.vercel
73 changes: 73 additions & 0 deletions components/LotteryHistory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React, { useState, useEffect } from 'react';
import { useLotteryContext } from '../context/context';
import styles from '../styles/LotteryHistory.module.css';

interface LotteryRound {
roundId: number;
timestamp: Date;
winner: string;
potSize: string;
}

const LotteryHistory: React.FC = () => {
const [history, setHistory] = useState<LotteryRound[]>([]);
const [loading, setLoading] = useState<boolean>(true);
const [error, setError] = useState<string | null>(null);

const { lotteryContract } = useLotteryContext();

useEffect(() => {
const fetchLotteryHistory = async () => {
try {
if (!lotteryContract) {
throw new Error('Lottery contract not initialized');
}

// Simulated fetch - replace with actual contract method
const rounds: LotteryRound[] = await lotteryContract.getPastRounds();
setHistory(rounds);
setLoading(false);
} catch (err) {
setError(err instanceof Error ? err.message : 'Unknown error');
setLoading(false);
}
};

fetchLotteryHistory();
}, [lotteryContract]);

if (loading) return <div>Loading lottery history...</div>;
if (error) return <div>Error: {error}</div>;

return (
<div className={styles.historyContainer}>
<h2>Lottery History</h2>
{history.length === 0 ? (
<p>No past lottery rounds found.</p>
) : (
<table className={styles.historyTable}>
<thead>
<tr>
<th>Round</th>
<th>Date</th>
<th>Winner</th>
<th>Pot Size</th>
</tr>
</thead>
<tbody>
{history.map((round) => (
<tr key={round.roundId}>
<td>{round.roundId}</td>
<td>{round.timestamp.toLocaleDateString()}</td>
<td>{round.winner}</td>
<td>{round.potSize} ETH</td>
</tr>
))}
</tbody>
</table>
)}
</div>
);
};

export default LotteryHistory;
34 changes: 11 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
{
"name": "lottery",
"version": "0.1.0",
"private": true,
"name": "lottery-frontend",
"version": "1.0.0",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"deploy:sepolia": "cd blockchain && npx hardhat run scripts/deploy.ts --network sepolia && cd .."
"test": "vitest"
},
"dependencies": {
"@chainlink/contracts": "^0.6.1",
"@formkit/auto-animate": "^1.0.0-beta.6",
"@openzeppelin/contracts": "^4.8.2",
"dotenv": "^16.0.3",
"next": "12.2.5",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hot-toast": "^2.4.0",
"truncate-eth-address": "^1.0.2",
"web3": "^1.7.5"
"next": "^13.4.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
"@types/node": "^18.15.3",
"@types/react": "^18.0.28",
"eslint": "8.21.0",
"eslint-config-next": "12.2.5",
"hardhat": "^2.13.0",
"typescript": "^5.0.2"
"@types/node": "^20.3.1",
"@types/react": "^18.2.12",
"typescript": "^5.1.3",
"vitest": "^0.32.2"
}
}
}