Skip to content

Commit

Permalink
feat: added vite template
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasbenary committed Dec 23, 2024
1 parent 01723a6 commit 5fefee5
Show file tree
Hide file tree
Showing 20 changed files with 1,035 additions and 0 deletions.
24 changes: 24 additions & 0 deletions templates/frontend/vite/.gitignore
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?
38 changes: 38 additions & 0 deletions templates/frontend/vite/eslint.config.js
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 },
],
},
},
]
13 changes: 13 additions & 0 deletions templates/frontend/vite/index.html
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="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
59 changes: 59 additions & 0 deletions templates/frontend/vite/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "hello-near",
"private": true,
"version": "0.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": "^5.0.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^7.1.0",
"wagmi": "^2.14.4",
"wouter": "^3.3.5"
},
"overrides": {
"@near-wallet-selector/ethereum-wallets": {
"near-api-js": "4.0.3"
}
},
"devDependencies": {
"@eslint/js": "^9.17.0",
"@types/node": "^22.10.1",
"@types/react": "^18.3.17",
"@types/react-dom": "^18.3.5",
"@vitejs/plugin-react-swc": "^3.5.0",
"encoding": "^0.1.13",
"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.13.0",
"vite": "^6.0.3",
"vite-plugin-eslint": "^1.8.1"
}
}
1 change: 1 addition & 0 deletions templates/frontend/vite/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions templates/frontend/vite/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Navigation } from './components/navigation';
import Home from './pages/home';
import { Route } from 'wouter';
import HelloNear from './pages/hello_near';

function App() {

return (
<>
<Navigation />
<Route path="/" component={Home} />
<Route path="/hello-near" component={HelloNear}/>
</>
)
}

export default App
43 changes: 43 additions & 0 deletions templates/frontend/vite/src/assets/near-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions templates/frontend/vite/src/assets/near.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions templates/frontend/vite/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions templates/frontend/vite/src/components/cards.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import styles from '@/styles/app.module.css';

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>-&gt;</span>
</h2>
<p>Learn how this application works, and what you can build on Near.</p>
</a>

<a href="/hello-near" className={styles.card} rel="noopener noreferrer">
<h2>
Near Integration <span>-&gt;</span>
</h2>
<p>Discover how simple it is to interact with a Near smart contract.</p>
</a>
</div>
);
};
39 changes: 39 additions & 0 deletions templates/frontend/vite/src/components/navigation.jsx
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 'wouter';
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 href="/">
<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>
);
};
24 changes: 24 additions & 0 deletions templates/frontend/vite/src/config.js
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];
32 changes: 32 additions & 0 deletions templates/frontend/vite/src/main.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { StrictMode, useEffect, useState } from 'react';
import { createRoot } from 'react-dom/client';
import './styles/globals.css';
import { NearContext, Wallet } from '@/wallets/near';
import App from './App.jsx';
import { NetworkId } from './config.js';

// 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 });

const Root = () => {
const [signedAccountId, setSignedAccountId] = useState(null);

useEffect(() => {
wallet.startUp(setSignedAccountId);
}, []);

return (
<NearContext.Provider value={{ wallet, signedAccountId }}>
<App />
</NearContext.Provider>
);
};

createRoot(document.getElementById('root')).render(
<StrictMode>
<Root />
</StrictMode>,
);
Loading

0 comments on commit 5fefee5

Please sign in to comment.