Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Next.js playground with turborepo integration #1198

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,6 @@ packages/devreact/webpack.config.json

# Local Netlify folder
.netlify

# Turborepo
.turbo
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"packages/devexpo",
"packages/devreactnative",
"packages/devnext",
"packages/deve2e"
"packages/deve2e",
"packages/playground-next"
],
"scripts": {
"build": "yarn install && cd packages/sdk-socket-server-next && yarn install && cd ../.. && yarn workspaces foreach --verbose run build:pre-tsc && yarn workspaces foreach --verbose --topological --parallel --no-private run build && yarn workspaces foreach --verbose run build:post-tsc ",
Expand All @@ -33,6 +34,7 @@
"postinstall": "patch-package",
"link-packages": "./scripts/link-packages.sh",
"prepare": "husky install",
"dev:core": "turbo run dev --parallel --filter=@metamask/sdk-communication-layer --filter=@metamask/sdk --filter=@metamask/sdk-react",
"lint": "yarn workspaces foreach --no-private run lint",
"lint:changelogs": "yarn workspaces foreach --no-private run lint:changelog",
"lint:eslint": "yarn workspaces foreach --no-private run lint:eslint",
Expand Down Expand Up @@ -86,6 +88,8 @@
"rimraf": "^3.0.2",
"serve": "^14.2.1",
"ts-jest": "^29.0.3",
"turbo": "^2.3.3",
"turborepo": "^0.0.1",
"typescript": "^4.3.5"
},
"engines": {
Expand Down
41 changes: 41 additions & 0 deletions packages/playground-next/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

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

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions packages/playground-next/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://nextjs.org/docs/app/api-reference/cli/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/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.

## 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/app/building-your-application/deploying) for more details.
16 changes: 16 additions & 0 deletions packages/playground-next/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { dirname } from "path";
import { fileURLToPath } from "url";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname,
});

const eslintConfig = [
...compat.extends("next/core-web-vitals", "next/typescript"),
];

export default eslintConfig;
7 changes: 7 additions & 0 deletions packages/playground-next/next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
/* config options here */
};

export default nextConfig;
27 changes: 27 additions & 0 deletions packages/playground-next/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "playground-next",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev --turbopack",
"build": "next build",
"start": "next start",
"lint": "next lint",
"allow-scripts": "echo 'NA'"
},
"dependencies": {
"@metamask/sdk-react": "workspace:^",
"next": "15.1.4",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint-config-next": "15.1.4",
"typescript": "^5"
}
}
1 change: 1 addition & 0 deletions packages/playground-next/public/file.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 packages/playground-next/public/globe.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 packages/playground-next/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 packages/playground-next/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.
1 change: 1 addition & 0 deletions packages/playground-next/public/window.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 packages/playground-next/src/app/favicon.ico
Binary file not shown.
42 changes: 42 additions & 0 deletions packages/playground-next/src/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
:root {
--background: #ffffff;
--foreground: #171717;
}

@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}

html,
body {
max-width: 100vw;
overflow-x: hidden;
}

body {
color: var(--foreground);
background: var(--background);
font-family: Arial, Helvetica, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

a {
color: inherit;
text-decoration: none;
}

@media (prefers-color-scheme: dark) {
html {
color-scheme: dark;
}
}
41 changes: 41 additions & 0 deletions packages/playground-next/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use client';

import { Geist } from "next/font/google";
import "./globals.css";
import { MetaMaskProvider } from "@metamask/sdk-react";
import { useEffect, useState } from "react";

const geist = Geist({
variable: "--font-geist",
subsets: ["latin"],
});

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
const [dappUrl, setDappUrl] = useState("");

useEffect(() => {
setDappUrl(window.location.href);
}, []);

return (
<html lang="en">
<body className={geist.variable}>
<MetaMaskProvider
debug={false}
sdkOptions={{
dappMetadata: {
name: "Simple Web3 Dapp",
url: dappUrl,
}
}}
>
<>{children}</>
</MetaMaskProvider>
</body>
</html>
);
}
35 changes: 35 additions & 0 deletions packages/playground-next/src/app/page.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
padding: 20px;
gap: 20px;
}

.button {
background: var(--foreground);
color: var(--background);
border: none;
padding: 12px 24px;
border-radius: 8px;
font-family: var(--font-geist);
cursor: pointer;
transition: opacity 0.2s;
}

.button:hover {
opacity: 0.8;
}

.address {
font-family: var(--font-geist);
background: var(--foreground);
color: var(--background);
padding: 12px 24px;
border-radius: 8px;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
}
57 changes: 57 additions & 0 deletions packages/playground-next/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use client';

import { useSDK } from '@metamask/sdk-react';
import styles from './page.module.css';
import { useState } from 'react';

interface AccountInfo {
account: string;
balance: string;
}

export default function Home() {
const { sdk } = useSDK();
const [account, setAccount] = useState<AccountInfo | null>(null);

const connectWallet = async (): Promise<void> => {
try {
const accounts = await sdk?.connect();

if (accounts?.[0]) {
const provider = sdk?.getProvider();
const balance = await provider?.request({
method: 'eth_getBalance',
params: [accounts[0], 'latest']
});

setAccount({
account: accounts[0],
balance: balance ? (parseInt(balance as string, 16)).toString() : '0'
});
}
} catch (err) {
console.error('Failed to connect wallet:', err);
}
};

return (
<div className={styles.container}>
<h1>Simple Web3 Dapp</h1>

{!account ? (
<button className={styles.button} onClick={connectWallet}>
Connect MetaMask
</button>
) : (
<>
<div className={styles.address}>
Address: {account.account}
</div>
<div className={styles.address}>
Balance: {account.balance} Wei
</div>
</>
)}
</div>
);
}
27 changes: 27 additions & 0 deletions packages/playground-next/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "ES2017",
"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
Loading