Skip to content

Commit 32e8f77

Browse files
committed
fix missing discovered network set to appkit
Signed-off-by: p4u <pau@dabax.net>
1 parent 9c1784e commit 32e8f77

3 files changed

Lines changed: 11 additions & 15 deletions

File tree

src/Layout.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ export function Layout() {
3636
initializeNetworkDetection()
3737
}, [])
3838

39-
// Initialize AppKit once mini app context is ready
39+
// Initialize AppKit once mini app context is ready AND network is detected
4040
useEffect(() => {
4141
const initialize = async () => {
42-
if (!isInitialized) return
42+
if (!isInitialized || !detectedNetwork) return
4343

4444
try {
45-
// Initialize AppKit with conditional Farcaster support
46-
await initializeAppKit()
45+
// Initialize AppKit with the detected network
46+
await initializeAppKit(detectedNetwork)
4747
setAppKitInitialized(true)
4848
} catch (error) {
4949
console.error('Failed to initialize AppKit:', error)
@@ -52,7 +52,7 @@ export function Layout() {
5252
}
5353

5454
initialize()
55-
}, [isInitialized])
55+
}, [isInitialized, detectedNetwork])
5656

5757
// Switch to detected network only if auto-detection is enabled
5858
useEffect(() => {

src/lib/appkit-miniapp.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EthersAdapter } from '@reown/appkit-adapter-ethers'
22
import { AppKit, createAppKit } from '@reown/appkit/react'
3-
import { getConfiguredNetwork } from './network-config'
3+
import type { AppKitNetwork } from '@reown/appkit/networks'
44

55
// 1. Get projectId from environment
66
const projectId = import.meta.env.WALLETCONNECT_PROJECT_ID
@@ -13,23 +13,21 @@ const metadata = {
1313
icons: ['/images/davinci-icon-small.png'],
1414
}
1515

16-
// 3. Get configured network
17-
const network = getConfiguredNetwork()
18-
19-
// 4. Create Ethers Adapter with conditional provider
16+
// 3. Create Ethers Adapter with conditional provider
2017
const ethersAdapter = new EthersAdapter()
2118

2219
let appKit: AppKit | null = null
2320

2421
/**
25-
* Initialize AppKit - simplified version since mini app logic is now in context
22+
* Initialize AppKit with the detected network
23+
* @param network The network to initialize AppKit with
2624
*/
27-
export async function initializeAppKit() {
25+
export async function initializeAppKit(network: AppKitNetwork) {
2826
if (appKit) {
2927
return appKit
3028
}
3129

32-
console.log('Initializing AppKit...')
30+
console.log('Initializing AppKit with network:', network.name)
3331

3432
// Create standard AppKit (works for both mini app and regular web)
3533
appKit = createAppKit({

src/main.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { OfflineIndicator } from '~components/offline-indicator'
77
import { VocdoniApiProvider } from '~components/vocdoni-api-context'
88
import { MiniAppProvider } from '~contexts/MiniAppContext'
99
import { RouterProvider } from '~router'
10-
// Initialize AppKit
11-
import '~lib/appkit'
1210

1311
import '@fontsource/averia-libre/400.css'
1412
import '@fontsource/averia-libre/700.css'

0 commit comments

Comments
 (0)