@@ -3,7 +3,7 @@ import bowser from "bowser";
33import { ChangeEvent , useEffect , useMemo , useState } from "react" ;
44import { useTranslation } from "react-i18next" ;
55
6- import { ExternalButton , MODAL_STATUS , ModalStatusType } from "../interfaces" ;
6+ import { ExternalButton , ExternalWalletEventType , MODAL_STATUS , ModalStatusType } from "../interfaces" ;
77import i18n from "../localeImport" ;
88import ExternalWalletButton from "./ExternalWallet/ExternalWalletButton" ;
99import ExternalWalletDetail from "./ExternalWallet/ExternalWalletDetails" ;
@@ -12,13 +12,13 @@ import Loader from "./Loader";
1212
1313interface ExternalWalletsProps {
1414 hideExternalWallets : ( ) => void ;
15- handleExternalWalletClick : ( params : { connector : string } ) => void ;
15+ handleExternalWalletClick : ( params : ExternalWalletEventType ) => void ;
1616 closeModal : ( ) => void ;
1717 config : Record < string , BaseConnectorConfig > ;
1818 walletConnectUri : string | undefined ;
1919 showBackButton : boolean ;
2020 modalStatus : ModalStatusType ;
21- chainNamespace : ChainNamespaceType ;
21+ chainNamespaces : ChainNamespaceType [ ] ;
2222 walletRegistry ?: WalletRegistry ;
2323}
2424
@@ -33,7 +33,7 @@ function formatIOSMobile(params: { uri: string; link?: string }) {
3333 return "" ;
3434}
3535
36- export default function ExternalWallet ( props : ExternalWalletsProps ) {
36+ export default function ExternalWallets ( props : ExternalWalletsProps ) {
3737 const {
3838 hideExternalWallets,
3939 handleExternalWalletClick,
@@ -42,7 +42,7 @@ export default function ExternalWallet(props: ExternalWalletsProps) {
4242 walletConnectUri,
4343 showBackButton,
4444 modalStatus,
45- chainNamespace ,
45+ chainNamespaces ,
4646 walletRegistry,
4747 } = props ;
4848 const [ externalButtons , setExternalButtons ] = useState < ExternalButton [ ] > ( [ ] ) ;
@@ -116,6 +116,10 @@ export default function ExternalWallet(props: ExternalWalletsProps) {
116116 href = universalLink || deepLink ;
117117 }
118118
119+ const registryNamespaces = new Set ( walletRegistryItem . chains ?. map ( ( chain ) => chain . split ( ":" ) [ 0 ] ) ) ;
120+ const injectedChainNamespaces = new Set ( walletRegistryItem . injected ?. map ( ( injected ) => injected . namespace ) ) ;
121+ const availableChainNamespaces = chainNamespaces . filter ( ( x ) => registryNamespaces . has ( x ) || injectedChainNamespaces . has ( x ) ) ;
122+
119123 const button : ExternalButton = {
120124 name : wallet ,
121125 displayName : walletRegistryItem . name ,
@@ -125,13 +129,11 @@ export default function ExternalWallet(props: ExternalWalletsProps) {
125129 hasInstallLinks : Object . keys ( walletRegistryItem . app || { } ) . length > 0 ,
126130 walletRegistryItem,
127131 imgExtension : walletRegistryItem . imgExtension || "svg" ,
132+ chainNamespaces : availableChainNamespaces ,
128133 } ;
129134 // const isBrowserExtensionAvailable = walletRegistryItem.app?.chrome || walletRegistryItem.app?.firefox || walletRegistryItem.app?.edge;
130135 if ( ! button . hasInjectedWallet && ! button . hasWalletConnect && ! button . hasInstallLinks ) return acc ;
131-
132- const chainNamespaces = new Set ( walletRegistryItem . chains ?. map ( ( chain ) => chain . split ( ":" ) [ 0 ] ) ) ;
133- const injectedChainNamespaces = new Set ( walletRegistryItem . injected ?. map ( ( injected ) => injected . namespace ) ) ;
134- if ( ! chainNamespaces . has ( chainNamespace ) && ! injectedChainNamespaces . has ( chainNamespace ) ) return acc ;
136+ if ( availableChainNamespaces . length === 0 ) return acc ;
135137
136138 acc . push ( button ) ;
137139 return acc ;
@@ -196,15 +198,16 @@ export default function ExternalWallet(props: ExternalWalletsProps) {
196198 setExternalButtons ( buttons ) ;
197199 setTotalExternalWallets ( buttons . length ) ;
198200 }
199- } , [ config , deviceDetails , adapterVisibilityMap , walletRegistry , walletSearch , chainNamespace , walletDiscoverySupported ] ) ;
201+ } , [ config , deviceDetails , adapterVisibilityMap , walletRegistry , walletSearch , chainNamespaces , walletDiscoverySupported ] ) ;
200202
201203 const handleWalletClick = ( button : ExternalButton ) => {
202- // if has injected wallet, connect to injected wallet
203- // if doesn't have wallet connect & doesn't have install links, must be a custom adapter
204- if ( button . hasInjectedWallet || ( ! button . hasWalletConnect && ! button . hasInstallLinks ) ) {
204+ // if has injected wallet and single chain namespace, connect to injected wallet
205+ const isInjectedConnectorAndSingleChainNamespace = button . hasInjectedWallet && button . chainNamespaces ?. length === 1 ;
206+ // if doesn't have wallet connect & doesn't have install links, must be a custom connector
207+ const isCustomConnector = ! button . hasInjectedWallet && ! button . hasWalletConnect && ! button . hasInstallLinks ;
208+ if ( isInjectedConnectorAndSingleChainNamespace || isCustomConnector ) {
205209 handleExternalWalletClick ( { connector : button . name } ) ;
206210 } else {
207- // else, show wallet detail
208211 setSelectedButton ( button ) ;
209212 }
210213 } ;
@@ -295,6 +298,7 @@ export default function ExternalWallet(props: ExternalWalletsProps) {
295298 goBack = { ( ) => setSelectedButton ( null ) }
296299 walletConnectUri = { walletConnectUri }
297300 closeModal = { closeModal }
301+ handleExternalWalletClick = { handleExternalWalletClick }
298302 />
299303 ) )
300304 ) }
0 commit comments