refactor(dapp-v2): use existing onSessionConnected handler for session_updated

This commit is contained in:
Ben Kremer 2022-03-04 10:30:08 +00:00
parent 6eec915a46
commit 1998be6295

View File

@ -173,7 +173,8 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
}); });
}, [client, session]); }, [client, session]);
const _subscribeToEvents = useCallback(async (_client: Client) => { const _subscribeToEvents = useCallback(
async (_client: Client) => {
if (typeof _client === "undefined") { if (typeof _client === "undefined") {
throw new Error("WalletConnect is not initialized"); throw new Error("WalletConnect is not initialized");
} }
@ -192,15 +193,16 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
_client.on(CLIENT_EVENTS.session.updated, (updatedSession: SessionTypes.Settled) => { _client.on(CLIENT_EVENTS.session.updated, (updatedSession: SessionTypes.Settled) => {
console.log("EVENT", "session_updated"); console.log("EVENT", "session_updated");
setChains(updatedSession.permissions.blockchain.chains); onSessionConnected(updatedSession);
setAccounts(updatedSession.state.accounts);
}); });
_client.on(CLIENT_EVENTS.session.deleted, () => { _client.on(CLIENT_EVENTS.session.deleted, () => {
console.log("EVENT", "session_deleted"); console.log("EVENT", "session_deleted");
resetApp(); resetApp();
}); });
}, []); },
[onSessionConnected],
);
const _checkPersistedState = useCallback( const _checkPersistedState = useCallback(
async (_client: Client) => { async (_client: Client) => {