diff --git a/src/App.tsx b/src/App.tsx index f246106..dbadc2d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,7 +2,7 @@ import "./App.css"; import Game from "./Game"; import { useState, useRef } from "react"; import TitleBar from "./TitleBar"; -import { DefaultProvider, SensiletSigner, PubKey, toHex } from "scrypt-ts"; +import { DefaultProvider, DefaultProviderOption, PandaSigner, PubKey, Signer, bsv, toHex } from "scrypt-ts"; import { TicTacToe } from "./contracts/tictactoe"; const initialGameData = { amount: 0, @@ -19,11 +19,10 @@ const initialGameData = { } function App() { - const [gameData, setGameData] = useState(initialGameData); const [isConnected, setConnected] = useState(false); - const signerRef = useRef(); + const signerRef = useRef(); const [contract, setContract] = useState(undefined) const [deployedTxId, setDeployedTxId] = useState("") const [alicePubkey, setAlicePubkey] = useState(""); @@ -39,11 +38,8 @@ function App() { return } - - try { - const signer = signerRef.current as SensiletSigner; - + const signer = signerRef.current; const instance = new TicTacToe( PubKey(toHex(alicePubkey)), @@ -72,11 +68,13 @@ function App() { setGameData(Object.assign({}, gameData, initialGameData)) }; - const sensiletLogin = async () => { - console.log('sensiletLogin...') + const handleConnect = async () => { try { - const provider = new DefaultProvider(); - const signer = new SensiletSigner(provider); + const provider = new DefaultProvider({ + network: bsv.Networks.testnet + } as DefaultProviderOption); + + const signer = new PandaSigner(provider) signerRef.current = signer; @@ -86,7 +84,7 @@ function App() { } const pubkey = await signer.getDefaultPubKey(); - const changeAccountMessage = "Please change your account in Sensilet wallet, click again to get bob PublicKey"; + const changeAccountMessage = "Please switch wallet and hit the connect button again to get Bob's public key."; if (!alicePubkey) { @@ -113,8 +111,8 @@ function App() { } } catch (error) { - console.error("sensiletLogin failed", error); - alert("sensiletLogin failed") + console.error("Connecting wallet failed", error); + alert("Connecting wallet failed") } }; @@ -128,28 +126,29 @@ function App() { onCancel={cancelGame} started={gameData.start} /> - + { isConnected ? -
- -
- -
- : - +
+ +
+ +
+ : ( + + ) } diff --git a/src/Game.tsx b/src/Game.tsx index 02b3bff..1e0e816 100644 --- a/src/Game.tsx +++ b/src/Game.tsx @@ -44,7 +44,7 @@ function Game(props: any) { return true; } - async function isRightSensiletAccount() { + async function isRightAccount() { const current = props.contract as TicTacToe; const expectedPubkey = current.isAliceTurn ? props.alicePubkey : props.bobPubkey; @@ -81,10 +81,8 @@ function Game(props: any) { const history = gameData.history.slice(0, gameData.currentStepNumber + 1); const current = history[history.length - 1]; const squares = current.squares.slice(); - - const isRightAccount = await isRightSensiletAccount(); - if (!isRightAccount) { + if (!(await isRightAccount())) { alert(`Please switch Sensilet to ${gameData.isAliceTurn ? "Alice" : "Bob"} account!`) return; }