Skip to content

Commit

Permalink
fix(clerk-js): Always invoke an injected Web3 Wallet provider (#4734)
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 authored Dec 10, 2024
1 parent 52a24eb commit 80f2402
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
---

Bug fix: When the requested Web3 provider cannot be found, use any other available injected Web3 Wallet provider, instead of blocking the sign-in/sign-up flow.
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 blocking it
return window.ethereum;
};

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

0 comments on commit 80f2402

Please sign in to comment.