Skip to content

Commit 0ef37e6

Browse files
committed
fix incorrect connector in tracking by explicitly set falgs for installed wallets
1 parent 404ba12 commit 0ef37e6

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

packages/modal/src/ui/components/ConnectWallet/ConnectWallet.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,21 @@ function ConnectWallet(props: ConnectWalletProps) {
7676
...allExternalButtons.filter((button) => button.hasInjectedWallet && defaultButtonKeys.has(button.name)),
7777
...customConnectorButtons,
7878
...allExternalButtons.filter((button) => !button.hasInjectedWallet && defaultButtonKeys.has(button.name)),
79-
].sort((a, _) => (a.name === WALLET_CONNECTORS.METAMASK ? -1 : 1));
79+
].sort((a, b) => {
80+
// favor MetaMask over other wallets
81+
if (a.name === WALLET_CONNECTORS.METAMASK && b.name === WALLET_CONNECTORS.METAMASK) {
82+
// favor injected MetaMask over non-injected MetaMask
83+
if (a.hasInjectedWallet) return -1;
84+
if (b.hasInjectedWallet) return 1;
85+
// favor installed MetaMask over non-installed MetaMask
86+
if (a.isInstalled) return -1;
87+
if (b.isInstalled) return 1;
88+
return 0;
89+
}
90+
if (a.name === WALLET_CONNECTORS.METAMASK) return -1;
91+
if (b.name === WALLET_CONNECTORS.METAMASK) return 1;
92+
return 0;
93+
});
8094

8195
const buttonSet = new Set();
8296
return buttons
@@ -139,11 +153,10 @@ function ConnectWallet(props: ConnectWalletProps) {
139153
}, [walletDiscoverySupported, defaultButtons, installedWalletButtons, isShowAllWallets, totalExternalWalletsCount]);
140154

141155
const handleWalletClick = (button: ExternalButton) => {
142-
const isInstalled = button.hasInjectedWallet || (!button.hasWalletConnect && !button.hasInstallLinks);
143156
analytics?.track(ANALYTICS_EVENTS.EXTERNAL_WALLET_SELECTED, {
144-
connector: isInstalled ? button.name : button.hasWalletConnect ? WALLET_CONNECTORS.WALLET_CONNECT_V2 : "",
157+
connector: button.isInstalled ? button.name : button.hasWalletConnect ? WALLET_CONNECTORS.WALLET_CONNECT_V2 : "",
145158
wallet_name: button.displayName,
146-
is_installed: isInstalled,
159+
is_installed: button.isInstalled,
147160
is_injected: button.hasInjectedWallet,
148161
chain_namespaces: button.chainNamespaces,
149162
has_wallet_connect: button.hasWalletConnect,
@@ -165,19 +178,21 @@ function ConnectWallet(props: ConnectWalletProps) {
165178
return;
166179
}
167180

181+
// connect with connector if injected and single chain namespace or custom connector (except MetaMask)
168182
const isInjectedConnectorAndSingleChainNamespace = button.hasInjectedWallet && button.chainNamespaces?.length === 1;
169-
// if doesn't have wallet connect & doesn't have install links, must be a custom connector
170-
const isCustomConnector = !button.hasInjectedWallet && !button.hasWalletConnect && !button.hasInstallLinks;
171-
if (isInjectedConnectorAndSingleChainNamespace || isCustomConnector) {
183+
const isCustomConnector = !button.hasInjectedWallet && button.isInstalled;
184+
if (isInjectedConnectorAndSingleChainNamespace || (isCustomConnector && button.name !== WALLET_CONNECTORS.METAMASK)) {
172185
return handleExternalWalletClick({ connector: button.name });
173186
}
174187

188+
// show QR code for wallet connect v2 and MM (non-injected)
175189
if (button.hasWalletConnect) {
176190
setSelectedButton(button);
177191
setSelectedWallet(true);
178192
setCurrentPage(CONNECT_WALLET_PAGES.SELECTED_WALLET);
179193
handleWalletDetailsHeight();
180194
} else {
195+
// show install links
181196
setBodyState({
182197
...bodyState,
183198
installLinks: {

packages/modal/src/ui/components/Login/Login.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ function Login(props: LoginProps) {
346346
analytics?.track(ANALYTICS_EVENTS.EXTERNAL_WALLET_SELECTED, {
347347
connector: wallet.name,
348348
wallet_name: wallet.displayName,
349-
is_installed: true,
349+
is_installed: wallet.isInstalled,
350350
is_injected: wallet.hasInjectedWallet,
351351
chain_namespaces: wallet.chainNamespaces,
352352
has_wallet_connect: wallet.hasWalletConnect,

packages/modal/src/ui/components/Root/Root.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ function Root(props: RootProps) {
265265
displayName: walletRegistryItem.name,
266266
href,
267267
hasInjectedWallet: connectorConfig?.isInjected || false,
268+
isInstalled: !!connectorConfig,
268269
hasWalletConnect: isWalletConnectConnectorIncluded && walletRegistryItem.walletConnect?.sdks?.includes("sign_v2"),
269270
hasInstallLinks: Object.keys(walletRegistryItem.app || {}).length > 0,
270271
walletRegistryItem,
@@ -295,6 +296,7 @@ function Root(props: RootProps) {
295296
name: connector,
296297
displayName: connectorConfig?.label || connector,
297298
hasInjectedWallet: connectorConfig?.isInjected || false,
299+
isInstalled: true,
298300
hasWalletConnect: false,
299301
hasInstallLinks: false,
300302
icon: connectorConfig?.icon,
@@ -318,6 +320,7 @@ function Root(props: RootProps) {
318320
installedConnectors.splice(metamaskConnectorIdx, 1, {
319321
...metamaskRegistryButton,
320322
chainNamespaces: metamaskConnector.chainNamespaces, // preserve the chain namespaces
323+
isInstalled: true,
321324
});
322325
}
323326
}

packages/modal/src/ui/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export type ExternalButton = {
146146
displayName?: string;
147147
href?: string;
148148
icon?: string;
149+
isInstalled?: boolean;
149150
hasInjectedWallet: boolean;
150151
hasWalletConnect: boolean;
151152
hasInstallLinks: boolean;

0 commit comments

Comments
 (0)