From 601485ed110421c0ab50b0fcee6425245b1634b2 Mon Sep 17 00:00:00 2001 From: jinoosss Date: Tue, 9 Apr 2024 20:07:07 +0900 Subject: [PATCH] fix: [ADN-534] Fix injection and pop window collision --- .../src/inject/message/message-handler.ts | 7 ++----- .../adena-extension/src/inject/message/methods/common.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/adena-extension/src/inject/message/message-handler.ts b/packages/adena-extension/src/inject/message/message-handler.ts index 77616efd5..7f8f6a63b 100644 --- a/packages/adena-extension/src/inject/message/message-handler.ts +++ b/packages/adena-extension/src/inject/message/message-handler.ts @@ -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 { @@ -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': diff --git a/packages/adena-extension/src/inject/message/methods/common.ts b/packages/adena-extension/src/inject/message/methods/common.ts index 0d9c60968..92e5aaa63 100644 --- a/packages/adena-extension/src/inject/message/methods/common.ts +++ b/packages/adena-extension/src/inject/message/methods/common.ts @@ -60,6 +60,15 @@ export const existsPopups = async (): Promise => { return windows.findIndex((window) => window.type === 'popup') > -1; }; +export const removePopups = async (): Promise => { + 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,