@@ -3,28 +3,62 @@ import {
33 isInArgentMobileAppBrowser ,
44 ArgentMobileConnector ,
55} from "starknetkit/argentMobile"
6+ import {
7+ BraavosMobileConnector ,
8+ isInBraavosMobileAppBrowser ,
9+ } from "starknetkit/braavosMobile"
610import { InjectedConnector } from "starknetkit/injected"
711import { WebWalletConnector } from "starknetkit/webwallet"
812
9- export const connectors = isInArgentMobileAppBrowser ( )
10- ? [
11- ArgentMobileConnector . init ( {
12- options : {
13- url : typeof window !== "undefined" ? window . location . href : "" ,
14- dappName : "Example dapp" ,
15- chainId : CHAIN_ID ,
16- } ,
17- } ) ,
18- ]
19- : [
20- new InjectedConnector ( { options : { id : "argentX" } } ) ,
21- new InjectedConnector ( { options : { id : "braavos" } } ) ,
13+ const isMobileDevice = ( ) => {
14+ if ( typeof window === "undefined" ) {
15+ return false
16+ }
17+
18+ // Primary method: User Agent + Touch support check
19+ const userAgent = navigator . userAgent . toLowerCase ( )
20+ const isMobileUA =
21+ / a n d r o i d | w e b o s | i p h o n e | i p a d | i p o d | b l a c k b e r r y | w i n d o w s p h o n e / . test ( userAgent )
22+ const hasTouchSupport =
23+ "ontouchstart" in window || navigator . maxTouchPoints > 0
24+
25+ // Backup method: Screen size
26+ const isSmallScreen = window . innerWidth <= 768
27+
28+ // Combine checks: Must match user agent AND (touch support OR small screen)
29+ return isMobileUA && ( hasTouchSupport || isSmallScreen )
30+ }
31+
32+ export const availableConnectors = ( ) => {
33+ if ( isInArgentMobileAppBrowser ( ) ) {
34+ return [
2235 ArgentMobileConnector . init ( {
2336 options : {
2437 url : typeof window !== "undefined" ? window . location . href : "" ,
2538 dappName : "Example dapp" ,
2639 chainId : CHAIN_ID ,
2740 } ,
2841 } ) ,
29- new WebWalletConnector ( { url : ARGENT_WEBWALLET_URL } ) ,
3042 ]
43+ }
44+
45+ if ( isInBraavosMobileAppBrowser ( ) ) {
46+ return [ BraavosMobileConnector . init ( { } ) ]
47+ }
48+
49+ return [
50+ new InjectedConnector ( { options : { id : "argentX" } } ) ,
51+ new InjectedConnector ( { options : { id : "braavos" } } ) ,
52+ ArgentMobileConnector . init ( {
53+ options : {
54+ url : typeof window !== "undefined" ? window . location . href : "" ,
55+ dappName : "Example dapp" ,
56+ chainId : CHAIN_ID ,
57+ } ,
58+ } ) ,
59+ isMobileDevice ( ) ? BraavosMobileConnector . init ( { } ) : null ,
60+ new WebWalletConnector ( { url : ARGENT_WEBWALLET_URL } ) ,
61+ ] . filter ( ( connector ) => connector !== null )
62+ }
63+
64+ export const connectors = availableConnectors ( )
0 commit comments