reward distribution v1

This commit is contained in:
Sewmina 2025-04-05 22:01:57 +05:30
parent a78c8db008
commit c37f8f7457
9 changed files with 35 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@ -8,12 +8,13 @@ import { HowItWorksModal } from "./HowItWorksModal";
import YourGames from "./YourGames";
import { Bet } from "@/types/Bet";
import { fetchOpenBets } from "@/shared/solana_helpers";
import { usePrivy, useSolanaWallets } from "@privy-io/react-auth";
import { ConnectedSolanaWallet, usePrivy, useSolanaWallets } from "@privy-io/react-auth";
export default function HeroSection() {
const [isModalOpen, setIsModalOpen] = useState(false);
const [isGameModalOpen, setIsGameModalOpen] = useState(false);
const [bets, setBets] = useState<Bet[]>([]);
const [solWallet, setSolWallet] = useState<ConnectedSolanaWallet>();
const [myActiveBet, setMyActiveBet] = useState<Bet>();
const { wallets, ready } = useSolanaWallets();
const {user} = usePrivy();
@ -22,8 +23,8 @@ export default function HeroSection() {
if (!ready || wallets.length === 0) return;
// Find the wallet to use (either Solana wallet or the first available wallet)
let wallet = wallets.find((_wallet) => _wallet.type === "solana") || wallets[0];
const wallet = wallets.find((_wallet) => _wallet.type === "solana") || wallets[0];
setSolWallet(wallet);
// Fetch the open bets
const fetchedBets = await fetchOpenBets(wallet);
@ -62,7 +63,7 @@ export default function HeroSection() {
// Render Unity WebGL game when myActiveBet is found
<div className="w-full h-screen flex justify-center items-center bg-black">
<iframe
src={`/UnityBuild/${myActiveBet.id}/index.html?betId=${myActiveBet.id}&owner=${myActiveBet.owner_id}&joiner=${myActiveBet.joiner_id}&address=${myActiveBet.address}`} // Change this to the actual path of your Unity WebGL build
src={`/UnityBuild/${myActiveBet.id}/index.html?betId=${myActiveBet.id}&owner=${myActiveBet.owner_id}&joiner=${myActiveBet.joiner_id}&address=${myActiveBet.address}&uid=${user?.id}&pubkey=${solWallet?.address}`} // Change this to the actual path of your Unity WebGL build
className="w-full h-full"
allowFullScreen
/>

View File

@ -120,7 +120,7 @@ export default function YourGames({ bets }: GameModalProps) {
<div className="flex justify-between text-xs font-mono py-1">
<p className="text-white">{bet.wager} SOL</p>
<p className="text-white">{(bet.wager * 2).toFixed(2)} SOL</p>
<p className="text-white">{(bet.wager * 2 * 0.95).toFixed(2)} SOL</p>
</div>
{bet.ownerProfile && (

View File

@ -34,6 +34,10 @@ export type Bets = {
"name": "betVault",
"writable": true
},
{
"name": "feeWallet",
"writable": true
},
{
"name": "winner",
"writable": true
@ -252,8 +256,8 @@ export type Bets = {
"errors": [
{
"code": 6000,
"name": "betNotFilled",
"msg": "Bet is not filled yet!"
"name": "customError",
"msg": "Custom error message"
}
],
"types": [
@ -305,6 +309,11 @@ export type Bets = {
}
],
"constants": [
{
"name": "feeCollector",
"type": "string",
"value": "\"cocD4r4yNpHxPq7CzUebxEMyLki3X4d2Y3HcTX5ptUc\""
},
{
"name": "seed",
"type": "string",

View File

@ -28,6 +28,10 @@
"name": "bet_vault",
"writable": true
},
{
"name": "fee_wallet",
"writable": true
},
{
"name": "winner",
"writable": true
@ -246,8 +250,8 @@
"errors": [
{
"code": 6000,
"name": "BetNotFilled",
"msg": "Bet is not filled yet!"
"name": "CustomError",
"msg": "Custom error message"
}
],
"types": [
@ -299,10 +303,15 @@
}
],
"constants": [
{
"name": "FEE_COLLECTOR",
"type": "string",
"value": "\"cocD4r4yNpHxPq7CzUebxEMyLki3X4d2Y3HcTX5ptUc\""
},
{
"name": "SEED",
"type": "string",
"value": "\"anchor\""
}
]
}
}

3
src/shared/constants.ts Normal file
View File

@ -0,0 +1,3 @@
import { PublicKey } from "@solana/web3.js";
export const FEE_COLLECTOR_PUBKEY = new PublicKey("cocD4r4yNpHxPq7CzUebxEMyLki3X4d2Y3HcTX5ptUc");

View File

@ -7,6 +7,7 @@ import idl from "../idl/bets_idl.json";
import { Bet } from "@/types/Bet";
import { toast } from "sonner";
import { Game } from "@/types/Game";
import { FEE_COLLECTOR_PUBKEY } from "./constants";
export const fetchOpenBets = async (wallets: ConnectedSolanaWallet): Promise<Bet[]> => {
try {
@ -101,6 +102,7 @@ export const fetchOpenBets = async (wallets: ConnectedSolanaWallet): Promise<Bet
betVault: chosenBet,
betsList: bet_list_pda,
winner: winner,
feeWallet: FEE_COLLECTOR_PUBKEY
})
.transaction();
tx.feePayer = new PublicKey(wallets.address);