Skip to content
36 changes: 18 additions & 18 deletions src/background/services/monetization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,31 @@ export class MonetizationService {

const { tabId, frameId, url: fullUrl } = getSender(sender);
const url = removeQueryParams(fullUrl!);
const sessions = this.tabState.getSessions(tabId);

const replacedSessions = new Set<string>();

const sessions = this.tabState.getSessions(tabId);
const existingSessions = new Set<string>();
// Initialize new sessions
for (const { requestId, walletAddress: receiver } of payload) {
// Q: How does this impact client side apps/routing?
const existingSession = sessions.get(requestId);
if (existingSession) {
existingSession.stop();
existingSession.enable(); // if was disabled earlier
existingSessions.add(requestId);
// move existing into correct order
sessions.delete(requestId);
replacedSessions.add(requestId);
sessions.set(requestId, existingSession);
} else {
const session = new PaymentSession(
receiver,
connectedWallet,
requestId,
tabId,
frameId,
url,
deps,
);
sessions.set(requestId, session);
}

const session = new PaymentSession(
receiver,
connectedWallet,
requestId,
tabId,
frameId,
url,
deps,
);

sessions.set(requestId, session);
}

this.events.emit('monetization.state_update', tabId);
Expand All @@ -148,7 +148,7 @@ export class MonetizationService {
) {
for (const session of sessionsArr) {
if (!sessions.get(session.id)) continue;
const source = replacedSessions.has(session.id)
const source = existingSessions.has(session.id)
? 'request-id-reused'
: 'new-link';
void session.start(source);
Expand Down
7 changes: 1 addition & 6 deletions src/background/services/paymentSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,8 @@ export class PaymentSession {
this.stop();
}

/**
* there's no enable() as we replace the sessions with new ones when
* resume/start or removal of disabled attribute at the moment.
* @deprecated
*/
enable() {
throw new Error('Method not implemented.');
this.isDisabled = false;
}

private markInvalid() {
Expand Down