diff --git a/frontend/package.json b/frontend/package.json index 9114ed9..828218a 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -27,23 +27,15 @@ "@web3modal/wagmi": "^5.1.11", "bootstrap": "^5", "bootstrap-icons": "^1.11.3", - "near-api-js": "^5.0.1", + "near-api-js": "^4.0.3", "next": "14.2.5", "react": "^18", "react-dom": "^18", "wagmi": "^2.13.3" }, - "overrides": { - "@near-wallet-selector/ethereum-wallets": { - "near-api-js": "4.0.3" - } - }, - "resolutions": { - "near-api-js": "4.0.3" - }, "devDependencies": { "encoding": "^0.1.13", - "eslint": "^9", + "eslint": "^8", "eslint-config-next": "14.2.3" } } diff --git a/frontend/src/pages/_app.js b/frontend/src/pages/_app.js index 15ea045..b4ffded 100644 --- a/frontend/src/pages/_app.js +++ b/frontend/src/pages/_app.js @@ -7,14 +7,11 @@ import { Navigation } from '@/components/Navigation'; import { Wallet } from '@/wallets/near'; import { NetworkId, CoinFlipContract } from '@/config'; -// Wallet instance -const wallet = new Wallet({ networkId: NetworkId }); - -// Optional: Create an access key so the user does not need to sign transactions. Read more about access keys here: https://docs.near.org/concepts/protocol/access-keys -// const wallet = new Wallet({ -// createAccessKeyFor: CoinFlipContract, -// networkId: NetworkId, -// }); +// Create an access key so the user does not need to sign transactions. Read more about access keys here: https://docs.near.org/concepts/protocol/access-keys +const wallet = new Wallet({ + createAccessKeyFor: CoinFlipContract, + networkId: NetworkId, +}); export default function MyApp({ Component, pageProps }) { diff --git a/frontend/src/pages/index.js b/frontend/src/pages/index.js index a51e990..885ce83 100644 --- a/frontend/src/pages/index.js +++ b/frontend/src/pages/index.js @@ -13,7 +13,14 @@ export default function Home() { const [choice, setChoice] = useState(); useEffect(() => { - if (signedAccountId) updateScore(); + if (!signedAccountId) return; + + wallet.viewMethod({ + contractId: CoinFlipContract, + method: "points_of", + args: { player: signedAccountId }, + }).then((score) => setPoints(score)) + }, [signedAccountId]); const handleChoice = async (guess) => { @@ -32,24 +39,13 @@ export default function Home() { if (guess === outcome) { setStatus("You were right, you won a point!"); - setPoints(points+1); + setPoints(points + 1); } else { setStatus("You were wrong, you lost a point"); setPoints(points ? points - 1 : 0); } }; - const updateScore = async () => { - - const score = await wallet.viewMethod({ - contractId: CoinFlipContract, - method: "points_of", - args: { player: signedAccountId }, - }); - - setPoints(score); - }; - let color = choice === side ? "btn-success" : "btn-danger"; return ( @@ -68,17 +64,15 @@ export default function Home() {