Skip to content

Commit

Permalink
Merge branch 'main' into biome
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi authored Jan 9, 2025
2 parents 4852a25 + 0413c96 commit 0d21145
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 7 deletions.
5 changes: 4 additions & 1 deletion esbuild/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export const getPlugins = ({
}));
},
},
ignorePackagePlugin([/@apidevtools[/|\\]json-schema-ref-parser/]),
ignorePackagePlugin([
/@apidevtools[/|\\]json-schema-ref-parser/,
/@interledger[/|\\]openapi/,
]),
esbuildStylePlugin({
extract: true,
postcss: {
Expand Down
4 changes: 4 additions & 0 deletions src/background/services/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ export class Background {
this.sendToPopup.send('SET_TRANSIENT_STATE', state);
});

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

this.events.on('storage.balance_update', (balance) =>
this.sendToPopup.send('SET_BALANCE', balance),
);
Expand Down
1 change: 1 addition & 0 deletions src/background/services/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface BackgroundEvents {
'open_payments.key_revoked': undefined;
'open_payments.out_of_funds': undefined;
'open_payments.invalid_receiver': { tabId: number };
'connect_wallet.close_popup': void;
'storage.rate_of_pay_update': { rate: string };
'storage.state_update': {
state: Storage['state'];
Expand Down
5 changes: 5 additions & 0 deletions src/background/services/openPayments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ enum InteractionIntent {
export class OpenPaymentsService {
private browser: Cradle['browser'];
private storage: Cradle['storage'];
private events: Cradle['events'];
private deduplicator: Cradle['deduplicator'];
private logger: Cradle['logger'];
private appName: Cradle['appName'];
Expand All @@ -157,6 +158,7 @@ export class OpenPaymentsService {
constructor({
browser,
storage,
events,
deduplicator,
logger,
t,
Expand All @@ -166,6 +168,7 @@ export class OpenPaymentsService {
Object.assign(this, {
browser,
storage,
events,
deduplicator,
logger,
t,
Expand Down Expand Up @@ -553,6 +556,7 @@ export class OpenPaymentsService {
throw err;
});

this.events.emit('connect_wallet.close_popup');
const { interactRef, hash, tabId } = await this.getInteractionInfo(
grant.interact.redirect,
existingTabId,
Expand Down Expand Up @@ -651,6 +655,7 @@ export class OpenPaymentsService {
browserName: this.browserName,
t: this.t,
});
this.events.emit('connect_wallet.close_popup');
try {
await keyAutoAdd.addPublicKeyToWallet(walletAddress, existingTabId);
return keyAutoAdd.tabId;
Expand Down
6 changes: 0 additions & 6 deletions src/background/services/sendToPopup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export class SendToPopup {

private isConnected = false;
private port: Runtime.Port;
private queue = new Map<keyof BackgroundToPopupMessagesMap, any>();

constructor({ browser }: Cradle) {
Object.assign(this, { browser });
Expand All @@ -25,10 +24,6 @@ export class SendToPopup {
}
this.port = port;
this.isConnected = true;
for (const [type, data] of this.queue) {
this.send(type, data);
this.queue.delete(type);
}
port.onDisconnect.addListener(() => {
this.isConnected = false;
});
Expand All @@ -44,7 +39,6 @@ export class SendToPopup {
data: BackgroundToPopupMessagesMap[T],
) {
if (!this.isConnected) {
this.queue.set(type, data);
return;
}
const message = { type, data } as BackgroundToPopupMessage;
Expand Down
2 changes: 2 additions & 0 deletions src/pages/popup/lib/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export const MessageContextProvider = ({
case 'SET_TAB_DATA':
case 'SET_TRANSIENT_STATE':
return dispatch(message);
case 'CLOSE_POPUP':
return window.close();
}
});
port.onDisconnect.addListener(() => {
Expand Down
1 change: 1 addition & 0 deletions src/shared/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export interface BackgroundToPopupMessagesMap {
SET_TAB_DATA: PopupState['tab'];
SET_STATE: { state: Storage['state']; prevState: Storage['state'] };
SET_TRANSIENT_STATE: PopupTransientState;
CLOSE_POPUP: void;
}

export type BackgroundToPopupMessage = {
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/pages/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export async function openPopup(
await popup.reload({ waitUntil: 'networkidle' });
await popup.waitForSelector('#main', { timeout: 500 });
}

// prevent popup from closing via `window.close()`
popup.exposeFunction('close', () => {});

return popup;
}

Expand Down

0 comments on commit 0d21145

Please sign in to comment.