diff --git a/release.config.cjs b/release.config.cjs index b6a6d93..58b1435 100644 --- a/release.config.cjs +++ b/release.config.cjs @@ -55,6 +55,10 @@ module.exports = { type: 'chore', release: 'patch', }, + { + type: 'code', + release: 'patch', + }, { type: 'no-release', release: false, @@ -142,19 +146,17 @@ module.exports = { }, ], [ - "semantic-release-replace-plugin", + 'semantic-release-replace-plugin', { - "replacements": [ + replacements: [ { - "files": [ - "src/version.ts" - ], - "from": "export const __VERSION__ = '1.0.0'", - "to": "export const __VERSION__ = '${nextRelease.version}'", - "countMatches": true - } - ] - } + files: ['src/version.ts'], + from: "export const __VERSION__ = '1.0.0'", + to: "export const __VERSION__ = '${nextRelease.version}'", + countMatches: true, + }, + ], + }, ], [ '@semantic-release/exec', diff --git a/src/chrome/background/background.ts b/src/chrome/background/background.ts index 846da8c..95c469d 100644 --- a/src/chrome/background/background.ts +++ b/src/chrome/background/background.ts @@ -107,9 +107,6 @@ const handleNotificationClick = (notificationId: string) => { const tabRemovedListener = (tabId: number) => { ledgerTabWatcher.triggerTabRemoval(tabId) - messageHandler.sendMessageAndWaitForConfirmation( - createMessage.closeDappTab('background', tabId), - ) } chrome.tabs.onUpdated.addListener((tabId, changeInfo) => { diff --git a/src/chrome/helpers/get-tabs-by-origin.ts b/src/chrome/helpers/get-tabs-by-origin.ts new file mode 100644 index 0000000..706b668 --- /dev/null +++ b/src/chrome/helpers/get-tabs-by-origin.ts @@ -0,0 +1,8 @@ +import { ResultAsync } from 'neverthrow' + +export const getTabsByOrigin = (origin: string) => + ResultAsync.fromPromise( + // url pattern match requires a trailing slash + chrome.tabs.query({ url: `${origin}/*` }), + (err) => err as Error, + ) diff --git a/src/chrome/messages/_types.ts b/src/chrome/messages/_types.ts index 9b625c4..6d2ed65 100644 --- a/src/chrome/messages/_types.ts +++ b/src/chrome/messages/_types.ts @@ -24,7 +24,6 @@ export const messageDiscriminator = { cancelWalletInteraction: 'cancelWalletInteraction', closeLedgerTab: 'closeLedgerTab', focusLedgerTab: 'focusLedgerTab', - closeDappTab: 'closeDappTab', extensionStatus: 'extensionStatus', ledgerResponse: 'ledgerResponse', walletToLedger: 'walletToLedger', @@ -192,10 +191,6 @@ export type Messages = { MessageDiscriminator['focusLedgerTab'], {} > - [messageDiscriminator.closeDappTab]: MessageBuilder< - MessageDiscriminator['closeDappTab'], - { tabId: number } - > [messageDiscriminator.incomingDappMessage]: MessageBuilder< MessageDiscriminator['incomingDappMessage'], { data: Record } diff --git a/src/chrome/messages/create-message.ts b/src/chrome/messages/create-message.ts index fff7558..5ab8b61 100644 --- a/src/chrome/messages/create-message.ts +++ b/src/chrome/messages/create-message.ts @@ -138,15 +138,6 @@ export const createMessage = { discriminator: 'closeLedgerTab', messageId: crypto.randomUUID(), }), - closeDappTab: ( - source: MessageSource, - tabId: number, - ): Messages['closeDappTab'] => ({ - source, - tabId, - discriminator: 'closeDappTab', - messageId: crypto.randomUUID(), - }), walletToLedger: ( source: MessageSource, message: LedgerRequest, diff --git a/src/chrome/messages/send-message.ts b/src/chrome/messages/send-message.ts index 81a6ea7..1fe7f47 100644 --- a/src/chrome/messages/send-message.ts +++ b/src/chrome/messages/send-message.ts @@ -1,9 +1,10 @@ -import { ResultAsync } from 'neverthrow' +import { err, ok, ResultAsync } from 'neverthrow' import { ConfirmationMessageError, Message } from './_types' import { getTabById } from 'chrome/helpers/get-tab-by-id' import { sendMessage as chromeSendMessage } from 'chrome/helpers/send-message' import { sendMessageToTab as chromeSendMessageToTab } from 'chrome/helpers/send-message-to-tab' +import { getTabsByOrigin } from 'chrome/helpers/get-tabs-by-origin' export type SendMessage = typeof sendMessage export const sendMessage = ( @@ -19,8 +20,20 @@ export const sendMessage = ( message: 'could not find tab, user may have closed it', jsError: error, })) - .andThen(() => - chromeSendMessageToTab(tabId, message).mapErr((error) => ({ + .orElse((error) => { + if (message.discriminator === 'walletResponse') { + const maybeOrigin: string | undefined = message.data?.metadata.origin + if (maybeOrigin) { + return getTabsByOrigin(maybeOrigin) + .andThen((tabs) => (tabs[0] ? ok(tabs[0]) : err(error))) + .orElse(() => err(error)) + } + } + + return err(error) + }) + .andThen((tab) => + chromeSendMessageToTab(tab.id!, message).mapErr((error) => ({ reason: 'couldNotSendMessageToTab', jsError: error, })), diff --git a/src/chrome/offscreen/wallet-connection/message-handler.ts b/src/chrome/offscreen/wallet-connection/message-handler.ts index 8b98235..de7f093 100644 --- a/src/chrome/offscreen/wallet-connection/message-handler.ts +++ b/src/chrome/offscreen/wallet-connection/message-handler.ts @@ -222,22 +222,6 @@ export const WalletConnectionMessageHandler = (input: { .add(message.data, message.data.interactionId) .map(() => ({ sendConfirmation: false })) - case messageDiscriminator.closeDappTab: { - const { tabId } = message - return messagesRouter - .getAndRemoveByTabId(tabId) - .mapErr(() => ({ reason: 'tabIdNotFound' })) - .map((interactionIds) => { - for (const interactionId of interactionIds) { - ResultAsync.combine([ - dAppRequestQueue.cancel(interactionId), - incomingWalletMessageQueue.cancel(interactionId), - ]) - } - }) - .map(() => ({ sendConfirmation: false })) - } - default: return errAsync({ reason: 'unhandledMessageDiscriminator',