-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a Vite sample application (#1451)
* feat: add vite blank project * fix: update yarn.lock * fix: add Hash page * fix: add SDK network * fix: complete vite SDK integration * fix: add another example * fix: update tsconfig for vite sample dApp * fix: refactor code * fix: refactor code * fix: refactor code * fix: add tests * fix: fix vitest error * fix: fix error tests * fix: fix error tests * fix: fix error when testing
- Loading branch information
1 parent
c29efb3
commit 2c65ef2
Showing
31 changed files
with
1,408 additions
and
20 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
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,50 @@ | ||
# React + TypeScript + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh | ||
|
||
## Expanding the ESLint configuration | ||
|
||
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: | ||
|
||
- Configure the top-level `parserOptions` property like this: | ||
|
||
```js | ||
export default tseslint.config({ | ||
languageOptions: { | ||
// other options... | ||
parserOptions: { | ||
project: ['./tsconfig.node.json', './tsconfig.app.json'], | ||
tsconfigRootDir: import.meta.dirname, | ||
}, | ||
}, | ||
}) | ||
``` | ||
|
||
- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked` | ||
- Optionally add `...tseslint.configs.stylisticTypeChecked` | ||
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config: | ||
|
||
```js | ||
// eslint.config.js | ||
import react from 'eslint-plugin-react' | ||
|
||
export default tseslint.config({ | ||
// Set the react version | ||
settings: { react: { version: '18.3' } }, | ||
plugins: { | ||
// Add the react plugin | ||
react, | ||
}, | ||
rules: { | ||
// other rules... | ||
// Enable its recommended rules | ||
...react.configs.recommended.rules, | ||
...react.configs['jsx-runtime'].rules, | ||
}, | ||
}) | ||
``` |
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,28 @@ | ||
import js from '@eslint/js' | ||
import globals from 'globals' | ||
import reactHooks from 'eslint-plugin-react-hooks' | ||
import reactRefresh from 'eslint-plugin-react-refresh' | ||
import tseslint from 'typescript-eslint' | ||
|
||
export default tseslint.config( | ||
{ ignores: ['dist'] }, | ||
{ | ||
extends: [js.configs.recommended, ...tseslint.configs.recommended], | ||
files: ['**/*.{ts,tsx}'], | ||
languageOptions: { | ||
ecmaVersion: 2020, | ||
globals: globals.browser, | ||
}, | ||
plugins: { | ||
'react-hooks': reactHooks, | ||
'react-refresh': reactRefresh, | ||
}, | ||
rules: { | ||
...reactHooks.configs.recommended.rules, | ||
'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="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React + TS</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></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,37 @@ | ||
{ | ||
"name": "sdk-vite-integration", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc -b && vite build", | ||
"lint": "eslint .", | ||
"preview": "vite preview", | ||
"test": "vitest" | ||
}, | ||
"dependencies": { | ||
"@vechain/sdk-core": "^1.0.0-beta.32", | ||
"@vechain/sdk-network": "^1.0.0-beta.32", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"react-router-dom": "^6.27.0" | ||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^9.13.0", | ||
"@types/react": "^18.3.11", | ||
"@types/react-dom": "^18.3.1", | ||
"@vitejs/plugin-react": "^4.3.3", | ||
"@vitest/browser": "^2.1.4", | ||
"eslint": "^9.13.0", | ||
"eslint-plugin-react-hooks": "^5.0.0", | ||
"eslint-plugin-react-refresh": "^0.4.13", | ||
"globals": "^15.11.0", | ||
"playwright": "^1.48.2", | ||
"typescript": "~5.6.2", | ||
"typescript-eslint": "^8.10.0", | ||
"vite": "^5.4.10", | ||
"vitest": "^2.1.4", | ||
"vitest-browser-react": "^0.0.3" | ||
} | ||
} |
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,42 @@ | ||
#root { | ||
max-width: 1280px; | ||
margin: 0 auto; | ||
padding: 2rem; | ||
text-align: center; | ||
} | ||
|
||
.logo { | ||
height: 6em; | ||
padding: 1.5em; | ||
will-change: filter; | ||
transition: filter 300ms; | ||
} | ||
.logo:hover { | ||
filter: drop-shadow(0 0 2em #646cffaa); | ||
} | ||
.logo.react:hover { | ||
filter: drop-shadow(0 0 2em #61dafbaa); | ||
} | ||
|
||
@keyframes logo-spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
@media (prefers-reduced-motion: no-preference) { | ||
a:nth-of-type(2) .logo { | ||
animation: logo-spin infinite 20s linear; | ||
} | ||
} | ||
|
||
.card { | ||
padding: 2em; | ||
} | ||
|
||
.read-the-docs { | ||
color: #888; | ||
} |
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,63 @@ | ||
import { BrowserRouter as Router, Route, Routes, Link } from 'react-router-dom'; | ||
import reactLogo from './assets/react.svg'; | ||
import viteLogo from '/vite.svg'; | ||
import './App.css'; | ||
import Hash from './components/Hash'; | ||
import TransferLogs from './components/TransferLogs'; | ||
import GetLastBlock from './components/GetLastBlock'; | ||
|
||
function App() { | ||
return ( | ||
<Router> | ||
<div> | ||
<div> | ||
<a href="https://vite.dev" target="_blank" rel="noopener noreferrer"> | ||
<img src={viteLogo} className="logo" alt="Vite logo" /> | ||
</a> | ||
<a href="https://react.dev" target="_blank" rel="noopener noreferrer"> | ||
<img src={reactLogo} className="logo react" alt="React logo" /> | ||
</a> | ||
</div> | ||
<h2>Welcome to the SDK Vite Integration!</h2> | ||
<div className="card"> | ||
<p> | ||
<b>@vechain/sdk-core</b> integration example:{' '} | ||
<Link | ||
className="text-blue-500 hover:underline" | ||
to="/hash" // Change from href to to for React Router | ||
> | ||
Hash | ||
</Link> | ||
</p> | ||
<p> | ||
<b>@vechain/sdk-network</b> integration example:{' '} | ||
<Link | ||
className="text-blue-500 hover:underline" | ||
to='/transfer-logs' | ||
> | ||
Transfer logs | ||
</Link> | ||
</p> | ||
<p> | ||
<b>@vechain/sdk-network</b> integration example:{' '} | ||
<Link | ||
className="text-blue-500 hover:underline" | ||
to='/get-last-block' | ||
> | ||
Get Last Block | ||
</Link> | ||
</p> | ||
</div> | ||
</div> | ||
|
||
{/* Define Routes */} | ||
<Routes> | ||
<Route path="/hash" element={<Hash />} /> | ||
<Route path="/transfer-logs" element={<TransferLogs />} /> | ||
<Route path="/get-last-block" element={<GetLastBlock />} /> | ||
</Routes> | ||
</Router> | ||
); | ||
} | ||
|
||
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.
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 { type CompressedBlockDetail, ThorClient } from "@vechain/sdk-network"; | ||
import { useState } from "react"; | ||
|
||
const GetLastBlock = () => { | ||
const [block, setBlock] = useState<CompressedBlockDetail | null>(null); | ||
|
||
// URL of the VeChain mainnet | ||
const mainnetUrl = 'https://mainnet.vechain.org'; | ||
|
||
// Thor client instance | ||
const thorClient = ThorClient.fromUrl(mainnetUrl); | ||
|
||
// Function to fetch the last block | ||
const fetchLastBlock = async () => { | ||
try { | ||
const lastBlock = await thorClient.blocks.getBlockCompressed("best"); | ||
setBlock(lastBlock); | ||
} catch (error) { | ||
console.error("Error fetching the last block:", error); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<button onClick={fetchLastBlock}> | ||
Get Last Block | ||
</button> | ||
{block && ( | ||
<div> | ||
<h3>Last Block Details:</h3> | ||
<pre>{JSON.stringify(block, null, 2)}</pre> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default GetLastBlock; |
Oops, something went wrong.
2c65ef2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test Coverage
Summary