Skip to content

Commit cab41b1

Browse files
Feature/with vite react (#1329)
* Add working vite example * Add exclude dep * minor updates
1 parent 5076ff6 commit cab41b1

File tree

17 files changed

+10266
-0
lines changed

17 files changed

+10266
-0
lines changed

examples/with-vite-react/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

examples/with-vite-react/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# with-vite-react

examples/with-vite-react/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/blocknative.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + Web3-Onboard + React + TS</title>
8+
9+
</head>
10+
<body>
11+
<div id="root"></div>
12+
<script type="module" src="/src/main.tsx"></script>
13+
</body>
14+
</html>

examples/with-vite-react/package.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "with-vite-react",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "tsc && vite build",
9+
"preview": "vite preview"
10+
},
11+
"dependencies": {
12+
"@web3-onboard/coinbase": "^2.1.3",
13+
"@web3-onboard/dcent": "^2.2.1",
14+
"@web3-onboard/fortmatic": "^2.0.14",
15+
"@web3-onboard/gnosis": "^2.1.3",
16+
"@web3-onboard/injected-wallets": "^2.2.4",
17+
"@web3-onboard/keepkey": "^2.3.1",
18+
"@web3-onboard/keystone": "^2.3.1",
19+
"@web3-onboard/ledger": "^2.3.1",
20+
"@web3-onboard/magic": "^2.1.3",
21+
"@web3-onboard/mew": "^2.1.3",
22+
"@web3-onboard/portis": "^2.1.3",
23+
"@web3-onboard/react": "^2.3.5",
24+
"@web3-onboard/sequence": "^2.0.2",
25+
"@web3-onboard/tallyho": "^2.0.1",
26+
"@web3-onboard/torus": "^2.1.3",
27+
"@web3-onboard/trezor": "^2.3.1",
28+
"@web3-onboard/walletconnect": "^2.1.3",
29+
"react": "^18.2.0",
30+
"react-dom": "^18.2.0"
31+
},
32+
"devDependencies": {
33+
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
34+
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
35+
"@types/react": "^18.0.17",
36+
"@types/react-dom": "^18.0.6",
37+
"@vitejs/plugin-react": "^2.1.0",
38+
"buffer": "^6.0.3",
39+
"node-stdlib-browser": "^1.2.0",
40+
"typescript": "^4.6.4",
41+
"vite": "^3.1.8",
42+
"vite-plugin-node-stdlib-browser": "^0.1.1"
43+
}
44+
}
Lines changed: 16 additions & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

examples/with-vite-react/src/App.css

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#root {
2+
max-width: 1280px;
3+
margin: 0 auto;
4+
padding: 2rem;
5+
text-align: center;
6+
}
7+
8+
.logo {
9+
height: 6em;
10+
padding: 1.5em;
11+
will-change: filter;
12+
}
13+
.logo:hover {
14+
filter: drop-shadow(0 0 2em #646cffaa);
15+
}
16+
.logo.react:hover {
17+
filter: drop-shadow(0 0 2em #61dafbaa);
18+
}
19+
20+
.logo.blocknative:hover {
21+
filter: drop-shadow(0 0 2em #5e93efaa);
22+
}
23+
24+
@keyframes logo-spin {
25+
from {
26+
transform: rotate(0deg);
27+
}
28+
to {
29+
transform: rotate(360deg);
30+
}
31+
}
32+
33+
@media (prefers-reduced-motion: no-preference) {
34+
a:nth-of-type(2) .logo {
35+
animation: logo-spin infinite 20s linear;
36+
}
37+
}
38+
39+
.card {
40+
padding: 2em;
41+
}
42+
43+
.read-the-docs {
44+
color: #888;
45+
}

examples/with-vite-react/src/App.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { useState } from 'react'
2+
import reactLogo from './assets/react.svg'
3+
import './App.css'
4+
5+
import web3Onboard from './web3-onboard'
6+
import { useConnectWallet } from '@web3-onboard/react'
7+
8+
function App() {
9+
const [count, setCount] = useState(0)
10+
11+
const [{ wallet, connecting }, connect, disconnect] = useConnectWallet()
12+
13+
return (
14+
<div className="App">
15+
<div>
16+
<a href="https://onboard.blocknative.com" target="_blank">
17+
<img
18+
src="/blocknative.svg"
19+
className="logo blocknative"
20+
alt="Blocknative logo"
21+
/>
22+
</a>
23+
<a href="https://vitejs.dev" target="_blank">
24+
<img src="/vite.svg" className="logo" alt="Vite logo" />
25+
</a>
26+
<a href="https://reactjs.org" target="_blank">
27+
<img src={reactLogo} className="logo react" alt="React logo" />
28+
</a>
29+
</div>
30+
<h1>Web3-Onboard + Vite + React</h1>
31+
<div className="card">
32+
<button onClick={() => connect()}>connect</button>
33+
<p>
34+
Edit <code>src/App.tsx</code> and save to test HMR
35+
</p>
36+
</div>
37+
<p className="read-the-docs">
38+
Click on the Blocknative, Vite and React logos to learn more
39+
</p>
40+
</div>
41+
)
42+
}
43+
44+
export default App
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
:root {
2+
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
3+
font-size: 16px;
4+
line-height: 24px;
5+
font-weight: 400;
6+
7+
color-scheme: light dark;
8+
color: rgba(255, 255, 255, 0.87);
9+
background-color: #242424;
10+
11+
font-synthesis: none;
12+
text-rendering: optimizeLegibility;
13+
-webkit-font-smoothing: antialiased;
14+
-moz-osx-font-smoothing: grayscale;
15+
-webkit-text-size-adjust: 100%;
16+
}
17+
18+
a {
19+
font-weight: 500;
20+
color: #646cff;
21+
text-decoration: inherit;
22+
}
23+
a:hover {
24+
color: #535bf2;
25+
}
26+
27+
body {
28+
margin: 0;
29+
display: flex;
30+
place-items: center;
31+
min-width: 320px;
32+
min-height: 100vh;
33+
}
34+
35+
h1 {
36+
font-size: 3.2em;
37+
line-height: 1.1;
38+
}
39+
40+
button {
41+
border-radius: 8px;
42+
border: 1px solid transparent;
43+
padding: 0.6em 1.2em;
44+
font-size: 1em;
45+
font-weight: 500;
46+
font-family: inherit;
47+
background-color: #1a1a1a;
48+
cursor: pointer;
49+
transition: border-color 0.25s;
50+
}
51+
button:hover {
52+
border-color: #646cff;
53+
}
54+
button:focus,
55+
button:focus-visible {
56+
outline: 4px auto -webkit-focus-ring-color;
57+
}
58+
59+
@media (prefers-color-scheme: light) {
60+
:root {
61+
color: #213547;
62+
background-color: #ffffff;
63+
}
64+
a:hover {
65+
color: #747bff;
66+
}
67+
button {
68+
background-color: #f9f9f9;
69+
}
70+
}

examples/with-vite-react/src/main.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react'
2+
import ReactDOM from 'react-dom/client'
3+
import { Web3OnboardProvider } from '@web3-onboard/react'
4+
import web3Onboard from './web3-onboard'
5+
import App from './App'
6+
import './index.css'
7+
8+
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
9+
<React.StrictMode>
10+
<Web3OnboardProvider web3Onboard={web3Onboard}>
11+
<App />
12+
</Web3OnboardProvider>
13+
</React.StrictMode>
14+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />

0 commit comments

Comments
 (0)