Skip to content

Commit

Permalink
fix(clerk-js): Always invoke an injected Web3 Wallet provider
Browse files Browse the repository at this point in the history
If we weren't able to find the exact requested Web3 Wallet provider, then we should
fallback and use the injected provider in order for the user to be able to continue
the flow
  • Loading branch information
chanioxaris committed Dec 9, 2024
1 parent fba9d1d commit 78283ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-penguins-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Always invoke an injected Web3 Wallet provider, if any, to allow the user to continue the flow rather than be a no-op
14 changes: 8 additions & 6 deletions packages/clerk-js/src/utils/injectedWeb3Providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ class InjectedWeb3Providers {
}

get = (provider: InjectedWeb3Provider) => {
// In case there is a single injected provider, use that directly.
// This is needed in order to support other compatible Web3 Wallets (e.g. Rabby Wallet)
// and maintain the previous behavior
if (this.#providers.length === 1) {
return this.#providers[0].provider;
const ethProvider = this.#providers.find(p => p.info.name === this.#providerIdMap[provider])?.provider;
if (ethProvider !== undefined) {
return ethProvider;
}
return this.#providers.find(p => p.info.name === this.#providerIdMap[provider])?.provider;

// In case we weren't able to find the requested provider, fallback to the
// global injected provider instead, if any, to allow the user to continue
// the flow rather than be a no-op
return window.ethereum;
};

#onAnnouncement = (event: EIP6963AnnounceProviderEvent) => {
Expand Down

0 comments on commit 78283ea

Please sign in to comment.