@@ -304,6 +304,62 @@ describe('ConnectionController', () => {
304304 expect ( ConnectionController . state . status ) . toEqual ( 'connected' )
305305 } )
306306
307+ it ( 'should set wcError and status to disconnected when connectWalletConnect rejects in cached mode on telegram' , async ( ) => {
308+ client . connectWalletConnect = vi . fn ( ) . mockRejectedValueOnce ( new Error ( 'Connection failed' ) )
309+ vi . spyOn ( CoreHelperUtil , 'isPairingExpired' ) . mockReturnValue ( true )
310+ vi . spyOn ( CoreHelperUtil , 'isTelegram' ) . mockReturnValue ( true )
311+
312+ ConnectionController . state . wcError = false
313+
314+ await expect ( ConnectionController . connectWalletConnect ( ) ) . rejects . toThrow ( 'Connection failed' )
315+
316+ expect ( ConnectionController . state . wcError ) . toEqual ( true )
317+ expect ( ConnectionController . state . wcFetchingUri ) . toEqual ( false )
318+ expect ( ConnectionController . state . status ) . toEqual ( 'disconnected' )
319+ } )
320+
321+ it ( 'should set wcError and status to disconnected when connectWalletConnect rejects with cache "always"' , async ( ) => {
322+ client . connectWalletConnect = vi . fn ( ) . mockRejectedValueOnce ( new Error ( 'Connection failed' ) )
323+ vi . spyOn ( CoreHelperUtil , 'isPairingExpired' ) . mockReturnValue ( true )
324+
325+ ConnectionController . state . wcError = false
326+
327+ await expect ( ConnectionController . connectWalletConnect ( { cache : 'always' } ) ) . rejects . toThrow (
328+ 'Connection failed'
329+ )
330+
331+ expect ( ConnectionController . state . wcError ) . toEqual ( true )
332+ expect ( ConnectionController . state . wcFetchingUri ) . toEqual ( false )
333+ expect ( ConnectionController . state . status ) . toEqual ( 'disconnected' )
334+ } )
335+
336+ it ( 'should not set wcError when connectWalletConnect succeeds in cached mode' , async ( ) => {
337+ client . connectWalletConnect = vi . fn ( ) . mockResolvedValueOnce ( undefined )
338+ vi . spyOn ( CoreHelperUtil , 'isPairingExpired' ) . mockReturnValue ( true )
339+ vi . spyOn ( CoreHelperUtil , 'isTelegram' ) . mockReturnValue ( true )
340+
341+ ConnectionController . state . wcError = false
342+
343+ await ConnectionController . connectWalletConnect ( )
344+
345+ expect ( ConnectionController . state . wcError ) . toEqual ( false )
346+ expect ( ConnectionController . state . status ) . toEqual ( 'connected' )
347+ } )
348+
349+ it ( 'should set wcError and rethrow when connectWalletConnect rejects in non-cached mode' , async ( ) => {
350+ client . connectWalletConnect = vi . fn ( ) . mockRejectedValueOnce ( new Error ( 'Connection failed' ) )
351+
352+ ConnectionController . state . wcError = false
353+
354+ await expect ( ConnectionController . connectWalletConnect ( { cache : 'never' } ) ) . rejects . toThrow (
355+ 'Connection failed'
356+ )
357+
358+ expect ( ConnectionController . state . wcError ) . toEqual ( true )
359+ expect ( ConnectionController . state . wcFetchingUri ) . toEqual ( false )
360+ expect ( ConnectionController . state . status ) . toEqual ( 'disconnected' )
361+ } )
362+
307363 it ( 'should handle connectWalletConnect when cache argument is "never"' , async ( ) => {
308364 vi . spyOn ( CoreHelperUtil , 'isTelegram' ) . mockReturnValue ( true )
309365 vi . spyOn ( CoreHelperUtil , 'isSafari' ) . mockReturnValue ( true )
0 commit comments