Skip to content

Commit

Permalink
refactor next
Browse files Browse the repository at this point in the history
  • Loading branch information
glitch-txs committed Jan 19, 2024
1 parent a2f89d0 commit 4b6a6f9
Show file tree
Hide file tree
Showing 8 changed files with 4,991 additions and 5,917 deletions.
4 changes: 2 additions & 2 deletions dapps/web3modal/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"next": "14.0.4",
"react": "^18",
"react-dom": "^18",
"viem": "^2.2.0",
"wagmi": "^2.2.1"
"viem": "^2.4.0",
"wagmi": "^2.3.1"
},
"devDependencies": {
"@biomejs/biome": "1.5.2",
Expand Down
113 changes: 92 additions & 21 deletions dapps/web3modal/next/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion dapps/web3modal/next/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import { headers } from 'next/headers'

import { Web3Modal, wagmiConfig } from '@/context/Web3Modal'
import { Web3Modal } from '@/context/Web3Modal'
import { cookieToInitialState } from 'wagmi'
import { wagmiConfig } from '@/context/wagmiConfig'

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

Expand Down
36 changes: 1 addition & 35 deletions dapps/web3modal/next/src/context/Web3Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,11 @@
import { WagmiProvider, State } from 'wagmi'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { ReactNode } from 'react'
import { createWeb3Modal } from '@web3modal/wagmi/react'
import { cookieStorage, createConfig, createStorage, http } from 'wagmi'
import { type Chain, mainnet, sepolia } from 'wagmi/chains'
import { walletConnect } from 'wagmi/connectors'
import { wagmiConfig } from './wagmiConfig'

// 0. Setup queryClient
const queryClient = new QueryClient()

// 1. Get projectId at https://cloud.walletconnect.com
const projectId = process.env.NEXT_PUBLIC_PROJECT_ID || ''

if (!projectId) throw new Error('WalletConnect Project ID is undefined')

// 2. Create wagmiConfig
const metadata = {
name: 'Web3Modal',
description: 'Web3Modal Example',
url: 'https://web3modal.com',
icons: ['https://avatars.githubusercontent.com/u/37784886'],
}

const chains = [mainnet, sepolia] as [Chain, ...Chain[]]

export const wagmiConfig = createConfig({
chains,
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
connectors: [walletConnect({ projectId, metadata, showQrModal: false })],
ssr: true,
storage: createStorage({
storage: cookieStorage,
}),
})

// 3. Create modal
createWeb3Modal({ wagmiConfig, projectId, chains })

export function Web3Modal({ children, initialState }: { children: ReactNode; initialState?: State }) {
return (
<WagmiProvider config={wagmiConfig} initialState={initialState}>
Expand Down
41 changes: 41 additions & 0 deletions dapps/web3modal/next/src/context/wagmiConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { createWeb3Modal } from "@web3modal/wagmi"
import { cookieStorage, createConfig, createStorage, http } from "wagmi"
import { getConnectors, watchConnectors } from "wagmi/actions"
import { Chain, mainnet, sepolia } from "wagmi/chains"
import { injected, walletConnect } from "wagmi/connectors"

// 1. Get projectId at https://cloud.walletconnect.com
const projectId = process.env.NEXT_PUBLIC_PROJECT_ID || ''

if (!projectId) throw new Error('WalletConnect Project ID is undefined')

// 2. Create wagmiConfig
const metadata = {
name: 'Web3Modal',
description: 'Web3Modal Example',
url: 'https://web3modal.com',
icons: ['https://avatars.githubusercontent.com/u/37784886'],
}

const chains = [mainnet, sepolia] as [Chain, ...Chain[]]

export const wagmiConfig = createConfig({
chains,
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
connectors: [walletConnect({ projectId, metadata, showQrModal: false }), injected()],
ssr: true,
storage: createStorage({
storage: cookieStorage,
}),
})

const connectors = getConnectors(wagmiConfig)
console.log(connectors)

watchConnectors(wagmiConfig, { onChange(cone){ console.log(cone) } })
// 3. Create modal
createWeb3Modal({ wagmiConfig, projectId, chains })

2 changes: 1 addition & 1 deletion dapps/web3modal/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"viem": "^2.4.0",
"wagmi": "^2.2.1"
"wagmi": "^2.3.1"
},
"devDependencies": {
"@types/react": "^18.2.14",
Expand Down
Loading

0 comments on commit 4b6a6f9

Please sign in to comment.