Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
glitch-txs committed Jan 24, 2024
1 parent 6f942ce commit 2cbd550
Show file tree
Hide file tree
Showing 12 changed files with 315 additions and 256 deletions.
8 changes: 4 additions & 4 deletions dapps/web3modal/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
"format": "pnpm dlx @biomejs/biome format ./src --write"
},
"dependencies": {
"@tanstack/react-query": "^5.17.14",
"@web3modal/wagmi": "4.0.0-alpha.0",
"@tanstack/react-query": "^5.17.19",
"@web3modal/wagmi": "4.0.0-alpha.2",
"next": "14.0.4",
"react": "^18",
"react-dom": "^18",
"viem": "^2.4.0",
"wagmi": "^2.3.1"
"viem": "^2.5.0",
"wagmi": "^2.5.2"
},
"devDependencies": {
"@biomejs/biome": "1.5.2",
Expand Down
154 changes: 77 additions & 77 deletions dapps/web3modal/next/pnpm-lock.yaml

Large diffs are not rendered by default.

38 changes: 17 additions & 21 deletions dapps/web3modal/next/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
import './globals.css'
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import { headers } from 'next/headers'

import { Web3Modal } from '@/context/Web3Modal'
import './globals.css'
import { cookieToInitialState } from 'wagmi'
import { wagmiConfig } from '@/context/wagmiConfig'
import { headers } from 'next/headers'
import ContextProvider from '@/context'
import { config } from '@/config'

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

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

interface Props {
export default function RootLayout({
children
}: Readonly<{
children: React.ReactNode
}

export default async function RootLayout({ children }: Props) {
const initialState = cookieToInitialState(
wagmiConfig,
headers().get('cookie')
}>) {
const initialState = cookieToInitialState(config, headers().get('cookie'))
return (
<html lang="en">
<body className={inter.className}>
<ContextProvider initialState={initialState}>{children}</ContextProvider>
</body>
</html>
)
return (
<html lang="en">
<body className={inter.className}>
<Web3Modal initialState={initialState} >{children}</Web3Modal>
</body>
</html>
)
}
11 changes: 6 additions & 5 deletions dapps/web3modal/next/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Connect from '@/components/Connect'
import styles from './page.module.css'

export default function Home() {
return (
<main className={styles.main}>
<w3m-button />
</main>
)
return (
<main className={styles.main}>
<Connect />
</main>
)
}
5 changes: 5 additions & 0 deletions dapps/web3modal/next/src/components/Connect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use client'

export default function Connect() {
return <w3m-button />
}
22 changes: 22 additions & 0 deletions dapps/web3modal/next/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defaultWagmiConfig } from '@web3modal/wagmi/react/config'
import { cookieStorage, createStorage } from 'wagmi'
import { mainnet, sepolia } from 'wagmi/chains'

export const projectId = process.env.NEXT_PUBLIC_PROJECT_ID

if (!projectId) throw new Error('Project ID is not defined')

export const config = defaultWagmiConfig({
projectId,
chains: [mainnet, sepolia],
metadata: {
name: 'My App',
description: 'My app description',
url: 'https://myapp.com',
icons: ['https://myapp.com/favicon.ico']
},
storage: createStorage({
storage: cookieStorage
}),
ssr: true
})
17 changes: 0 additions & 17 deletions dapps/web3modal/next/src/context/Web3Modal.tsx

This file was deleted.

32 changes: 32 additions & 0 deletions dapps/web3modal/next/src/context/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use client'

import { config, projectId } from '@/config'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { createWeb3Modal } from '@web3modal/wagmi/react'
import React, { ReactNode } from 'react'
import { State, WagmiProvider } from 'wagmi'

const queryClient = new QueryClient()

if (!projectId) throw new Error('Project ID is not defined')

createWeb3Modal({
wagmiConfig: config,
projectId
})

function ContextProvider({
children,
initialState
}: {
children: ReactNode
initialState: State | undefined
}) {
return (
<WagmiProvider config={config} initialState={initialState}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</WagmiProvider>
)
}

export default ContextProvider
36 changes: 0 additions & 36 deletions dapps/web3modal/next/src/context/wagmiConfig.ts

This file was deleted.

8 changes: 4 additions & 4 deletions dapps/web3modal/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^5.17.15",
"@web3modal/wagmi": "4.0.0-alpha.0",
"@tanstack/react-query": "^5.17.19",
"@web3modal/wagmi": "4.0.0-alpha.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"viem": "^2.4.0",
"wagmi": "^2.3.1"
"viem": "^2.5.0",
"wagmi": "^2.5.2"
},
"devDependencies": {
"@types/react": "^18.2.14",
Expand Down
Loading

0 comments on commit 2cbd550

Please sign in to comment.