Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillermo Alejandro Gallardo Diez authored and Guillermo Alejandro Gallardo Diez committed Jan 4, 2025
1 parent 415b070 commit b7ced3d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 37 deletions.
12 changes: 2 additions & 10 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
13 changes: 5 additions & 8 deletions frontend/src/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down
32 changes: 13 additions & 19 deletions frontend/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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 (
Expand All @@ -68,17 +64,15 @@ export default function Home() {
</h2>
<div className="d-flex justify-content-center">
<button
className={`btn me-2 ${
choice === "heads" && side !== 'loading' ? color : "btn-primary"
}`}
className={`btn me-2 ${choice === "heads" && side !== 'loading' ? color : "btn-primary"
}`}
onClick={() => handleChoice("heads")}
>
Heads
</button>
<button
className={`btn ${
choice === "tails" && side !== 'loading' ? color : "btn-primary"
}`}
className={`btn ${choice === "tails" && side !== 'loading' ? color : "btn-primary"
}`}
onClick={() => handleChoice("tails")}
>
Tails
Expand Down

0 comments on commit b7ced3d

Please sign in to comment.