Skip to content

Commit

Permalink
fix: Fix injection and pop window collision (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Apr 9, 2024
1 parent fe9f54e commit 919cb17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HandlerMethod } from '.';
import { InjectionMessage, InjectionMessageInstance } from './message';
import { existsPopups } from './methods';
import { existsPopups, removePopups } from './methods';
import { InjectCore } from './methods/core';

export class MessageHandler {
Expand Down Expand Up @@ -52,10 +52,7 @@ export class MessageHandler {
}
const isPopup = await existsPopups();
if (isPopup) {
sendResponse(
InjectionMessageInstance.failure('UNRESOLVED_TRANSACTION_EXISTS', {}, message.key),
);
return true;
await removePopups();
}
switch (message.type) {
case 'DO_CONTRACT':
Expand Down
9 changes: 9 additions & 0 deletions packages/adena-extension/src/inject/message/methods/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ export const existsPopups = async (): Promise<boolean> => {
return windows.findIndex((window) => window.type === 'popup') > -1;
};

export const removePopups = async (): Promise<void> => {
const windows = await chrome.windows.getAll();
windows.forEach((window) => {
if (window.type === 'popup' && window.id) {
chrome.windows.remove(window.id);
}
});
};

export const checkEstablished = async (
requestData: InjectionMessage,
sendResponse: (response: any) => void,
Expand Down

0 comments on commit 919cb17

Please sign in to comment.