Skip to content

Commit 83d7c47

Browse files
authored
chore(bg/utils)!: remove params from PostConnect screen URL (#1331)
1 parent 260149f commit 83d7c47

3 files changed

Lines changed: 23 additions & 116 deletions

File tree

src/background/services/wallet.ts

Lines changed: 17 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ import type {
1919
} from '@/shared/messages';
2020
import { OPEN_PAYMENTS_REDIRECT_URL } from '@/shared/defines';
2121
import {
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() {

src/background/utils.ts

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,6 @@ type OnConnectCallback = Parameters<
2222
Browser['runtime']['onConnect']['addListener']
2323
>[0];
2424

25-
export enum GrantResult {
26-
GRANT_SUCCESS = 'grant_success',
27-
GRANT_ERROR = 'grant_error',
28-
GRANT_REJECTED = 'grant_rejected',
29-
KEY_ADD_SUCCESS = 'key_add_success',
30-
KEY_ADD_ERROR = 'key_add_error',
31-
}
32-
33-
export enum InteractionIntent {
34-
CONNECT = 'connect',
35-
RECONNECT = 'reconnect',
36-
FUNDS = 'funds',
37-
UPDATE_BUDGET = 'update_budget',
38-
}
39-
40-
/** @deprecated Used only for URL params on post-connect screen */
41-
export enum ErrorCode {
42-
CONTINUATION_FAILED = 'continuation_failed',
43-
HASH_FAILED = 'hash_failed',
44-
KEY_ADD_FAILED = 'key_add_failed',
45-
TIMEOUT = 'timeout',
46-
GRANT_INVALID = 'grant_invalid',
47-
UNKNOWN = 'unknown',
48-
}
49-
5025
export class WalletStatusFailureError extends Error {
5126
public readonly details: WalletStatusFailure['details'];
5227
constructor(
@@ -260,19 +235,12 @@ export async function openAppPage(
260235
}
261236
}
262237

263-
export const redirectToWelcomeScreen = async (
238+
export async function redirectToPostConnect(
264239
browser: Browser,
265-
tabId: number | undefined,
266-
result: GrantResult,
267-
intent: InteractionIntent,
268-
errorCode?: ErrorCode,
269-
): Promise<void> => {
270-
const params = new URLSearchParams();
271-
params.set('result', result);
272-
params.set('intent', intent);
273-
if (errorCode) params.set('errorCode', errorCode);
274-
await openAppPage(browser, '/post-connect', { params, tabId });
275-
};
240+
tabId?: TabId,
241+
): Promise<void> {
242+
await openAppPage(browser, '/post-connect', { tabId });
243+
}
276244

277245
export const closeTabsByFilter = async (
278246
browser: Browser,

tests/e2e/walletBudget.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,7 @@ for (const testCase of TEST_CASES) {
190190
);
191191
const continueWaitMs = await continueWaitMsPromise;
192192
await completeGrant(newPage, continueWaitMs);
193-
await expect(newPage).toHaveURL(
194-
(url) => url.searchParams.get('intent') === 'update_budget',
195-
);
193+
await expect(newPage).toHaveURL((url) => url.hash === '#/post-connect');
196194
await newPage.close();
197195

198196
const newGrants = await getStorage(background, [

0 commit comments

Comments
 (0)