mirror of
https://github.com/logos-messaging/OpChan.git
synced 2026-07-30 10:23:22 +00:00
chore: improve wallet reconnection
This commit is contained in:
parent
a07fa3f7ba
commit
5ea4d7343f
@ -16,6 +16,8 @@ import { localDatabase } from '@/lib/database/LocalDatabase';
|
|||||||
import { useAppKitAccount, useDisconnect, modal } from '@reown/appkit/react';
|
import { useAppKitAccount, useDisconnect, modal } from '@reown/appkit/react';
|
||||||
import { MessageService } from '@/lib/services/MessageService';
|
import { MessageService } from '@/lib/services/MessageService';
|
||||||
import { UserIdentityService } from '@/lib/services/UserIdentityService';
|
import { UserIdentityService } from '@/lib/services/UserIdentityService';
|
||||||
|
import { reconnect } from '@wagmi/core';
|
||||||
|
import { config as wagmiConfig } from '@/lib/wallet/config';
|
||||||
|
|
||||||
interface AuthContextType {
|
interface AuthContextType {
|
||||||
currentUser: User | null;
|
currentUser: User | null;
|
||||||
@ -81,6 +83,31 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|||||||
}
|
}
|
||||||
}, [bitcoinAccount, ethereumAccount]);
|
}, [bitcoinAccount, ethereumAccount]);
|
||||||
|
|
||||||
|
// Try to auto-reconnect EVM wallets on app mount
|
||||||
|
useEffect(() => {
|
||||||
|
void reconnect(wagmiConfig)
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Attempt reconnect when network comes back online
|
||||||
|
useEffect(() => {
|
||||||
|
const handleOnline = () => {
|
||||||
|
void reconnect(wagmiConfig)
|
||||||
|
};
|
||||||
|
window.addEventListener('online', handleOnline);
|
||||||
|
return () => window.removeEventListener('online', handleOnline);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Attempt reconnect when tab becomes visible again
|
||||||
|
useEffect(() => {
|
||||||
|
const handleVisibility = () => {
|
||||||
|
if (document.visibilityState === 'visible') {
|
||||||
|
reconnect(wagmiConfig).catch(() => {});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
document.addEventListener('visibilitychange', handleVisibility);
|
||||||
|
return () => document.removeEventListener('visibilitychange', handleVisibility);
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Helper functions for user persistence
|
// Helper functions for user persistence
|
||||||
const loadStoredUser = async (): Promise<User | null> => {
|
const loadStoredUser = async (): Promise<User | null> => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user