|
1 | 1 | 'use client' |
2 | 2 |
|
3 | 3 | import { useState, useEffect } from 'react' |
4 | | -import { useAccount } from 'wagmi' |
| 4 | +import { useAccount, useDisconnect } from 'wagmi' |
5 | 5 | import { usePrivy } from '@privy-io/react-auth' |
6 | 6 | import { useRouter } from 'next/navigation' |
7 | 7 | import { useTokenBalances, useSenseUsername } from '@/hooks/useTokenBalances' |
@@ -37,10 +37,18 @@ type BalanceView = 'total' | 'network' | 'tokens' |
37 | 37 |
|
38 | 38 | export function WalletBalanceDropdown() { |
39 | 39 | const { address, isConnected } = useAccount() |
40 | | - // Disconnect routes through Privy's `logout` so the embedded-wallet |
41 | | - // session ends. wagmi's useDisconnect alone would only drop the wagmi |
42 | | - // connector and leave the Privy session live. |
| 40 | + // Disconnect needs to terminate both possible session types: |
| 41 | + // - Privy session (embedded wallet, Stage 1 default) |
| 42 | + // - wagmi connector session (legacy MetaMask / injected, or any cached |
| 43 | + // state from before the Privy migration). |
| 44 | + // Calling both is safe — each is a no-op if the corresponding session |
| 45 | + // doesn't exist. Calling only one leaves the other stuck. |
43 | 46 | const { logout } = usePrivy() |
| 47 | + const { disconnect } = useDisconnect() |
| 48 | + const handleDisconnect = async () => { |
| 49 | + try { await logout() } catch {} |
| 50 | + try { disconnect() } catch {} |
| 51 | + } |
44 | 52 | const router = useRouter() |
45 | 53 | const { balances, isLoading, ethBalance, gameBalance, usdcBalance } = useTokenBalances() |
46 | 54 | const { username: senseUsername, isLoading: usernameLoading } = useSenseUsername(address) |
@@ -320,7 +328,7 @@ export function WalletBalanceDropdown() { |
320 | 328 | <DropdownMenuSeparator /> |
321 | 329 |
|
322 | 330 | {/* Disconnect */} |
323 | | - <DropdownMenuItem onClick={() => logout()} className="text-red-600 focus:text-red-600"> |
| 331 | + <DropdownMenuItem onClick={handleDisconnect} className="text-red-600 focus:text-red-600"> |
324 | 332 | <LogOut className="h-4 w-4 mr-2" /> |
325 | 333 | Disconnect Wallet |
326 | 334 | </DropdownMenuItem> |
|
0 commit comments