Skip to content

Commit 900e7d0

Browse files
authored
fix: Remove duplicated entry for MetaMask in MM browser (#2741)
1 parent 031eccb commit 900e7d0

File tree

7 files changed

+41
-30
lines changed

7 files changed

+41
-30
lines changed

.changeset/khaki-gifts-sing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Remove duplicated entry for MetaMask in MM browser

packages/thirdweb/src/react/web/ui/ConnectWallet/Modal/AnyWalletConnectUI.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
InjectedSupportedWalletIds,
44
WCSupportedWalletIds,
55
} from "../../../../../wallets/__generated__/wallet-ids.js";
6-
import { getMIPDStore } from "../../../../../wallets/injected/mipdStore.js";
6+
import { getInstalledWalletProviders } from "../../../../../wallets/injected/mipdStore.js";
77
import type { Wallet } from "../../../../../wallets/interfaces/wallet.js";
88
import { useWalletConnectionCtx } from "../../../../core/hooks/others/useWalletConnectionCtx.js";
99
import { getInjectedWalletLocale } from "../../../wallets/injected/locale/getInjectedWalletLocale.js";
@@ -52,9 +52,9 @@ export function AnyWalletConnectUI(props: {
5252
}
5353

5454
// if wallet can connect to injected wallet + wallet is injected
55-
const isInstalled = getMIPDStore()
56-
.getProviders()
57-
.find((w) => w.info.rdns === walletInfo.data.rdns);
55+
const isInstalled = getInstalledWalletProviders().find(
56+
(w) => w.info.rdns === walletInfo.data.rdns,
57+
);
5858

5959
if (screen === "get-started") {
6060
return (

packages/thirdweb/src/react/web/ui/ConnectWallet/WalletEntryButton.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getMIPDStore } from "../../../../wallets/injected/mipdStore.js";
1+
import { getInstalledWalletProviders } from "../../../../wallets/injected/mipdStore.js";
22
import type { WalletId } from "../../../../wallets/wallet-types.js";
33
// import { localWalletMetadata } from "../../../../wallets/local/index._ts";
44
import { useWalletConnectionCtx } from "../../../core/hooks/others/useWalletConnectionCtx.js";
@@ -26,14 +26,12 @@ export function WalletEntryButton(props: {
2626
const walletInfo = useWalletInfo(walletId);
2727

2828
const walletName =
29-
getMIPDStore()
30-
.getProviders()
31-
.find((p) => p.info.rdns === walletId)?.info.name ||
32-
walletInfo.data?.name;
29+
getInstalledWalletProviders().find((p) => p.info.rdns === walletId)?.info
30+
.name || walletInfo.data?.name;
3331

34-
const isInstalled = getMIPDStore()
35-
.getProviders()
36-
.find((p) => p.info.rdns === walletId);
32+
const isInstalled = getInstalledWalletProviders().find(
33+
(p) => p.info.rdns === walletId,
34+
);
3735

3836
return (
3937
<WalletButton

packages/thirdweb/src/react/web/ui/ConnectWallet/WalletSelector.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ChevronLeftIcon } from "@radix-ui/react-icons";
22
import { Suspense, lazy, useContext, useEffect, useRef, useState } from "react";
33
import type { InjectedSupportedWalletIds } from "../../../../wallets/__generated__/wallet-ids.js";
44
import { createWallet } from "../../../../wallets/create-wallet.js";
5-
import { getMIPDStore } from "../../../../wallets/injected/mipdStore.js";
5+
import { getInstalledWalletProviders } from "../../../../wallets/injected/mipdStore.js";
66
import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
77
import type { WalletId } from "../../../../wallets/wallet-types.js";
88
// import { localWalletMetadata } from "../../../../wallets/local/index._ts";
@@ -467,7 +467,7 @@ let _installedWallets: Wallet[] = [];
467467

468468
function getInstalledWallets() {
469469
if (_installedWallets.length === 0) {
470-
const providers = getMIPDStore().getProviders();
470+
const providers = getInstalledWalletProviders();
471471
const walletIds = providers.map((provider) => provider.info.rdns);
472472
_installedWallets = walletIds.map((w) =>
473473
createWallet(w as InjectedSupportedWalletIds),

packages/thirdweb/src/react/web/ui/components/WalletImage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getMIPDStore } from "../../../../wallets/injected/mipdStore.js";
1+
import { getInstalledWalletProviders } from "../../../../wallets/injected/mipdStore.js";
22
import type { WalletId } from "../../../../wallets/wallet-types.js";
33
import { radius } from "../design-system/index.js";
44
import { useWalletImage } from "../hooks/useWalletInfo.js";
@@ -8,9 +8,9 @@ import { Img } from "./Img.js";
88
* @internal
99
*/
1010
export function WalletImage(props: { id: WalletId; size: string }) {
11-
const mipdImage = getMIPDStore()
12-
.getProviders()
13-
.find((provider) => provider.info.rdns === props.id)?.info.icon;
11+
const mipdImage = getInstalledWalletProviders().find(
12+
(provider) => provider.info.rdns === props.id,
13+
)?.info.icon;
1414

1515
if (mipdImage) {
1616
return (

packages/thirdweb/src/react/web/utils/sortWallets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getMIPDStore } from "../../../wallets/injected/mipdStore.js";
1+
import { getInstalledWalletProviders } from "../../../wallets/injected/mipdStore.js";
22
import type { WalletId } from "../../../wallets/wallet-types.js";
33

44
/**
@@ -9,7 +9,7 @@ export function sortWallets<T extends { id: string }>(
99
wallets: T[],
1010
recommendedWallets?: { id: WalletId }[],
1111
): T[] {
12-
const providers = getMIPDStore().getProviders();
12+
const providers = getInstalledWalletProviders();
1313
return (
1414
wallets
1515
// show the installed wallets first

packages/thirdweb/src/wallets/injected/mipdStore.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,9 @@ const mipdStore: Store | undefined = /* @__PURE__ */ (() =>
2929
* @walletUtils
3030
*/
3131
export function injectedProvider(walletId: WalletId): Ethereum | undefined {
32-
if (!mipdStore) {
33-
throw new Error("store not initialized");
34-
}
35-
36-
const store = getMIPDStore();
37-
38-
const injectedProviderDetail = store.findProvider({
39-
rdns: walletId,
40-
});
32+
const injectedProviderDetail = getInstalledWalletProviders().find(
33+
(p) => p.info.rdns === walletId,
34+
);
4135

4236
return injectedProviderDetail?.provider as Ethereum | undefined;
4337
}
@@ -46,9 +40,23 @@ export function injectedProvider(walletId: WalletId): Ethereum | undefined {
4640
* Get Injected Provider Details for given wallet ID (rdns)
4741
* @internal
4842
*/
49-
export function getMIPDStore() {
43+
function getMIPDStore() {
5044
if (!mipdStore) {
5145
throw new Error("MIPD store not initialized");
5246
}
5347
return mipdStore;
5448
}
49+
50+
export function getInstalledWalletProviders() {
51+
const providers = getMIPDStore().getProviders();
52+
53+
for (const provider of providers) {
54+
// Map io.metamask.mobile to io.metamask rdns to fix double entry issue in MetaMask mobile browser
55+
if ((provider.info.rdns as string) === "io.metamask.mobile") {
56+
provider.info.rdns = "io.metamask";
57+
break;
58+
}
59+
}
60+
61+
return providers;
62+
}

0 commit comments

Comments
 (0)