@@ -19,10 +19,7 @@ import type {
1919} from '@/shared/messages' ;
2020import { OPEN_PAYMENTS_REDIRECT_URL } from '@/shared/defines' ;
2121import {
22- InteractionIntent ,
23- ErrorCode ,
24- GrantResult ,
25- redirectToWelcomeScreen ,
22+ redirectToPostConnect ,
2623 toAmount ,
2724 onPopupOpen ,
2825 closeTabsByFilter ,
@@ -113,7 +110,6 @@ export class WalletService {
113110 await this . openPaymentsService . initClient ( walletAddress . id ) ;
114111
115112 const browser = this . browser ;
116- const intent = InteractionIntent . CONNECT ;
117113
118114 const isKeyAdded = await isKeyAddedToWallet ( walletAddress . id , keyId ) ;
119115 if ( ! isKeyAdded ) {
@@ -142,7 +138,7 @@ export class WalletService {
142138 } catch ( error ) {
143139 cleanupListeners ( ) ;
144140 const err = this . setConnectStateError ( error , 'connect' ) ;
145- await this . redirectOnGrantError ( err || error , intent , tabId ! ) ;
141+ await this . redirectOnGrantError ( err || error , tabId ) ;
146142 throw err || error ;
147143 }
148144 }
@@ -185,15 +181,15 @@ export class WalletService {
185181 } catch ( error ) {
186182 cleanupListeners ( ) ;
187183 const err = this . setConnectStateError ( error , 'connect' ) ;
188- await this . redirectOnGrantError ( err || error , intent , tabId ! ) ;
184+ await this . redirectOnGrantError ( err || error , tabId ) ;
189185 throw err || error ;
190186 }
191187
192188 this . storage . setTransientState ( 'connect' , ( ) => ( {
193189 intent : 'connect' ,
194190 type : 'success' ,
195191 } ) ) ;
196- await this . redirectOnSuccess ( intent , tabId ) ;
192+ await this . redirectOnSuccess ( tabId ) ;
197193 await this . storage . set ( {
198194 walletAddress,
199195 rateOfPay,
@@ -250,11 +246,7 @@ export class WalletService {
250246 error instanceof WalletStatusCancelError && error . code === 'tab_closed' ;
251247
252248 if ( tabId && ! isTabClosed ) {
253- await this . redirectOnGrantError (
254- error ,
255- InteractionIntent . RECONNECT ,
256- tabId ,
257- ) ;
249+ await this . redirectOnGrantError ( error , tabId ) ;
258250 }
259251
260252 if ( isInvalidClientError ( error ) ) {
@@ -267,12 +259,7 @@ export class WalletService {
267259 type : 'success' ,
268260 intent : 'reconnect' ,
269261 } ) ) ;
270- await redirectToWelcomeScreen (
271- this . browser ,
272- tabId ! ,
273- GrantResult . KEY_ADD_SUCCESS ,
274- InteractionIntent . RECONNECT ,
275- ) ;
262+ await this . redirectOnSuccess ( tabId ) ;
276263 }
277264
278265 async disconnectWallet ( force = false ) {
@@ -330,7 +317,7 @@ export class WalletService {
330317 recurring,
331318 assetScale : walletAddress . assetScale ,
332319 } ) ;
333- const intent = InteractionIntent . FUNDS ;
320+
334321 const grant =
335322 await this . outgoingPaymentGrantService . createOutgoingPaymentGrant (
336323 walletAddress ,
@@ -349,7 +336,7 @@ export class WalletService {
349336 ) ;
350337 } catch ( error ) {
351338 const err = this . setConnectStateError ( error , 'add_funds' ) ;
352- await this . redirectOnGrantError ( err || error , intent , tabId ! ) ;
339+ await this . redirectOnGrantError ( err || error , tabId ) ;
353340 throw err || error ;
354341 }
355342
@@ -359,7 +346,7 @@ export class WalletService {
359346 intent : 'add_funds' ,
360347 type : 'success' ,
361348 } ) ) ;
362- await this . redirectOnSuccess ( intent , tabId ) ;
349+ await this . redirectOnSuccess ( tabId ) ;
363350
364351 // cancel existing grants of same type, if any
365352 if ( grants . oneTimeGrant && ! recurring ) {
@@ -388,7 +375,7 @@ export class WalletService {
388375 recurring,
389376 assetScale : walletAddress . assetScale ,
390377 } ) ;
391- const intent = InteractionIntent . UPDATE_BUDGET ;
378+
392379 const grant =
393380 await this . outgoingPaymentGrantService . createOutgoingPaymentGrant (
394381 walletAddress ,
@@ -407,15 +394,15 @@ export class WalletService {
407394 ) ;
408395 } catch ( error ) {
409396 const err = this . setConnectStateError ( error , 'update_budget' ) ;
410- await this . redirectOnGrantError ( err || error , intent , tabId ! ) ;
397+ await this . redirectOnGrantError ( err || error , tabId ) ;
411398 throw err || error ;
412399 }
413400
414401 this . storage . setTransientState ( 'connect' , ( ) => ( {
415- intent,
402+ intent : 'update_budget' ,
416403 type : 'success' ,
417404 } ) ) ;
418- await this . redirectOnSuccess ( intent , tabId ) ;
405+ await this . redirectOnSuccess ( tabId ) ;
419406
420407 // Revoke all existing grants.
421408 // Note: Clear storage only if new grant type is not same as previous grant
@@ -494,63 +481,17 @@ export class WalletService {
494481 await this . storage . setState ( { key_revoked : false } ) ;
495482 }
496483
497- private async redirectOnSuccess ( intent : InteractionIntent , tabId ?: TabId ) {
498- await redirectToWelcomeScreen (
499- this . browser ,
500- tabId ,
501- GrantResult . GRANT_SUCCESS ,
502- intent ,
503- ) ;
484+ private async redirectOnSuccess ( tabId ?: TabId ) {
485+ await redirectToPostConnect ( this . browser , tabId ) ;
504486 }
505487
506- private async redirectOnGrantError (
507- error : WalletStatusFailureError | WalletStatusCancelError | Error ,
508- intent : InteractionIntent ,
509- tabId : TabId ,
510- ) {
511- if ( error instanceof WalletStatusFailureError ) {
512- const ERROR_CODE_MAP : Record <
513- WalletStatusFailureError [ 'code' ] ,
514- ErrorCode
515- > = {
516- grant_hash_failed : ErrorCode . HASH_FAILED ,
517- grant_continuation_failed : ErrorCode . CONTINUATION_FAILED ,
518- timeout : ErrorCode . TIMEOUT ,
519- key_add_failed : ErrorCode . KEY_ADD_FAILED ,
520- grant_invalid : ErrorCode . GRANT_INVALID ,
521- unknown : ErrorCode . UNKNOWN ,
522- } ;
523- await redirectToWelcomeScreen (
524- this . browser ,
525- tabId ,
526- GrantResult . GRANT_ERROR ,
527- intent ,
528- ERROR_CODE_MAP [ error . code ] ,
529- ) ;
530- return ;
531- }
532-
488+ private async redirectOnGrantError ( error : Error , tabId ?: TabId ) {
533489 if ( error instanceof WalletStatusCancelError ) {
534490 if ( error . code === 'tab_closed' ) {
535491 return ;
536492 }
537-
538- await redirectToWelcomeScreen (
539- this . browser ,
540- tabId ,
541- GrantResult . GRANT_REJECTED ,
542- intent ,
543- ) ;
544- return ;
545493 }
546-
547- await redirectToWelcomeScreen (
548- this . browser ,
549- tabId ,
550- GrantResult . GRANT_ERROR ,
551- intent ,
552- ErrorCode . UNKNOWN ,
553- ) ;
494+ await redirectToPostConnect ( this . browser , tabId ) ;
554495 }
555496
556497 public resetConnectState ( ) {
0 commit comments