@@ -12,10 +12,15 @@ const mockWindow = {
1212 }
1313}
1414
15+ const actualWindow = window
16+
1517describe ( 'MobileWalletUtil' , ( ) => {
1618 beforeEach ( ( ) => {
1719 vi . restoreAllMocks ( )
18- vi . stubGlobal ( 'window' , { location : { href : ORIGINAL_HREF } } )
20+ vi . stubGlobal ( 'window' , {
21+ ...actualWindow ,
22+ location : { href : ORIGINAL_HREF }
23+ } )
1924
2025 mockChainControllerState ( { activeChain : ConstantsUtil . CHAIN . SOLANA } )
2126 } )
@@ -33,6 +38,26 @@ describe('MobileWalletUtil', () => {
3338 expect ( window . location . href ) . toBe ( expectedUrl )
3439 } )
3540
41+ it ( 'should redirect to Binance Web3 Wallet when Binance is not installed' , ( ) => {
42+ MobileWalletUtil . handleMobileDeeplinkRedirect (
43+ CUSTOM_DEEPLINK_WALLETS . BINANCE . id ,
44+ ConstantsUtil . CHAIN . BITCOIN
45+ )
46+
47+ const actualUrl = new URL ( window . location . href )
48+ const actualDpEncoded = actualUrl . searchParams . get ( '_dp' ) !
49+ const actualDp = new URL ( atob ( actualDpEncoded ) )
50+
51+ const encodedHref = encodeURIComponent ( ORIGINAL_HREF )
52+ const expectedStartPagePath = window . btoa ( '/pages/browser/index' )
53+ const expectedStartPageQuery = window . btoa ( `url=${ encodedHref } &defaultChainId=1` )
54+
55+ expect ( actualUrl . origin + actualUrl . pathname ) . toBe ( CUSTOM_DEEPLINK_WALLETS . BINANCE . url )
56+ expect ( actualDp . searchParams . get ( 'appId' ) ) . toBe ( CUSTOM_DEEPLINK_WALLETS . BINANCE . appId )
57+ expect ( actualDp . searchParams . get ( 'startPagePath' ) ) . toBe ( expectedStartPagePath )
58+ expect ( actualDp . searchParams . get ( 'startPageQuery' ) ) . toBe ( expectedStartPageQuery )
59+ } )
60+
3661 it ( 'should not redirect when Phantom is installed' , ( ) => {
3762 vi . stubGlobal ( 'window' , {
3863 ...mockWindow ,
@@ -48,6 +73,21 @@ describe('MobileWalletUtil', () => {
4873 expect ( window . location . href ) . toBe ( originalHref )
4974 } )
5075
76+ it ( 'should not redirect when Binance Web3 Wallet is installed' , ( ) => {
77+ vi . stubGlobal ( 'window' , {
78+ ...mockWindow ,
79+ binancew3w : { }
80+ } )
81+
82+ const originalHref = window . location . href
83+ MobileWalletUtil . handleMobileDeeplinkRedirect (
84+ CUSTOM_DEEPLINK_WALLETS . BINANCE . id ,
85+ ConstantsUtil . CHAIN . BITCOIN
86+ )
87+
88+ expect ( window . location . href ) . toBe ( originalHref )
89+ } )
90+
5191 it ( 'should redirect to Coinbase Wallet when it is not installed' , ( ) => {
5292 MobileWalletUtil . handleMobileDeeplinkRedirect (
5393 CUSTOM_DEEPLINK_WALLETS . COINBASE . id ,
0 commit comments