Skip to content

Commit

Permalink
Safely handle disconnect errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Apr 18, 2023
1 parent d3ff800 commit b3c5b59
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
8 changes: 4 additions & 4 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@keplr-wallet/provider": "^0.11.49",
"@keplr-wallet/stores": "^0.11.49",
"@keplr-wallet/types": "^0.11.49",
"@noahsaso/cosmodal": "0.10.0",
"@noahsaso/cosmodal": "0.10.1",
"@walletconnect/client": "^1.7.8",
"next": "^13.3.0",
"react": "^18.2.0",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@noahsaso/cosmodal",
"version": "0.10.0",
"version": "0.10.1",
"repository": {
"type": "git",
"url": "git+https://github.com/NoahSaso/cosmodal.git"
Expand Down
10 changes: 7 additions & 3 deletions src/components/WalletManagerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,12 @@ export const WalletManagerProvider: FunctionComponent<
// Disconnect from connected wallet.
const disconnect = useCallback(
async (dontKillWalletConnect?: boolean) => {
// Disconnect client if it exists.
connectedWallet?.walletClient?.disconnect?.()
// Disconnect client if it exists. Log and ignore errors.
try {
await connectedWallet?.walletClient?.disconnect?.()
} catch (err) {
console.error("Error disconnecting wallet client", err)
}

// Disconnect wallet.
setConnectedWallet(undefined)
Expand All @@ -153,7 +157,7 @@ export const WalletManagerProvider: FunctionComponent<
// Disconnect WalletConnect.
setWalletConnect(undefined)
if (walletConnect?.connected && !dontKillWalletConnect) {
await walletConnect.killSession()
await walletConnect.killSession().catch(console.error)
// Remove session from localStorage since it tries to use the same
// session as last time on future attempts. When the user manually
// disconnects, we want to clear this state in case something is wrong
Expand Down

1 comment on commit b3c5b59

@vercel
Copy link

@vercel vercel bot commented on b3c5b59 Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

noahsaso-cosmodal – ./

noahsaso-cosmodal.vercel.app
noahsaso-cosmodal-noahsaso.vercel.app
noahsaso-cosmodal-git-main-noahsaso.vercel.app

Please sign in to comment.