Skip to content

Commit

Permalink
core: add disconnect event listener for wallets (#526)
Browse files Browse the repository at this point in the history
when user disconnects dApp from the wallet ui itself, it will emit
`disconnect` event using which we update starknet state.

resolves #520
  • Loading branch information
fracek authored Oct 30, 2024
2 parents 240a265 + 8e20d64 commit 3d5aec9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "core: add disconnect event listener for wallets",
"packageName": "@starknet-react/core",
"email": "[email protected]",
"dependentChangeType": "patch"
}
3 changes: 3 additions & 0 deletions packages/core/src/context/starknet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ function useStarknetManager({
const needsListenerSetup = connectorRef.current?.id !== connector.id;
if (needsListenerSetup) {
connectorRef.current?.off("change", handleConnectorChange);
connectorRef.current?.off("disconnect", disconnect);
}

try {
Expand All @@ -214,6 +215,7 @@ function useStarknetManager({

if (needsListenerSetup) {
connector.on("change", handleConnectorChange);
connector.on("disconnect", disconnect);
}

updateChainAndProvider({ chainId });
Expand Down Expand Up @@ -248,6 +250,7 @@ function useStarknetManager({

if (!connectorRef.current) return;
connectorRef.current.off("change", handleConnectorChange);
connectorRef.current.off("disconnect", disconnect);

try {
await connectorRef.current.disconnect();
Expand Down

0 comments on commit 3d5aec9

Please sign in to comment.