From 81248c094f4cba251225c4f5d741623bfdc8cc2c Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Thu, 2 May 2024 23:33:31 -0500 Subject: [PATCH 01/11] feat: work in progress...developing --- contracts/src/models/utils.cairo | 12 ++++++++++++ contracts/src/systems/actions.cairo | 2 ++ 2 files changed, 14 insertions(+) create mode 100644 contracts/src/models/utils.cairo diff --git a/contracts/src/models/utils.cairo b/contracts/src/models/utils.cairo new file mode 100644 index 0000000..3712c0a --- /dev/null +++ b/contracts/src/models/utils.cairo @@ -0,0 +1,12 @@ +#[derive(Copy, Drop, Print, Serde, PartialEq)] +enum Winner { + A, + B, + Draw +} + +#[derive(Copy, Drop, Print, Serde, PartialEq)] +enum Status { + Running, + Finished: Winner +} \ No newline at end of file diff --git a/contracts/src/systems/actions.cairo b/contracts/src/systems/actions.cairo index ec7f1e5..14127da 100644 --- a/contracts/src/systems/actions.cairo +++ b/contracts/src/systems/actions.cairo @@ -3,6 +3,8 @@ use starknet::ContractAddress; #[dojo::interface] trait IActions { fn spawn(player_one: ContractAddress, player_two: ContractAddress) -> u32; + fn play_turn(game_id: u32, player: ContractAddress, pit: u8); + fn capture(game_id: u32, player: ContractAddress, pit: u8); } #[dojo::contract] From 81330fa26e3d8503186d2cd4e05995f8f5345f8c Mon Sep 17 00:00:00 2001 From: supreme2580 Date: Thu, 16 May 2024 21:37:16 +0100 Subject: [PATCH 02/11] integrate starknet id --- client/package.json | 3 +- client/src/App.tsx | 36 +++++++++++++++++------ client/src/atom/atoms.ts | 2 ++ client/src/pages/Leaderboard.tsx | 49 ++++++++++++++++++++++---------- client/yarn.lock | 23 +++++++++------ 5 files changed, 80 insertions(+), 33 deletions(-) diff --git a/client/package.json b/client/package.json index 91374f1..00f1dad 100644 --- a/client/package.json +++ b/client/package.json @@ -42,7 +42,8 @@ "react-dom": "^18.2.0", "react-router-dom": "^6.23.1", "rxjs": "^7.8.1", - "starknet": "^6.1.5", + "starknet": "^6.8.0", + "starknetid.js": "^3.2.0", "starknetkit": "^1.1.9", "tailwind-merge": "^2.2.2", "tailwindcss-animate": "^1.0.7", diff --git a/client/src/App.tsx b/client/src/App.tsx index 9e50f8e..fc5223b 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -4,16 +4,36 @@ import { BrowserRouter, Routes, Route } from "react-router-dom" import Home from "./pages/Home" import Leaderboard from "./pages/Leaderboard" import { Provider as JotaiProvider } from "jotai"; +import { argent, braavos, publicProvider, StarknetConfig, useInjectedConnectors, voyager } from "@starknet-react/core"; +import { mainnet, sepolia } from "@starknet-react/chains"; export default function App() { + const { connectors } = useInjectedConnectors({ + // Show these connectors if the user has no connector installed. + recommended: [ + argent(), + braavos(), + ], + // Hide recommended connectors if the user has any connector installed. + includeRecommended: "onlyIfNoConnectors", + // Randomize the order of the connectors. + order: "random" + }); return ( - - - - } /> - } /> - - - + + + + + } /> + } /> + + + + ) } \ No newline at end of file diff --git a/client/src/atom/atoms.ts b/client/src/atom/atoms.ts index 5e5faf9..b3b1231 100644 --- a/client/src/atom/atoms.ts +++ b/client/src/atom/atoms.ts @@ -1,3 +1,5 @@ import { atom } from 'jotai' export const isPlaying = atom(false) +export const profileData = atom({}) +export const address = atom('') diff --git a/client/src/pages/Leaderboard.tsx b/client/src/pages/Leaderboard.tsx index 09bcedf..2aa6b37 100644 --- a/client/src/pages/Leaderboard.tsx +++ b/client/src/pages/Leaderboard.tsx @@ -1,5 +1,4 @@ - -import React, { useEffect, useRef } from "react"; +import { useEffect, useRef } from "react"; import { Button } from "@material-tailwind/react"; import eniola from "../assets/eniola.png"; @@ -12,19 +11,35 @@ import { Card, Typography } from "@material-tailwind/react"; import clsx from "clsx"; import { stats, table_head } from "@/lib/constants"; import { useAtom } from "jotai"; -import { isPlaying as isPlayingAtom } from "../atom/atoms"; +import { isPlaying as isPlayingAtom, profileData as profileDataAtom, address as addressAtom } from "../atom/atoms"; import audio from "../music/audio_1.mp3"; +import { useProvider } from "@starknet-react/core"; +import { StarknetIdNavigator } from "starknetid.js"; +import { constants, type StarkProfile } from "starknet"; export default function Leaderboard() { const [connection, setConnection] = useState(); - const [address, setAddress] = useState(); + const [address, setAddress] = useAtom(addressAtom); + const [profileData, setProfileData] = useAtom(profileDataAtom) + + const { provider } = useProvider(); + const starknetIdNavigator = new StarknetIdNavigator( + provider, + constants.StarknetChainId.SN_MAIN + ); + const connectWallet = async () => { await connect({ modalMode: "neverAsk" }) const { wallet } = await connect({ modalMode: "canAsk" }) if (wallet && wallet.isConnected) { + const starkProfile = await starknetIdNavigator.getProfileData("0x0643948eef68D67CBd9A1853b6181B83f15D06953724Fd5347e922d40245B93C"); setConnection(wallet); + setProfileData({ + ...starkProfile, + }) setAddress(wallet.selectedAddress); } + console.log(profileData) } const disconnectWallet = async () => { await disconnect(); @@ -55,18 +70,22 @@ export default function Leaderboard() {