Skip to content

Commit 905c27f

Browse files
authored
Merge pull request #368 from LIT-Protocol/fix/dashboard-wallet-auth-patch
fix(dashboard): rainbow wallet fix, shared wagmi config
2 parents 82d11cc + c8cdcfb commit 905c27f

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

packages/apps/app-dashboard/src/components/user-dashboard/auth/EthWalletAuth.tsx

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useState, useEffect, useRef } from 'react';
22
import { createAppKit } from '@reown/appkit/react';
33
import { WagmiAdapter } from '@reown/appkit-adapter-wagmi';
44
import { mainnet, polygon, arbitrum, optimism, base, AppKitNetwork } from '@reown/appkit/networks';
5-
import { useAccount, useSignMessage, useDisconnect } from 'wagmi';
5+
import { useAccount, useSignMessage, useDisconnect, useConfig } from 'wagmi';
66
import { Button } from '@/components/shared/ui/button';
77
import { ThemeType } from '../connect/ui/theme';
88
import StatusMessage from '../connect/StatusMessage';
@@ -24,23 +24,32 @@ export default function EthWalletAuth({ authWithEthWallet, setView, theme }: Wal
2424
const { address, isConnected } = useAccount();
2525
const { signMessageAsync } = useSignMessage();
2626
const { disconnect } = useDisconnect();
27+
const wagmiConfig = useConfig();
2728
const appKitRef = useRef<any>(null);
2829

2930
const { VITE_WALLETCONNECT_PROJECT_ID, VITE_DASHBOARD_URL } = env;
3031

31-
// Initialize AppKit on demand
32+
// Initialize AppKit on demand - wrap existing wagmi config in WagmiAdapter
3233
useEffect(() => {
33-
if (!appKitInitialized) {
34+
if (!appKitInitialized && wagmiConfig) {
3435
const allNetworks = [mainnet, polygon, arbitrum, optimism, base] as [
3536
AppKitNetwork,
3637
...AppKitNetwork[],
3738
];
3839

40+
// Create a WagmiAdapter that wraps the existing config from WagmiProviderWrapper
3941
const wagmiAdapter = new WagmiAdapter({
4042
projectId: VITE_WALLETCONNECT_PROJECT_ID,
4143
networks: allNetworks,
4244
});
4345

46+
// Override the adapter's wagmiConfig with the one from the provider
47+
// This ensures AppKit uses the same config instance as the wagmi hooks
48+
Object.defineProperty(wagmiAdapter, 'wagmiConfig', {
49+
get: () => wagmiConfig,
50+
configurable: true,
51+
});
52+
4453
appKitRef.current = createAppKit({
4554
adapters: [wagmiAdapter],
4655
networks: [...allNetworks],
@@ -56,7 +65,7 @@ export default function EthWalletAuth({ authWithEthWallet, setView, theme }: Wal
5665

5766
setAppKitInitialized(true);
5867
}
59-
}, [appKitInitialized, VITE_WALLETCONNECT_PROJECT_ID, VITE_DASHBOARD_URL]);
68+
}, [appKitInitialized, wagmiConfig, VITE_WALLETCONNECT_PROJECT_ID, VITE_DASHBOARD_URL]);
6069

6170
// Clean up AppKit when component unmounts or after successful authentication
6271
useEffect(() => {
@@ -141,22 +150,6 @@ export default function EthWalletAuth({ authWithEthWallet, setView, theme }: Wal
141150

142151
return (
143152
<>
144-
{isWalletReady && (
145-
<div className="mb-4 flex justify-center">
146-
<div className="w-4/5">
147-
<div className="bg-green-50 border border-green-200 rounded-lg p-3">
148-
<div className="flex items-center justify-center mb-2">
149-
<div className="w-2 h-2 bg-green-500 rounded-full mr-2"></div>
150-
<span className="text-sm font-medium text-green-800">Connected Wallet</span>
151-
</div>
152-
<div className="rounded p-2 border bg-white border-green-300">
153-
<div className="text-[10px] break-all text-center text-black">{address}</div>
154-
</div>
155-
</div>
156-
</div>
157-
</div>
158-
)}
159-
160153
<div className="flex justify-center">
161154
<div className="space-y-4 w-4/5">
162155
{!isWalletReady ? (
@@ -178,7 +171,18 @@ export default function EthWalletAuth({ authWithEthWallet, setView, theme }: Wal
178171
</Button>
179172
</div>
180173
) : (
181-
<div>
174+
<div className="space-y-3">
175+
<div className={`${theme.successBg} border ${theme.cardBorder} rounded-lg p-3`}>
176+
<div className="flex items-center justify-center mb-2">
177+
<div className="w-2 h-2 bg-green-500 rounded-full mr-2"></div>
178+
<span className={`text-sm font-medium ${theme.successText}`}>
179+
Connected Wallet
180+
</span>
181+
</div>
182+
<div className={`rounded p-2 border ${theme.cardBg} ${theme.cardBorder}`}>
183+
<div className={`text-[10px] break-all text-center ${theme.text}`}>{address}</div>
184+
</div>
185+
</div>
182186
<Button
183187
onClick={authenticate}
184188
disabled={loading}

0 commit comments

Comments
 (0)