refactor(dapp-v2): use existing onSessionConnected
handler for session_updated
This commit is contained in:
parent
6eec915a46
commit
1998be6295
@ -173,34 +173,36 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
|
|||||||
});
|
});
|
||||||
}, [client, session]);
|
}, [client, session]);
|
||||||
|
|
||||||
const _subscribeToEvents = useCallback(async (_client: Client) => {
|
const _subscribeToEvents = useCallback(
|
||||||
if (typeof _client === "undefined") {
|
async (_client: Client) => {
|
||||||
throw new Error("WalletConnect is not initialized");
|
if (typeof _client === "undefined") {
|
||||||
}
|
throw new Error("WalletConnect is not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
_client.on(CLIENT_EVENTS.pairing.proposal, async (proposal: PairingTypes.Proposal) => {
|
_client.on(CLIENT_EVENTS.pairing.proposal, async (proposal: PairingTypes.Proposal) => {
|
||||||
const { uri } = proposal.signal.params;
|
const { uri } = proposal.signal.params;
|
||||||
console.log("EVENT", "QR Code Modal open");
|
console.log("EVENT", "QR Code Modal open");
|
||||||
QRCodeModal.open(uri, () => {
|
QRCodeModal.open(uri, () => {
|
||||||
console.log("EVENT", "QR Code Modal closed");
|
console.log("EVENT", "QR Code Modal closed");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
_client.on(CLIENT_EVENTS.pairing.created, async () => {
|
_client.on(CLIENT_EVENTS.pairing.created, async () => {
|
||||||
setPairings(_client.pairing.topics);
|
setPairings(_client.pairing.topics);
|
||||||
});
|
});
|
||||||
|
|
||||||
_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) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user