Skip to content

Commit

Permalink
7. Subscribe to Events
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa Mercado authored and Vanessa Mercado committed Dec 2, 2022
1 parent bd941aa commit 6771cb7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function App() {
projectId: process.env.REACT_APP_PROJECT_ID,
});
setSignClient(signClient);
await subscribeToEvents(signClient);
} catch (e) {
console.log(e);
}
Expand Down Expand Up @@ -72,6 +73,19 @@ function App() {
}
}

async function subscribeToEvents(client) {
if (!client)
throw Error("Unable to subscribe to events. Client does not exist.");
try {
client.on("session_delete", () => {
console.log("The user has disconnected the session from their wallet.");
reset();
});
} catch (e) {
console.log(e);
}
}

const reset = () => {
setAccount([]);
setSession([]);
Expand Down

0 comments on commit 6771cb7

Please sign in to comment.