Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/background/services/paymentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ export class PaymentStream {
#sessions = new Map<SessionId, PaymentSession>();

constructor(
private frameId: FrameId,
private url: string,
private tabId: TabId,
public readonly frameId: FrameId,
public readonly tabUrl: string,
public readonly tabId: TabId,
private sender: WalletAddress,
private rootLogger: Cradle['rootLogger'],
private deps: ConstructorParameters<typeof PaymentSession>[6],
Expand All @@ -332,11 +332,11 @@ export class PaymentStream {
}
session = new PaymentSession(
receiver,
this.sender,
sessionId,
this.tabId,
this.frameId,
this.url,
this.tabUrl,
this.sender,
{
...this.deps,
logger: this.rootLogger.getLogger(`payment-session/${sessionId}`),
Expand Down
57 changes: 21 additions & 36 deletions src/background/services/paymentSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ export class PaymentSession {
private timeout: ReturnType<typeof setTimeout> | null = null;

constructor(
private receiver: WalletAddress,
public readonly receiver: WalletAddress,
public readonly id: string,
public readonly tabId: number,
public readonly frameId: number,
public readonly tabUrl: string,
private sender: WalletAddress,
private requestId: string,
private tabId: number,
private frameId: number,
private url: string,
private deps: Cradle,
) {
Object.assign(this, this.deps);
Expand Down Expand Up @@ -243,14 +243,6 @@ export class PaymentSession {
// this.logger.log('minSendAmount: binary search gave us', this.minSendAmount);
}

get id() {
return this.requestId;
}

get walletAddress() {
return this.receiver.id;
}

get disabled() {
return this.isDisabled;
}
Expand Down Expand Up @@ -306,17 +298,14 @@ export class PaymentSession {

const { waitTime, monetizationEvent } = this.tabState.getOverpayingDetails(
this.tabId,
this.url,
this.tabUrl,
this.receiver.id,
);

this.debug(`Overpaying: waitTime=${waitTime}`);

if (monetizationEvent && source !== 'tab-change') {
this.sendMonetizationEvent({
requestId: this.requestId,
details: monetizationEvent,
});
this.sendMonetizationEvent(monetizationEvent);
}

const continuePayment = () => {
Expand Down Expand Up @@ -355,12 +344,14 @@ export class PaymentSession {
}
}

private async sendMonetizationEvent(payload: MonetizationEventPayload) {
private async sendMonetizationEvent(
payload: MonetizationEventPayload['details'],
) {
await this.message.sendToTab(
this.tabId,
this.frameId,
'MONETIZATION_EVENT',
payload,
{ requestId: this.id, details: payload },
);
}

Expand Down Expand Up @@ -525,18 +516,15 @@ export class PaymentSession {
});

this.sendMonetizationEvent({
requestId: this.requestId,
details: {
amountSent: {
currency: outgoingPayment.receiveAmount.assetCode,
value: transformBalance(
outgoingPayment.receiveAmount.value,
outgoingPayment.receiveAmount.assetScale,
),
},
incomingPayment: outgoingPayment.receiver,
paymentPointer: this.receiver.id,
amountSent: {
currency: outgoingPayment.receiveAmount.assetCode,
value: transformBalance(
outgoingPayment.receiveAmount.value,
outgoingPayment.receiveAmount.assetScale,
),
},
incomingPayment: outgoingPayment.receiver,
paymentPointer: this.receiver.id,
});

return outgoingPayment;
Expand Down Expand Up @@ -636,14 +624,11 @@ export class PaymentSession {
paymentPointer: this.receiver.id,
};

this.sendMonetizationEvent({
requestId: this.requestId,
details: monetizationEventDetails,
});
this.sendMonetizationEvent(monetizationEventDetails);

// TO DO: find a better source of truth for deciding if overpaying is applicable
if (this.intervalInMs > 1000) {
this.tabState.saveOverpaying(this.tabId, this.url, {
this.tabState.saveOverpaying(this.tabId, this.tabUrl, {
walletAddressId: this.receiver.id,
monetizationEvent: monetizationEventDetails,
intervalInMs: this.intervalInMs,
Expand Down