-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: added vite template * feat: added vite template * feat: added vite template * minor changes * feat: change routing to react router * chore: handle dependencies --------- Co-authored-by: Guillermo Alejandro Gallardo Diez <[email protected]> Co-authored-by: Guillermo Alejandro Gallardo Diez <[email protected]>
- Loading branch information
1 parent
01723a6
commit e3982e3
Showing
25 changed files
with
1,029 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import js from '@eslint/js' | ||
import globals from 'globals' | ||
import react from 'eslint-plugin-react' | ||
import reactHooks from 'eslint-plugin-react-hooks' | ||
import reactRefresh from 'eslint-plugin-react-refresh' | ||
|
||
export default [ | ||
{ ignores: ['dist'] }, | ||
{ | ||
files: ['**/*.{js,jsx}'], | ||
languageOptions: { | ||
ecmaVersion: 2020, | ||
globals: globals.browser, | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
ecmaFeatures: { jsx: true }, | ||
sourceType: 'module', | ||
}, | ||
}, | ||
settings: { react: { version: '18.3' } }, | ||
plugins: { | ||
react, | ||
'react-hooks': reactHooks, | ||
'react-refresh': reactRefresh, | ||
}, | ||
rules: { | ||
...js.configs.recommended.rules, | ||
...react.configs.recommended.rules, | ||
...react.configs['jsx-runtime'].rules, | ||
...reactHooks.configs.recommended.rules, | ||
'react/jsx-no-target-blank': 'off', | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, | ||
], | ||
}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title> Near App</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.jsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "hello-near", | ||
"private": true, | ||
"version": "1.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"lint": "eslint .", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@esbuild-plugins/node-globals-polyfill": "^0.2.3", | ||
"@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", | ||
"@wagmi/connectors": "^5.7.1", | ||
"@wagmi/core": "^2.16.1", | ||
"@web3modal/wagmi": "^5.1.11", | ||
"bootstrap": "^5", | ||
"bootstrap-icons": "^1.11.3", | ||
"buffer": "^6.0.3", | ||
"near-api-js": "^4.0.3", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"react-router": "^7.1.1", | ||
"vite-plugin-eslint": "^1.8.1" | ||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^9.17.0", | ||
"@types/react": "^18.3.18", | ||
"@types/react-dom": "^18.3.5", | ||
"@vitejs/plugin-react": "^4.3.4", | ||
"eslint": "^9.17.0", | ||
"eslint-plugin-react": "^7.37.2", | ||
"eslint-plugin-react-hooks": "^5.0.0", | ||
"eslint-plugin-react-refresh": "^0.4.16", | ||
"globals": "^15.14.0", | ||
"vite": "^6.0.5" | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Navigation } from './components/navigation'; | ||
import Home from './pages/home'; | ||
|
||
import HelloNear from './pages/hello_near'; | ||
import { useEffect, useState } from 'react'; | ||
import { NetworkId } from './config.js'; | ||
import { NearContext, Wallet } from '@/wallets/near'; | ||
import { BrowserRouter, Routes, Route } from "react-router"; | ||
|
||
// 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({ networkId: NetworkId, createAccessKeyFor: HelloNearContract }); | ||
|
||
function App() { | ||
const [signedAccountId, setSignedAccountId] = useState(null); | ||
|
||
useEffect(() => { | ||
wallet.startUp(setSignedAccountId); | ||
}, []); | ||
|
||
return ( | ||
<NearContext.Provider value={{ wallet, signedAccountId }}> | ||
<BrowserRouter> | ||
<Navigation /> | ||
<Routes> | ||
<Route path="/" element={<Home />} /> | ||
<Route path="/hello-near" element={<HelloNear />} /> | ||
</Routes> | ||
</BrowserRouter> | ||
</NearContext.Provider> | ||
) | ||
} | ||
|
||
export default App |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import styles from '@/styles/app.module.css'; | ||
import { Link } from 'react-router'; | ||
|
||
export const Cards = () => { | ||
return ( | ||
<div className={styles.grid}> | ||
<a | ||
href="https://docs.near.org/build/web3-apps/quickstart" | ||
className={styles.card} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
<h2> | ||
Near Docs <span>-></span> | ||
</h2> | ||
<p>Learn how this application works, and what you can build on Near.</p> | ||
</a> | ||
|
||
<Link to="/hello-near" className={styles.card} rel="noopener noreferrer"> | ||
<h2> | ||
Near Integration <span>-></span> | ||
</h2> | ||
<p>Discover how simple it is to interact with a Near smart contract.</p> | ||
</Link> | ||
</div> | ||
); | ||
}; |
39 changes: 39 additions & 0 deletions
39
templates/frontend/vite-react/src/components/navigation.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useContext,useEffect, useState } from 'react'; | ||
|
||
import NearLogo from '@/assets/near-logo.svg'; | ||
import { NearContext } from '@/wallets/near'; | ||
import { Link } from "react-router"; | ||
import styles from '@/styles/app.module.css'; | ||
|
||
export const Navigation = () => { | ||
const { signedAccountId, wallet } = useContext(NearContext); | ||
const [action, setAction] = useState(() => {}); | ||
const [label, setLabel] = useState('Loading...'); | ||
|
||
useEffect(() => { | ||
if (!wallet) return; | ||
|
||
if (signedAccountId) { | ||
setAction(() => wallet.signOut); | ||
setLabel(`Logout ${signedAccountId}`); | ||
} else { | ||
setAction(() => wallet.signIn); | ||
setLabel('Login'); | ||
} | ||
}, [signedAccountId, wallet]); | ||
|
||
return ( | ||
<nav className="navbar navbar-expand-lg"> | ||
<div className="container-fluid"> | ||
<Link to="/"> | ||
<img src={NearLogo} alt="NEAR" width="30" height="24" className={styles.logo} /> | ||
</Link> | ||
<div className="navbar-nav pt-1"> | ||
<button className="btn btn-secondary" onClick={action}> | ||
{label} | ||
</button> | ||
</div> | ||
</div> | ||
</nav> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const contractPerNetwork = { | ||
mainnet: 'hello.near-examples.near', | ||
testnet: 'hello.near-examples.testnet', | ||
}; | ||
|
||
// 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 NetworkId = 'testnet'; | ||
export const HelloNearContract = contractPerNetwork[NetworkId]; | ||
export const EVMWalletChain = evmWalletChains[NetworkId]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { StrictMode } from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
import './styles/globals.css'; | ||
import App from './App.jsx'; | ||
|
||
|
||
createRoot(document.getElementById('root')).render( | ||
<StrictMode> | ||
<App /> | ||
</StrictMode>, | ||
); |
Oops, something went wrong.