Skip to content

Commit

Permalink
Feat simple nextjs app (#530)
Browse files Browse the repository at this point in the history
* fix: remove apps from turbo (different app can have different ways to compile)

* feat: very simple next app

* feat: add network package

* fix: missing

* fix: disable telemetry
  • Loading branch information
rodolfopietro97 authored Feb 1, 2024
1 parent c08a5cf commit 2a22a5c
Show file tree
Hide file tree
Showing 17 changed files with 3,169 additions and 1 deletion.
3 changes: 3 additions & 0 deletions apps/vechain-sdk-nextjs/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions apps/vechain-sdk-nextjs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
1 change: 1 addition & 0 deletions apps/vechain-sdk-nextjs/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@vechain=https://npm.pkg.github.com
36 changes: 36 additions & 0 deletions apps/vechain-sdk-nextjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
8 changes: 8 additions & 0 deletions apps/vechain-sdk-nextjs/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
env: {
NEXT_TELEMETRY_DISABLED: "1"
}
};

export default nextConfig;
30 changes: 30 additions & 0 deletions apps/vechain-sdk-nextjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "vechain-sdk-nextjs",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"prebuild": "next telemetry disable",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"react": "^18",
"react-dom": "^18",
"next": "14.1.0",
"@vechain/vechain-sdk-core": "*",
"@vechain/vechain-sdk-network": "*"
},
"devDependencies": {
"typescript": "^5",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"autoprefixer": "^10.0.1",
"postcss": "^8",
"tailwindcss": "^3.3.0",
"eslint": "^8",
"eslint-config-next": "14.1.0"
}
}
6 changes: 6 additions & 0 deletions apps/vechain-sdk-nextjs/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
1 change: 1 addition & 0 deletions apps/vechain-sdk-nextjs/public/next.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 apps/vechain-sdk-nextjs/public/vercel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/vechain-sdk-nextjs/src/app/favicon.ico
Binary file not shown.
33 changes: 33 additions & 0 deletions apps/vechain-sdk-nextjs/src/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
}
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}

@layer utilities {
.text-balance {
text-wrap: balance;
}
}
22 changes: 22 additions & 0 deletions apps/vechain-sdk-nextjs/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import './globals.css';

const inter = Inter({ subsets: ['latin'] });

export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app'
};

export default function RootLayout({
children
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
</html>
);
}
101 changes: 101 additions & 0 deletions apps/vechain-sdk-nextjs/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'use client';

import { mnemonic } from '@vechain/vechain-sdk-core';
import { useState } from 'react';
import {
type BlockDetail,
HttpClient,
ThorClient
} from '@vechain/vechain-sdk-network';

/**
* Url of the testnet fixture
*/
const testnetUrl = 'https://testnet.vechain.org';

/**
* Test Network instance fixture
*/
const testNetwork = new HttpClient(testnetUrl);

/**
* Main thor client
*/
const thorClient = new ThorClient(testNetwork);

export default function Home() {
// Random wallet
const [mnemonicWallet, setMnemonicWallet] = useState<string[]>([]);
const generateWallet = (): void => {
setMnemonicWallet(mnemonic.generate());
};

// Block
const [block, setBlock] = useState<BlockDetail | null>(null);

const getLatestBlock = async (): Promise<void> => {
const latestBlock = await thorClient.blocks.getBestBlock();
setBlock(latestBlock);
};

return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
{/* Welcome Header */}
<div>
<header className="flex flex-col items-center justify-center">
<h1 className="text-5xl font-bold">
Welcome to Vechain SDK
</h1>
</header>
</div>

{/* Wallet words */}
<div>
<p className="text-2xl font-bold">
{mnemonicWallet.length > 0
? mnemonicWallet.join(' ')
: 'Click on "Generate Wallet" button'}
</p>
</div>

{/* Block */}
<div>
<p className="text-2xl font-bold">
{block !== null
? block.id
: 'Click on "Get latest block" button'}
</p>
</div>

{/* Generate Wallet button */}
<div className={'flex flex-row justify-end'}>
<div>
<button
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded mx-4"
onClick={() => {
generateWallet();
}}
>
Generate Wallet
</button>
<br />
(vechain-sdk-core)
</div>

{/* Get latest block */}
<div>
<button
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded mx-4"
onClick={async (): Promise<void> => {
await getLatestBlock();
}}
>
Get latest block
</button>
<br />
(vechain-sdk-network)
</div>
</div>
</main>
);
}
20 changes: 20 additions & 0 deletions apps/vechain-sdk-nextjs/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Config } from "tailwindcss";

const config: Config = {
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {
backgroundImage: {
"gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
"gradient-conic":
"conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
},
},
},
plugins: [],
};
export default config;
26 changes: 26 additions & 0 deletions apps/vechain-sdk-nextjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
Loading

1 comment on commit 2a22a5c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Coverage

Summary

Lines Statements Branches Functions
Coverage: 100%
100% (2330/2330) 99.75% (413/414) 99.8% (499/500)
Title Tests Skipped Failures Errors Time
core 406 0 💤 0 ❌ 0 🔥 1m 16s ⏱️
network 192 0 💤 0 ❌ 0 🔥 2m 33s ⏱️
errors 43 0 💤 0 ❌ 0 🔥 9.885s ⏱️

Please sign in to comment.