diff --git a/contract-rs/Cargo.toml b/contract-rs/Cargo.toml index 350bb9d..984f1e7 100644 --- a/contract-rs/Cargo.toml +++ b/contract-rs/Cargo.toml @@ -13,11 +13,11 @@ crate-type = ["cdylib", "rlib"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -near-sdk = { version = "5.1.0", features = ["legacy"] } +near-sdk = { version = "5.7.0", features = ["legacy"] } [dev-dependencies] -near-sdk = { version = "5.1.0", features = ["unit-testing"] } -near-workspaces = { version = "0.10.0", features = ["unstable"] } +near-sdk = { version = "5.7.0", features = ["unit-testing"] } +near-workspaces = { version = "0.16.0", features = ["unstable"] } tokio = { version = "1.12.0", features = ["full"] } serde_json = "1" diff --git a/frontend/package.json b/frontend/package.json index 0f31183..828218a 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -12,21 +12,29 @@ "lint": "next lint" }, "dependencies": { - "@near-wallet-selector/core": "^8.9.11", - "@near-wallet-selector/here-wallet": "^8.9.11", - "@near-wallet-selector/modal-ui": "^8.9.11", - "@near-wallet-selector/my-near-wallet": "^8.9.11", + "@near-js/providers": "^1.0.1", + "@near-wallet-selector/bitte-wallet": "^8.9.14", + "@near-wallet-selector/core": "^8.9.14", + "@near-wallet-selector/ethereum-wallets": "^8.9.14", + "@near-wallet-selector/here-wallet": "^8.9.14", + "@near-wallet-selector/ledger": "^8.9.14", + "@near-wallet-selector/meteor-wallet": "^8.9.14", + "@near-wallet-selector/modal-ui": "^8.9.14", + "@near-wallet-selector/my-near-wallet": "^8.9.14", + "@near-wallet-selector/near-mobile-wallet": "^8.9.14", + "@near-wallet-selector/sender": "^8.9.14", + "@near-wallet-selector/welldone-wallet": "^8.9.14", + "@web3modal/wagmi": "^5.1.11", "bootstrap": "^5", "bootstrap-icons": "^1.11.3", "near-api-js": "^4.0.3", - "next": "14.2.3", + "next": "14.2.5", "react": "^18", - "react-dom": "^18" + "react-dom": "^18", + "wagmi": "^2.13.3" }, - "resolutions": { - "near-api-js": "4.0.3" - }, "devDependencies": { + "encoding": "^0.1.13", "eslint": "^8", "eslint-config-next": "14.2.3" } diff --git a/frontend/src/config.js b/frontend/src/config.js index 571fab8..b03b8dd 100644 --- a/frontend/src/config.js +++ b/frontend/src/config.js @@ -4,3 +4,23 @@ const contractPerNetwork = { export const NetworkId = "testnet"; export const CoinFlipContract = contractPerNetwork[NetworkId]; + +// Chains for EVM Wallets +const evmWalletChains = { + mainnet: { + chainId: 397, + name: 'Near Mainnet', + explorer: 'https://eth-explorer.near.org', + rpc: 'https://eth-rpc.mainnet.near.org', + }, + testnet: { + chainId: 398, + name: 'Near Testnet', + explorer: 'https://eth-explorer-testnet.near.org', + rpc: 'https://eth-rpc.testnet.near.org', + }, + }; + + + export const EVMWalletChain = evmWalletChains[NetworkId]; + \ No newline at end of file diff --git a/frontend/src/pages/_app.js b/frontend/src/pages/_app.js index a967392..b4ffded 100644 --- a/frontend/src/pages/_app.js +++ b/frontend/src/pages/_app.js @@ -7,7 +7,12 @@ import { Navigation } from '@/components/Navigation'; import { Wallet } from '@/wallets/near'; import { NetworkId, CoinFlipContract } from '@/config'; -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 }) { const [signedAccountId, setSignedAccountId] = useState(''); diff --git a/frontend/src/pages/index.js b/frontend/src/pages/index.js index d4c8660..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,22 +39,11 @@ export default function Home() { if (guess === outcome) { setStatus("You were right, you won a point!"); + setPoints(points + 1); } else { setStatus("You were wrong, you lost a point"); + setPoints(points ? points - 1 : 0); } - - updateScore(); - }; - - 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"; @@ -68,17 +64,15 @@ export default function Home() {