diff --git a/.gitignore b/.gitignore index f936439..80f7429 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/components/LotteryHistory.tsx b/components/LotteryHistory.tsx new file mode 100644 index 0000000..f6de725 --- /dev/null +++ b/components/LotteryHistory.tsx @@ -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([]); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(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
Loading lottery history...
; + if (error) return
Error: {error}
; + + return ( +
+

Lottery History

+ {history.length === 0 ? ( +

No past lottery rounds found.

+ ) : ( + + + + + + + + + + + {history.map((round) => ( + + + + + + + ))} + +
RoundDateWinnerPot Size
{round.roundId}{round.timestamp.toLocaleDateString()}{round.winner}{round.potSize} ETH
+ )} +
+ ); +}; + +export default LotteryHistory; \ No newline at end of file diff --git a/package.json b/package.json index 061bbf1..503ce8e 100644 --- a/package.json +++ b/package.json @@ -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" } -} +} \ No newline at end of file