Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(background): close popup on right time #820

Merged
merged 1 commit into from
Jan 10, 2025
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
2 changes: 1 addition & 1 deletion src/background/services/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export class Background {
this.sendToPopup.send('SET_TRANSIENT_STATE', state);
});

this.events.on('wallet.close_popup', () => {
this.events.on('request_popup_close', () => {
this.sendToPopup.send('CLOSE_POPUP', undefined);
});

Expand Down
2 changes: 1 addition & 1 deletion src/background/services/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface BackgroundEvents {
'open_payments.key_revoked': undefined;
'open_payments.out_of_funds': undefined;
'open_payments.invalid_receiver': { tabId: number };
'wallet.close_popup': undefined;
request_popup_close: undefined;
'storage.rate_of_pay_update': { rate: string };
'storage.state_update': {
state: Storage['state'];
Expand Down
4 changes: 4 additions & 0 deletions src/background/services/outgoingPaymentGrant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class OutgoingPaymentGrantService {
private logger: Cradle['logger'];
private deduplicator: Cradle['deduplicator'];
private openPaymentsService: Cradle['openPaymentsService'];
private events: Cradle['events'];
private browser: Cradle['browser'];
private t: Cradle['t'];

Expand All @@ -59,13 +60,15 @@ export class OutgoingPaymentGrantService {
logger,
deduplicator,
openPaymentsService,
events,
browser,
t,
}: Cradle) {
Object.assign(this, {
storage,
logger,
deduplicator,
events,
openPaymentsService,
browser,
t,
Expand Down Expand Up @@ -144,6 +147,7 @@ export class OutgoingPaymentGrantService {
intent,
);

this.events.emit('request_popup_close');
const { interactRef, hash, tabId } = await this.getInteractionInfo(
grant.interact.redirect,
existingTabId,
Expand Down
5 changes: 1 addition & 4 deletions src/background/services/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export class WalletService {

await this.openPaymentsService.initClient(walletAddress.id);
this.setConnectState('connecting');
this.events.emit('wallet.close_popup');

const [existingTab] = await this.browser.tabs.query({
url: this.browser.runtime.getURL(APP_URL),
Expand Down Expand Up @@ -192,7 +191,6 @@ export class WalletService {
throw error;
}

this.events.emit('wallet.close_popup');
try {
// add key to wallet and try again
this.retryAddPublicKeyToWallet(walletAddress);
Expand Down Expand Up @@ -234,7 +232,6 @@ export class WalletService {
'recurringGrant',
]);

this.events.emit('wallet.close_popup');
await this.outgoingPaymentGrantService.completeOutgoingPaymentGrant(
amount,
walletAddress!,
Expand Down Expand Up @@ -263,7 +260,6 @@ export class WalletService {
'recurringGrant',
]);

this.events.emit('wallet.close_popup');
await this.outgoingPaymentGrantService.completeOutgoingPaymentGrant(
amount,
walletAddress!,
Expand Down Expand Up @@ -329,6 +325,7 @@ export class WalletService {
browserName: this.browserName,
t: this.t,
});
this.events.emit('request_popup_close');
try {
await keyAutoAdd.addPublicKeyToWallet(walletAddress, tabId);
return keyAutoAdd.tabId;
Expand Down