Skip to content

Commit

Permalink
Add fallback for addListener for old extension versions
Browse files Browse the repository at this point in the history
  • Loading branch information
aryzing committed Aug 12, 2024
1 parent db26982 commit f1b6380
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
8 changes: 4 additions & 4 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
Expand Up @@ -24,7 +24,7 @@
]
},
"dependencies": {
"@sats-connect/core": "0.1.2-b66f8be",
"@sats-connect/core": "0.2.0",
"@sats-connect/make-default-provider-config": "0.0.5",
"@sats-connect/ui": "0.0.6"
},
Expand Down
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ class Wallet {
}

const adapter = this.defaultAdapters[this.providerId as string];

// Clients may have be using the latest version of sats-connect without
// their wallets having been updated. Until we have API versioning for the
// wallet, we can avoid having apps crash by checking whether the adapter
// actually supports `addListener`.
if (!new adapter().addListener) {
console.error(
`The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
);
return () => {};
}

return new adapter().addListener(event, cb);
};
}
Expand Down

0 comments on commit f1b6380

Please sign in to comment.