@@ -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 : {
0 commit comments