@@ -21,13 +21,7 @@ import {
2121 isInvalidContinuationError ,
2222 isNotFoundError ,
2323} from '@/background/services/openPayments' ;
24- import {
25- createTabIfNotExists ,
26- ErrorCode ,
27- GrantResult ,
28- InteractionIntent ,
29- redirectToWelcomeScreen ,
30- } from '@/background/utils' ;
24+ import { createTabIfNotExists , InteractionIntent } from '@/background/utils' ;
3125
3226interface InteractionParams {
3327 interactRef : string ;
@@ -132,14 +126,13 @@ export class OutgoingPaymentGrantService {
132126 walletAmount : WalletAmount ,
133127 walletAddress : WalletAddress ,
134128 { grant, nonce } : Awaited < ReturnType < this[ 'createOutgoingPaymentGrant' ] > > ,
135- intent : InteractionIntent ,
136129 onTabOpen : ( tabId : TabId ) => void ,
137130 existingTabId ?: TabId ,
138131 timeout = ACCEPT_GRANT_TIMEOUT ,
139132 ) : Promise < GrantDetails > {
140133 const signal = AbortSignal . timeout ( timeout ) ;
141134
142- const { interactRef, hash, tabId } = await this . getInteractionInfo (
135+ const { interactRef, hash } = await this . getInteractionInfo (
143136 grant . interact . redirect ,
144137 onTabOpen ,
145138 signal ,
@@ -152,17 +145,10 @@ export class OutgoingPaymentGrantService {
152145 interactRef ,
153146 hash ,
154147 walletAddress . authServer ,
155- intent ,
156- tabId ,
157148 ) ;
158149 signal . throwIfAborted ( ) ;
159150
160- const continuation = await this . continueGrant (
161- grant ,
162- interactRef ,
163- intent ,
164- tabId ,
165- ) ;
151+ const continuation = await this . continueGrant ( grant , interactRef ) ;
166152 if ( ! isFinalizedGrantWithAccessToken ( continuation ) ) {
167153 throw new Error (
168154 'Expected finalized grant. Received non-finalized grant.' ,
@@ -173,13 +159,6 @@ export class OutgoingPaymentGrantService {
173159 this . grant = this . buildGrantDetails ( continuation , walletAmount ) ;
174160 await this . persistGrantDetails ( this . grant ) ;
175161
176- await redirectToWelcomeScreen (
177- this . browser ,
178- tabId ,
179- GrantResult . GRANT_SUCCESS ,
180- intent ,
181- ) ;
182-
183162 return this . grant ;
184163 }
185164
@@ -336,6 +315,8 @@ export class OutgoingPaymentGrantService {
336315 resolve ( { interactRef, hash, tabId } ) ;
337316 } else if ( result === 'grant_rejected' ) {
338317 reject ( new ErrorWithKey ( 'connectWallet_error_grantRejected' ) ) ;
318+ } else if ( result === 'grant_invalid' ) {
319+ reject ( new ErrorWithKey ( 'connectWallet_error_grantInvalid' ) ) ;
339320 }
340321 } catch {
341322 /* do nothing */
@@ -354,29 +335,17 @@ export class OutgoingPaymentGrantService {
354335 interactRef : string ,
355336 hash : string ,
356337 authServer : string ,
357- intent : InteractionIntent ,
358- tabId : TabId ,
359338 ) {
360339 const computeHash = ( authServer : string ) =>
361340 this . computeHash ( clientNonce , interactionNonce , interactRef , authServer ) ;
362- try {
363- if ( hash === ( await computeHash ( authServer ) ) ) return ;
364- // See https://github.com/interledger/web-monetization-extension/pull/1230
365- this . logger . warn (
366- 'verifyInteractionHash failed with authServer without trailing slash' ,
367- ) ;
368- if ( hash === ( await computeHash ( ensureEnd ( authServer , '/' ) ) ) ) return ;
369- throw new Error ( 'Invalid interaction hash' ) ;
370- } catch ( error ) {
371- await redirectToWelcomeScreen (
372- this . browser ,
373- tabId ,
374- GrantResult . GRANT_ERROR ,
375- intent ,
376- ErrorCode . HASH_FAILED ,
377- ) ;
378- throw error ;
379- }
341+
342+ if ( hash === ( await computeHash ( authServer ) ) ) return ;
343+ // See https://github.com/interledger/web-monetization-extension/pull/1230
344+ this . logger . warn (
345+ 'verifyInteractionHash failed with authServer without trailing slash' ,
346+ ) ;
347+ if ( hash === ( await computeHash ( ensureEnd ( authServer , '/' ) ) ) ) return ;
348+ throw new ErrorWithKey ( 'connectWallet_error_hashFailed' ) ;
380349 }
381350
382351 private computeHash = async (
@@ -392,12 +361,7 @@ export class OutgoingPaymentGrantService {
392361 return btoa ( String . fromCharCode . apply ( null , new Uint8Array ( digest ) ) ) ;
393362 } ;
394363
395- private async continueGrant (
396- grant : PendingGrant ,
397- interactRef : string ,
398- intent : InteractionIntent ,
399- tabId : TabId ,
400- ) {
364+ private async continueGrant ( grant : PendingGrant , interactRef : string ) {
401365 try {
402366 const continuation = await this . openPaymentsService . client . grant . continue (
403367 {
@@ -409,14 +373,10 @@ export class OutgoingPaymentGrantService {
409373
410374 return continuation ;
411375 } catch ( error ) {
412- await redirectToWelcomeScreen (
413- this . browser ,
414- tabId ,
415- GrantResult . GRANT_ERROR ,
416- intent ,
417- ErrorCode . CONTINUATION_FAILED ,
418- ) ;
419- throw error ;
376+ this . logger . error ( 'connectWallet_error_continuationFailed' , {
377+ cause : error ,
378+ } ) ;
379+ throw new ErrorWithKey ( 'connectWallet_error_continuationFailed' ) ;
420380 }
421381 }
422382
0 commit comments