Skip to content

Test/appkit with immutable #83

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions nextjs/next-wagmi-app-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"lint": "next lint"
},
"dependencies": {
"@reown/appkit": "1.7.2",
"@reown/appkit-adapter-wagmi": "1.7.2",
"@imtbl/sdk": "^2.1.16",
"@reown/appkit": "1.7.4-4aeb703fc5bc44cfc6cb34b43758eb3fbb8ab005.0",
"@reown/appkit-adapter-wagmi": "1.7.4-4aeb703fc5bc44cfc6cb34b43758eb3fbb8ab005.0",
"@tanstack/react-query": "^5.59.20",
"next": "15.1.6",
"react": "19.0.0",
Expand Down
29 changes: 29 additions & 0 deletions nextjs/next-wagmi-app-router/src/app/logout/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use client'

import { useEffect } from 'react'
import { passportInstance } from '@/config/passport'
import { useRouter } from 'next/navigation'

export default function LogoutPage() {
const router = useRouter()

useEffect(() => {
const handleLogout = async () => {
try {
await passportInstance.logout()
router.push('/')
} catch (error) {
console.error('Logout failed:', error)
router.push('/')
}
}

handleLogout()
}, [router])

return (
<div className="pages">
<h1>Logging out...</h1>
</div>
)
}
29 changes: 29 additions & 0 deletions nextjs/next-wagmi-app-router/src/app/redirect/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use client'

import { useEffect } from 'react'
import { passportInstance } from '@/config/passport'
import { useRouter } from 'next/navigation'

export default function RedirectPage() {
const router = useRouter()

useEffect(() => {
const handleCallback = async () => {
try {
await passportInstance.loginCallback()
router.push('/')
} catch (error) {
console.error('Login callback failed:', error)
router.push('/')
}
}

handleCallback()
}, [router])

return (
<div className="pages">
<h1>Completing login...</h1>
</div>
)
}
13 changes: 10 additions & 3 deletions nextjs/next-wagmi-app-router/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { cookieStorage, createStorage } from 'wagmi'
import { cookieStorage, createStorage } from 'wagmi'
import { WagmiAdapter } from '@reown/appkit-adapter-wagmi'
import { mainnet, arbitrum } from '@reown/appkit/networks'
import { immutableZkEvmTestnet } from '@reown/appkit/networks'
import type { AppKitNetwork } from '@reown/appkit/networks'


// Get projectId from https://cloud.reown.com
export const projectId = process.env.NEXT_PUBLIC_PROJECT_ID || "b56e18d47c72ab683b10814fe9495694" // this is a public projectId only to use on localhost

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

export const networks = [mainnet, arbitrum] as [AppKitNetwork, ...AppKitNetwork[]]
export const networks = [immutableZkEvmTestnet] as [AppKitNetwork, ...AppKitNetwork[]]


// create the connectors (delete the ones you don't need)
/* const connectors: CreateConnectorFn[] = []
connectors.push(walletConnect({ projectId, metadata, showQrModal: false })) // showQrModal must be false
) */

//Set up the Wagmi Adapter (Config)
export const wagmiAdapter = new WagmiAdapter({
Expand Down
20 changes: 20 additions & 0 deletions nextjs/next-wagmi-app-router/src/config/passport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { config, passport } from '@imtbl/sdk';

const publishableKey = process.env.NEXT_PUBLIC_PUBLISHABLE_KEY || '';
const clientId = process.env.NEXT_PUBLIC_CLIENT_ID || '';
// create the Passport instance and export it so it can be used in the examples
export const passportInstance = new passport.Passport({
baseConfig: {
environment: config.Environment.SANDBOX,
publishableKey
},
clientId,
redirectUri: 'http://localhost:3000/redirect', // replace with one of your redirect URIs from Hub
logoutRedirectUri: 'http://localhost:3000/logout', // replace with one of your logout URIs from Hub
audience: 'platform_api',
scope: 'openid offline_access email transact',
popupOverlayOptions: {
disableGenericPopupOverlay: false, // Set to true to disable the generic pop-up overlay
disableBlockedPopupOverlay: false, // Set to true to disable the blocked pop-up overlay
},
});
15 changes: 14 additions & 1 deletion nextjs/next-wagmi-app-router/src/context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import { wagmiAdapter, projectId, networks } from '@/config'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { createAppKit } from '@reown/appkit/react'
import React, { type ReactNode } from 'react'
import React, { useEffect, type ReactNode } from 'react'
import { cookieToInitialState, WagmiProvider, type Config } from 'wagmi'
import { passportInstance } from '../config/passport';


// Set up queryClient
const queryClient = new QueryClient()
Expand All @@ -17,6 +19,8 @@ const metadata = {
icons: ['https://avatars.githubusercontent.com/u/179229932']
}



// Create the modal
export const modal = createAppKit({
adapters: [wagmiAdapter],
Expand All @@ -33,6 +37,15 @@ export const modal = createAppKit({
})

function ContextProvider({ children, cookies }: { children: ReactNode; cookies: string | null }) {
useEffect(() => {
const init = async () => {

// calling connectEVM() makes Passport available as an option to Wagmi
await passportInstance.connectEvm();
}

init();
}, []);
const initialState = cookieToInitialState(wagmiAdapter.wagmiConfig as Config, cookies)

return (
Expand Down