From 58d630744bc3c1a9cfa2faa58a6c928653e1076f Mon Sep 17 00:00:00 2001 From: escapedcat Date: Fri, 8 Jul 2022 15:05:32 +0800 Subject: [PATCH 01/47] refactor!: manifest v3 support #1051 --- .../actions/setup/setIcon.js | 27 ++++++ src/extension/background-script/index.ts | 25 +++++- src/extension/content-script/injectScript.ts | 8 +- src/manifest.json | 30 ++++--- src/manifest.json.development.sample | 90 ------------------- 5 files changed, 75 insertions(+), 105 deletions(-) create mode 100644 src/extension/background-script/actions/setup/setIcon.js delete mode 100644 src/manifest.json.development.sample diff --git a/src/extension/background-script/actions/setup/setIcon.js b/src/extension/background-script/actions/setup/setIcon.js new file mode 100644 index 0000000000..fe1a2f553c --- /dev/null +++ b/src/extension/background-script/actions/setup/setIcon.js @@ -0,0 +1,27 @@ +import browser from "webextension-polyfill"; + +const setIcon = async (message, sender) => { + // TODO: refactor names / rename files? + const names = { + active: "alby_icon_yellow", + off: "alby_icon_sleeping", + }; + const name = names[message.args.icon]; + return browser.action + .setIcon({ + path: { + 16: `assets/icons/${name}_16x16.png`, + 32: `assets/icons/${name}_32x32.png`, + 48: `assets/icons/${name}_48x48.png`, + 128: `assets/icons/${name}_128x128.png`, + }, + tabId: sender.tab.id, + }) + .then(() => { + return { + data: true, + }; + }); +}; + +export default setIcon; diff --git a/src/extension/background-script/index.ts b/src/extension/background-script/index.ts index 4bc1e08138..34f0200f99 100644 --- a/src/extension/background-script/index.ts +++ b/src/extension/background-script/index.ts @@ -34,6 +34,7 @@ const extractLightningData = ( // Adding a short delay because I've seen cases where this call has happened too fast // before the receiving side in the content-script was connected/listening setTimeout(() => { + // double check: https://developer.chrome.com/docs/extensions/mv3/migrating_to_service_workers/#alarms browser.tabs.sendMessage(tabId, { action: "extractLightningData", }); @@ -57,10 +58,26 @@ const updateIcon = async ( .equalsIgnoreCase(url.host) .first(); - await setIcon( - allowance ? ExtensionIcon.Active : ExtensionIcon.Default, - tabId - ); + // TODO: move to some config file + const names = { + active: "alby_icon_yellow", + off: "alby_icon_sleeping", + }; + let name; + if (allowance) { + name = names.active; + } else { + name = names.off; + } + return browser.action.setIcon({ + path: { + 16: `assets/icons/${name}_16x16.png`, + 32: `assets/icons/${name}_32x32.png`, + 48: `assets/icons/${name}_48x48.png`, + 128: `assets/icons/${name}_128x128.png`, + }, + tabId: tabId, + }); }; const debugLogger = (message: unknown, sender: Runtime.MessageSender) => { diff --git a/src/extension/content-script/injectScript.ts b/src/extension/content-script/injectScript.ts index a5594d3b5b..f0ebc72d75 100644 --- a/src/extension/content-script/injectScript.ts +++ b/src/extension/content-script/injectScript.ts @@ -1,3 +1,5 @@ +import browser from "webextension-polyfill"; + // load the inpage scripts // only an inpage script gets access to the document // and the document can interact with the extension through the inpage script @@ -9,7 +11,11 @@ export default function injectScript(url: string) { const scriptEl = document.createElement("script"); scriptEl.setAttribute("async", "false"); scriptEl.setAttribute("type", "text/javascript"); - scriptEl.setAttribute("src", url); + scriptEl.setAttribute( + "src", + browser.extension.getURL("js/inpageScript.bundle.js") // https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#sunset-deprecated-apis + ); + container.appendChild(scriptEl); container.insertBefore(scriptEl, container.children[0]); scriptEl.onload = () => { container.removeChild(scriptEl); diff --git a/src/manifest.json b/src/manifest.json index 37ab1dc6b0..9d9812ee6e 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { - "manifest_version": 2, + "manifest_version": 3, "name": "Alby - Bitcoin Lightning Wallet", - "version": "0.0.0", + "version": "1.0.0", "icons": { "16": "assets/icons/alby_icon_yellow_16x16.png", @@ -11,18 +11,29 @@ }, "description": "The Bitcoin Lightning wallet for direct payments across the globe, Bitcoin Lightning applications and passwordless logins.", "homepage_url": "https://getAlby.com/", - "web_accessible_resources": ["js/inpageScript.bundle.js"], + + "COMMENT_web_accessible_resources": "https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#web-accessible-resources", + "web_accessible_resources": [ + { + "resources": ["js/inpageScript.bundle.js"] + } + ], + "permissions": [ "notifications", "activeTab", "tabs", "storage", - "unlimitedStorage", "nativeMessaging", - "*://*/*" + "unlimitedStorage" ], + "host_permissions": ["*://*/*"], - "content_security_policy": "script-src 'self'; object-src 'self'", + "COMMENT_content_security_policy": [ + "https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#content-security-policy", + "https://developer.chrome.com/docs/extensions/mv3/mv3-migration-checklist/#security_checklist" + ], + "content_security_policy.extension_pages": "script-src 'self'; object-src 'self'", "__chrome|firefox__author": "Alby", "__opera__developer": { @@ -35,10 +46,10 @@ } }, - "__chrome__minimum_chrome_version": "49", + "__chrome__minimum_chrome_version": "88", "__opera__minimum_opera_version": "36", - "browser_action": { + "action": { "default_popup": "popup.html", "default_icon": { "16": "assets/icons/alby_icon_yellow_16x16.png", @@ -89,8 +100,7 @@ }, "background": { - "scripts": ["js/background.bundle.js"], - "__chrome|opera__persistent": true + "service_worker": "js/background.bundle.js" }, "content_scripts": [ diff --git a/src/manifest.json.development.sample b/src/manifest.json.development.sample deleted file mode 100644 index 309a5569c1..0000000000 --- a/src/manifest.json.development.sample +++ /dev/null @@ -1,90 +0,0 @@ -{ - "manifest_version": 2, - "name": "Lightning", - "version": "1.0.0", - - "icons": { - "16": "assets/icons/favicon-16.png", - "32": "assets/icons/favicon-32.png", - "48": "assets/icons/favicon-48.png", - "128": "assets/icons/favicon-128.png" - }, - "description": "Lightning up the browser", - "homepage_url": "https://github.com/bumi", - "short_name": "Lightning", - "web_accessible_resources": ["js/inpageScript.bundle.js"], - "permissions": [ - "nativeMessaging", - "notifications", - "activeTab", - "storage", - "webRequest", - "webRequestBlocking", - "http://*/*", - "https://*/*" - ], - "optional_permissions": [ - "nativeMessaging" - ], - - "content_security_policy": "script-src 'self' http://localhost:8097; object-src 'self'; connect-src ws://localhost:8097 ws://localhost:9090 https://alice-wallet.webln.external.myzel.io:443 https://blockchain.info/ticker", - - "__chrome|firefox__author": "bumi", - "__opera__developer": { - "name": "bumi" - }, - - "__firefox__applications": { - "gecko": { - "id": "{424FB1AD-CC3B-4856-B6A0-7786F8CA9D17}" - } - }, - - "__chrome__minimum_chrome_version": "49", - "__opera__minimum_opera_version": "36", - - "browser_action": { - "default_popup": "popup.html", - "default_icon": { - "16": "assets/icons/favicon-16.png", - "32": "assets/icons/favicon-32.png", - "48": "assets/icons/favicon-48.png", - "128": "assets/icons/favicon-128.png" - }, - "default_title": "Lightning", - "__chrome|opera__chrome_style": false, - "__firefox__browser_style": false - }, - - "commands": { - "_execute_browser_action": { - "suggested_key": { - "default": "Alt+Shift+A" - } - } - }, - - "__chrome|opera__options_page": "options.html", - "options_ui": { - "page": "options.html", - "open_in_tab": true, - "__chrome__chrome_style": false - }, - - "background": { - "scripts": [ - "js/background.bundle.js" - ], - "__chrome|opera__persistent": true - }, - - "content_scripts": [{ - "matches": [ - "http://*/*", - "https://*/*" - ], - "js": [ - "js/contentScriptOnEnd.bundle.js" - ] - }] -} From 7f61c9a9bab0164b852b5a4b4872793ef0ea1d18 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Fri, 8 Jul 2022 15:42:12 +0800 Subject: [PATCH 02/47] refactor!: fix manifest v3 errors #1051 --- src/manifest.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/manifest.json b/src/manifest.json index 9d9812ee6e..59a10da42e 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -15,7 +15,8 @@ "COMMENT_web_accessible_resources": "https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#web-accessible-resources", "web_accessible_resources": [ { - "resources": ["js/inpageScript.bundle.js"] + "resources": ["js/inpageScript.bundle.js"], + "matches": ["https://*/*"] } ], @@ -80,7 +81,6 @@ } ], "default_title": "Alby - Bitcoin Lightning Wallet", - "__chrome|opera__chrome_style": false, "__firefox__browser_style": false }, @@ -95,7 +95,6 @@ "options_ui": { "page": "options.html", "open_in_tab": true, - "__chrome|opera__chrome_style": false, "__firefox__browser_style": false }, From 992efc51c1f0286da466725405597792febf1e60 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Mon, 11 Jul 2022 15:17:28 +0800 Subject: [PATCH 03/47] test: update ext-id finding #1051 --- tests/e2e/helpers/loadExtension.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/tests/e2e/helpers/loadExtension.ts b/tests/e2e/helpers/loadExtension.ts index 2e9fef0f6a..80983a7738 100644 --- a/tests/e2e/helpers/loadExtension.ts +++ b/tests/e2e/helpers/loadExtension.ts @@ -27,23 +27,17 @@ export const loadExtension = async () => { // trick to bring the new welcome page to the front await delay(1000); + const page = await browser.newPage(); await page.setViewport({ width: 1366, height: 768 }); - // get extensionId - // https://github.com/microsoft/playwright/issues/5593#issuecomment-949813218 - await page.goto("chrome://inspect/#extensions"); - // https://techoverflow.net/2019/01/26/puppeteer-get-text-content-inner-html-of-an-element/ - // TODO: check if just `page.$('...') will work because it should: - // https://puppeteer.github.io/puppeteer/docs/puppeteer.elementhandle - const url = await page.evaluate( - () => - ( - document.querySelector( - '#extensions-list div[class="url"]' - ) as HTMLElement - ).innerText + const targets = await browser.targets(); + const albyExtensionServiceWorkerTarget = targets.find( + (target) => target.url().indexOf("chrome-extension") > -1 ); + if (!albyExtensionServiceWorkerTarget) return; + + const url = albyExtensionServiceWorkerTarget.url(); const [, , extensionId] = url.split("/"); const extensionOptionHtml = "welcome.html"; From a4c5d69f8edb6c4caacd7e59bc7c7a203ee3594d Mon Sep 17 00:00:00 2001 From: escapedcat Date: Tue, 12 Jul 2022 12:38:24 +0800 Subject: [PATCH 04/47] fix(axios): use fetach-adapter within service-worker #1124 --- package.json | 1 + .../actions/setup/setIcon.js | 27 ------------------- .../background-script/connectors/lndhub.ts | 3 +++ src/extension/background-script/index.ts | 24 +++-------------- src/manifest.json | 2 +- yarn.lock | 5 ++++ 6 files changed, 14 insertions(+), 48 deletions(-) delete mode 100644 src/extension/background-script/actions/setup/setIcon.js diff --git a/package.json b/package.json index 18a358db93..e95d3d1934 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "@runcitadel/sdk": "^0.3.8", "@tailwindcss/forms": "^0.5.2", "@tailwindcss/line-clamp": "^0.4.2", + "@vespaiach/axios-fetch-adapter": "^0.3.0", "axios": "^0.27.2", "bech32": "^2.0.0", "bolt11": "^1.4.0", diff --git a/src/extension/background-script/actions/setup/setIcon.js b/src/extension/background-script/actions/setup/setIcon.js deleted file mode 100644 index fe1a2f553c..0000000000 --- a/src/extension/background-script/actions/setup/setIcon.js +++ /dev/null @@ -1,27 +0,0 @@ -import browser from "webextension-polyfill"; - -const setIcon = async (message, sender) => { - // TODO: refactor names / rename files? - const names = { - active: "alby_icon_yellow", - off: "alby_icon_sleeping", - }; - const name = names[message.args.icon]; - return browser.action - .setIcon({ - path: { - 16: `assets/icons/${name}_16x16.png`, - 32: `assets/icons/${name}_32x32.png`, - 48: `assets/icons/${name}_48x48.png`, - 128: `assets/icons/${name}_128x128.png`, - }, - tabId: sender.tab.id, - }) - .then(() => { - return { - data: true, - }; - }); -}; - -export default setIcon; diff --git a/src/extension/background-script/connectors/lndhub.ts b/src/extension/background-script/connectors/lndhub.ts index 7cbc7ff608..b878c0b33e 100644 --- a/src/extension/background-script/connectors/lndhub.ts +++ b/src/extension/background-script/connectors/lndhub.ts @@ -1,3 +1,4 @@ +import fetchAdapter from "@vespaiach/axios-fetch-adapter"; import axios, { AxiosRequestConfig, Method } from "axios"; import type { AxiosResponse } from "axios"; import lightningPayReq from "bolt11"; @@ -345,6 +346,7 @@ export default class LndHub implements Connector { }, { headers: defaultHeaders, + adapter: fetchAdapter, } ); @@ -381,6 +383,7 @@ export default class LndHub implements Connector { ...defaultHeaders, Authorization: `Bearer ${this.access_token}`, }, + adapter: fetchAdapter, }; if (method === "POST") { diff --git a/src/extension/background-script/index.ts b/src/extension/background-script/index.ts index 34f0200f99..585a2b6d02 100644 --- a/src/extension/background-script/index.ts +++ b/src/extension/background-script/index.ts @@ -58,26 +58,10 @@ const updateIcon = async ( .equalsIgnoreCase(url.host) .first(); - // TODO: move to some config file - const names = { - active: "alby_icon_yellow", - off: "alby_icon_sleeping", - }; - let name; - if (allowance) { - name = names.active; - } else { - name = names.off; - } - return browser.action.setIcon({ - path: { - 16: `assets/icons/${name}_16x16.png`, - 32: `assets/icons/${name}_32x32.png`, - 48: `assets/icons/${name}_48x48.png`, - 128: `assets/icons/${name}_128x128.png`, - }, - tabId: tabId, - }); + await setIcon( + allowance ? ExtensionIcon.Active : ExtensionIcon.Default, + tabId + ); }; const debugLogger = (message: unknown, sender: Runtime.MessageSender) => { diff --git a/src/manifest.json b/src/manifest.json index 59a10da42e..81dc42e401 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "Alby - Bitcoin Lightning Wallet", - "version": "1.0.0", + "version": "0.0.0", "icons": { "16": "assets/icons/alby_icon_yellow_16x16.png", diff --git a/yarn.lock b/yarn.lock index 4ee4e04023..d2aaa79e73 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4361,6 +4361,11 @@ "@typescript-eslint/types" "5.31.0" eslint-visitor-keys "^3.3.0" +"@vespaiach/axios-fetch-adapter@^0.3.0": + version "0.3.0" + resolved "https://registry.yarnpkg.com/@vespaiach/axios-fetch-adapter/-/axios-fetch-adapter-0.3.0.tgz#abbd23478260a317165d0c52297306af9d39bb24" + integrity sha512-X3U9VANu+8R4Wu/77bAUiUSqgeTelDFZeJcGZDe63DiFcPI6onjrMWrG3py/N4Qf8qCU3YLq+wO2d8V6ftYcaw== + "@webassemblyjs/ast@1.11.0": version "1.11.0" resolved "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.0.tgz" From 902713c162178b15ce731c6972e913b68a0cc66e Mon Sep 17 00:00:00 2001 From: escapedcat Date: Thu, 1 Sep 2022 15:32:07 +0800 Subject: [PATCH 05/47] chore: update opera version #1051 --- src/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manifest.json b/src/manifest.json index 81dc42e401..6f53872217 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -48,7 +48,7 @@ }, "__chrome__minimum_chrome_version": "88", - "__opera__minimum_opera_version": "36", + "__opera__minimum_opera_version": "74", "action": { "default_popup": "popup.html", From 3a21e4ed8065c8dc387315a87a7e9ca69d08bff5 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Fri, 9 Sep 2022 11:42:00 +0800 Subject: [PATCH 06/47] revert: remove outdated function wich was added earlier in this PR #1051 --- src/extension/content-script/injectScript.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/extension/content-script/injectScript.ts b/src/extension/content-script/injectScript.ts index f0ebc72d75..e33cdc0fa2 100644 --- a/src/extension/content-script/injectScript.ts +++ b/src/extension/content-script/injectScript.ts @@ -1,5 +1,3 @@ -import browser from "webextension-polyfill"; - // load the inpage scripts // only an inpage script gets access to the document // and the document can interact with the extension through the inpage script @@ -11,10 +9,7 @@ export default function injectScript(url: string) { const scriptEl = document.createElement("script"); scriptEl.setAttribute("async", "false"); scriptEl.setAttribute("type", "text/javascript"); - scriptEl.setAttribute( - "src", - browser.extension.getURL("js/inpageScript.bundle.js") // https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#sunset-deprecated-apis - ); + scriptEl.setAttribute("src", url); container.appendChild(scriptEl); container.insertBefore(scriptEl, container.children[0]); scriptEl.onload = () => { From 8321efbc8a53c33ce92e3865da7b89b189adb40a Mon Sep 17 00:00:00 2001 From: escapedcat Date: Fri, 9 Sep 2022 12:29:23 +0800 Subject: [PATCH 07/47] fix: use further axios adapters #1051 --- src/extension/background-script/actions/lnurl/auth.ts | 6 +++++- .../content-script/batteries/StackOverflow.ts | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/extension/background-script/actions/lnurl/auth.ts b/src/extension/background-script/actions/lnurl/auth.ts index 92e2762560..14ba049cf6 100644 --- a/src/extension/background-script/actions/lnurl/auth.ts +++ b/src/extension/background-script/actions/lnurl/auth.ts @@ -1,3 +1,4 @@ +import fetchAdapter from "@vespaiach/axios-fetch-adapter"; import axios from "axios"; import Hex from "crypto-js/enc-hex"; import hmacSHA256 from "crypto-js/hmac-sha256"; @@ -85,7 +86,10 @@ export async function authFunction({ try { const authResponse = await axios.get( - loginURL.toString() + loginURL.toString(), + { + adapter: fetchAdapter, + } ); // if the service returned with a HTTP 200 we still check if the response data is OK diff --git a/src/extension/content-script/batteries/StackOverflow.ts b/src/extension/content-script/batteries/StackOverflow.ts index 57c1ddb359..12f8ee434b 100644 --- a/src/extension/content-script/batteries/StackOverflow.ts +++ b/src/extension/content-script/batteries/StackOverflow.ts @@ -1,3 +1,4 @@ +import fetchAdapter from "@vespaiach/axios-fetch-adapter"; import axios from "axios"; import type { Battery } from "~/types"; @@ -33,7 +34,8 @@ function htmlToText(html: string) { async function handleQuestionPage(questionId: string): Promise { const questionResponse = await axios.get( // The filter can be generated here: https://api.stackexchange.com/docs/users-by-ids - `https://api.stackexchange.com/2.2/questions/${questionId}?site=stackoverflow&filter=!9bOY8fLl6` + `https://api.stackexchange.com/2.2/questions/${questionId}?site=stackoverflow&filter=!9bOY8fLl6`, + { adapter: fetchAdapter } ); if (!questionResponse) { @@ -54,7 +56,8 @@ async function handleQuestionPage(questionId: string): Promise { const answerResponse = await axios.get( // The filter can be generated here: https://api.stackexchange.com/docs/users-by-ids - `https://api.stackexchange.com/2.2/answers/${questionData.accepted_answer_id}?site=stackoverflow&filter=!-)QWsbXSB(JQ` + `https://api.stackexchange.com/2.2/answers/${questionData.accepted_answer_id}?site=stackoverflow&filter=!-)QWsbXSB(JQ`, + { adapter: fetchAdapter } ); if (!answerResponse) { @@ -78,7 +81,8 @@ async function handleQuestionPage(questionId: string): Promise { async function handleProfilePage(userId: string): Promise { const response = await axios.get( // The filter can be generated here: https://api.stackexchange.com/docs/users-by-ids - `https://api.stackexchange.com/2.2/users/${userId}?site=stackoverflow&filter=!-B3yqvQ2YYGK1t-Hg_ydU` + `https://api.stackexchange.com/2.2/users/${userId}?site=stackoverflow&filter=!-B3yqvQ2YYGK1t-Hg_ydU`, + { adapter: fetchAdapter } ); if (!response) { From a9a61a136012c7304b0a9e32ee216fdd5fa44c7b Mon Sep 17 00:00:00 2001 From: escapedcat Date: Fri, 9 Sep 2022 13:05:33 +0800 Subject: [PATCH 08/47] fix(notifications): update imageUrl for manifest v3 #1051 --- src/common/lib/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/lib/utils.ts b/src/common/lib/utils.ts index f447d50581..7f8a0c3a92 100644 --- a/src/common/lib/utils.ts +++ b/src/common/lib/utils.ts @@ -38,7 +38,7 @@ const utils = { notify: (options: { title: string; message: string }) => { const notification: browser.Notifications.CreateNotificationOptions = { type: "basic", - iconUrl: "assets/icons/alby_icon_yellow_48x48.png", + iconUrl: "../assets/icons/alby_icon_yellow_48x48.png", // it's looking relative from the "js" folder ...options, }; From acd58b12e5a92435dab4e4d69fc8644846572188 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Fri, 9 Sep 2022 13:21:38 +0800 Subject: [PATCH 09/47] fix(manfifest): add mssing bundle to ressources for manifest v3 #1051 --- src/manifest.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/manifest.json b/src/manifest.json index 6f53872217..b95ba49c77 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -15,7 +15,10 @@ "COMMENT_web_accessible_resources": "https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#web-accessible-resources", "web_accessible_resources": [ { - "resources": ["js/inpageScript.bundle.js"], + "resources": [ + "js/inpageScript.bundle.js", + "js/inpageScriptWebLN.bundle.js" + ], "matches": ["https://*/*"] } ], From afe92ff683a1d4c45f67fcd47ae6c9bd30f1971b Mon Sep 17 00:00:00 2001 From: escapedcat Date: Fri, 9 Sep 2022 13:43:48 +0800 Subject: [PATCH 10/47] fix(seticon): use action for manifest v3 #1051 --- .../background-script/actions/setup/setIcon.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/extension/background-script/actions/setup/setIcon.ts b/src/extension/background-script/actions/setup/setIcon.ts index 419e11da4f..800145a715 100644 --- a/src/extension/background-script/actions/setup/setIcon.ts +++ b/src/extension/background-script/actions/setup/setIcon.ts @@ -46,14 +46,15 @@ const setIcon = async (icon: string, tabId: number): Promise => { const theme = state.getState().settings.theme == "dark" ? "_dark" : ""; - return browser.browserAction.setIcon({ + return browser.action.setIcon({ path: { - 16: `assets/icons/${icon}${theme}_16x16.png`, - 32: `assets/icons/${icon}${theme}_32x32.png`, - 48: `assets/icons/${icon}${theme}_48x48.png`, - 128: `assets/icons/${icon}${theme}_128x128.png`, + // it's looking relative from the "js" folder + 16: `../assets/icons/${icon}${theme}_16x16.png`, + 32: `../assets/icons/${icon}${theme}_32x32.png`, + 48: `../assets/icons/${icon}${theme}_48x48.png`, + 128: `../assets/icons/${icon}${theme}_128x128.png`, }, - tabId: tabId, + tabId, }); }; From 29ebf1e96a4868b7911878d7ee4d13e47568e9e6 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Fri, 9 Sep 2022 16:54:11 +0800 Subject: [PATCH 11/47] chore: remove rebase issue #1051 --- src/extension/content-script/injectScript.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/extension/content-script/injectScript.ts b/src/extension/content-script/injectScript.ts index e33cdc0fa2..a5594d3b5b 100644 --- a/src/extension/content-script/injectScript.ts +++ b/src/extension/content-script/injectScript.ts @@ -10,7 +10,6 @@ export default function injectScript(url: string) { scriptEl.setAttribute("async", "false"); scriptEl.setAttribute("type", "text/javascript"); scriptEl.setAttribute("src", url); - container.appendChild(scriptEl); container.insertBefore(scriptEl, container.children[0]); scriptEl.onload = () => { container.removeChild(scriptEl); From c9f359fb0cdcde6a08a5e32a42a83dca1525cd04 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Mon, 10 Oct 2022 20:23:25 +0800 Subject: [PATCH 12/47] chore: trigger actions From 50f79254c0c9cb3f8fb48172d74d462e68c4f788 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Mon, 10 Oct 2022 20:28:06 +0800 Subject: [PATCH 13/47] chore: trigger actions --- src/manifest.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/manifest.json b/src/manifest.json index b95ba49c77..0388f46d5a 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -34,6 +34,7 @@ "host_permissions": ["*://*/*"], "COMMENT_content_security_policy": [ + "TODO: trigger actions", "https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#content-security-policy", "https://developer.chrome.com/docs/extensions/mv3/mv3-migration-checklist/#security_checklist" ], From 8818410bdebb258b68ab4ccdc9fb0eee82a6d207 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Tue, 11 Oct 2022 14:00:04 +0800 Subject: [PATCH 14/47] fix: use further axios adapters #1051 --- src/common/lib/lnurl.ts | 5 ++++- .../actions/cache/getCurrencyRate.ts | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/common/lib/lnurl.ts b/src/common/lib/lnurl.ts index cab00f1c31..c1e70da8c0 100644 --- a/src/common/lib/lnurl.ts +++ b/src/common/lib/lnurl.ts @@ -1,3 +1,4 @@ +import fetchAdapter from "@vespaiach/axios-fetch-adapter"; import axios from "axios"; import lightningPayReq from "bolt11"; import Hex from "crypto-js/enc-hex"; @@ -70,7 +71,9 @@ const lnurl = { lnurlDetails.action = url.searchParams.get("action") || undefined; } else { try { - const res = await axios.get(url.toString()); + const res = await axios.get(url.toString(), { + adapter: fetchAdapter, + }); lnurlDetails = res.data; } catch (e) { throw new Error( diff --git a/src/extension/background-script/actions/cache/getCurrencyRate.ts b/src/extension/background-script/actions/cache/getCurrencyRate.ts index c84a681ba1..cbdf7be2d6 100644 --- a/src/extension/background-script/actions/cache/getCurrencyRate.ts +++ b/src/extension/background-script/actions/cache/getCurrencyRate.ts @@ -1,3 +1,4 @@ +import fetchAdapter from "@vespaiach/axios-fetch-adapter"; import axios from "axios"; import dayjs from "dayjs"; import isSameOrBefore from "dayjs/plugin/isSameOrBefore"; @@ -36,7 +37,10 @@ const getFiatBtcRate = async (currency: CURRENCIES): Promise => { if (exchange === "yadio") { response = await axios.get( - `https://api.yadio.io/exrates/${currency.toLowerCase()}` + `https://api.yadio.io/exrates/${currency.toLowerCase()}`, + { + adapter: fetchAdapter, + } ); const data = await response?.data; return data.BTC / numSatsInBtc; @@ -44,14 +48,20 @@ const getFiatBtcRate = async (currency: CURRENCIES): Promise => { if (exchange === "coindesk") { response = await axios.get( - `https://api.coindesk.com/v1/bpi/currentprice/${currency.toLowerCase()}.json` + `https://api.coindesk.com/v1/bpi/currentprice/${currency.toLowerCase()}.json`, + { + adapter: fetchAdapter, + } ); const data = await response?.data; return data.bpi[currency].rate_float / numSatsInBtc; } response = await axios.get( - `https://getalby.com/api/rates/${currency.toLowerCase()}.json` + `https://getalby.com/api/rates/${currency.toLowerCase()}.json`, + { + adapter: fetchAdapter, + } ); const data = await response?.data; From f247a231798373539ef38a4a594beb6348b834a5 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Tue, 8 Nov 2022 15:31:39 +0100 Subject: [PATCH 15/47] fix: use storage sessions for pw #1051 --- src/app/context/AccountContext.tsx | 52 +++++++++++-------- src/app/context/SettingsContext.tsx | 29 ++++++----- .../actions/accounts/lock.ts | 5 +- .../actions/accounts/unlock.ts | 5 +- .../background-script/actions/setup/status.js | 9 +++- 5 files changed, 58 insertions(+), 42 deletions(-) diff --git a/src/app/context/AccountContext.tsx b/src/app/context/AccountContext.tsx index 312f1c229d..58d42d818f 100644 --- a/src/app/context/AccountContext.tsx +++ b/src/app/context/AccountContext.tsx @@ -102,30 +102,36 @@ export function AccountProvider({ children }: { children: React.ReactNode }) { // Invoked only on on mount. useEffect(() => { - api - .getStatus() - .then((response) => { - const onWelcomePage = - window.location.pathname.indexOf("welcome.html") >= 0; - if (!response.configured && !onWelcomePage) { - utils.openPage("welcome.html"); - window.close(); - } else if (response.unlocked) { - if (response.configured && onWelcomePage) { - utils.redirectPage("options.html"); + setTimeout(() => { + console.log("ACCOUNT CONTEXT EFFECT"); + api + .getStatus() + .then((response) => { + const onWelcomePage = + window.location.pathname.indexOf("welcome.html") >= 0; + if (!response.configured && !onWelcomePage) { + utils.openPage("welcome.html"); + window.close(); + } else if (response.unlocked) { + if (response.configured && onWelcomePage) { + utils.redirectPage("options.html"); + } + setAccountId(response.currentAccountId); + fetchAccountInfo({ accountId: response.currentAccountId }); + } else { + setAccount(null); } - setAccountId(response.currentAccountId); - fetchAccountInfo({ accountId: response.currentAccountId }); - } else { - setAccount(null); - } - }) - .catch((e) => { - toast.error(`An unexpected error occurred (${e.message})`); - }) - .finally(() => { - setLoading(false); - }); + }) + .catch((e) => { + toast.error( + `AccountContext: An unexpected error occurred (${e.message})` + ); + }) + .finally(() => { + setLoading(false); + }); + }, 500); + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/src/app/context/SettingsContext.tsx b/src/app/context/SettingsContext.tsx index 8abda2026c..db71870f00 100644 --- a/src/app/context/SettingsContext.tsx +++ b/src/app/context/SettingsContext.tsx @@ -40,19 +40,22 @@ export const SettingsProvider = ({ // Invoked only on on mount. useEffect(() => { - api - .getSettings() - .then((response) => { - setSettings(response); - }) - .catch((e) => { - toast.error( - `SettingsProvider: An unexpected error occurred (${e.message})` - ); - }) - .finally(() => { - setIsLoading(false); - }); + setTimeout(() => { + console.log("SETTIMGS CONTEXT EFFECT"); + api + .getSettings() + .then((response) => { + setSettings(response); + }) + .catch((e) => { + // toast.error( + // `SettingsProvider: An unexpected error occurred (${e.message})` + // ); + }) + .finally(() => { + setIsLoading(false); + }); + }, 500); }, []); // update rate diff --git a/src/extension/background-script/actions/accounts/lock.ts b/src/extension/background-script/actions/accounts/lock.ts index 1081218008..125e2bd48d 100644 --- a/src/extension/background-script/actions/accounts/lock.ts +++ b/src/extension/background-script/actions/accounts/lock.ts @@ -1,9 +1,10 @@ import type { MessageAccountLock } from "~/types"; -import state from "../../state"; +// import state from "../../state"; const lock = async (message: MessageAccountLock) => { - await state.getState().lock(); + // await state.getState().lock(); + await chrome.storage.session.set({ password: null }); return { data: { unlocked: false }, }; diff --git a/src/extension/background-script/actions/accounts/unlock.ts b/src/extension/background-script/actions/accounts/unlock.ts index 553bb8ede1..f208dac584 100644 --- a/src/extension/background-script/actions/accounts/unlock.ts +++ b/src/extension/background-script/actions/accounts/unlock.ts @@ -4,7 +4,7 @@ import i18n from "~/i18n/i18nConfig"; import { translationI18nNamespace } from "~/i18n/namespaces"; import type { MessageAccountUnlock } from "~/types"; -const unlock = (message: MessageAccountUnlock) => { +const unlock = async (message: MessageAccountUnlock) => { const passwordArg = message.args.password; const password = typeof passwordArg === "number" ? `${passwordArg}` : passwordArg; @@ -31,7 +31,8 @@ const unlock = (message: MessageAccountUnlock) => { } // if everything is fine we keep the password in memory - state.setState({ password }); + // state.setState({ password }); + await chrome.storage.session.set({ password }); return Promise.resolve({ data: { unlocked: true, currentAccountId } }); }; diff --git a/src/extension/background-script/actions/setup/status.js b/src/extension/background-script/actions/setup/status.js index 53c1a7cd30..1808487a5e 100644 --- a/src/extension/background-script/actions/setup/status.js +++ b/src/extension/background-script/actions/setup/status.js @@ -1,7 +1,12 @@ import state from "../../state"; -const status = (message, sender) => { - const unlocked = state.getState().password !== null; +const status = async (message, sender) => { + const storageSessionPassword = await chrome.storage.session.get("password"); + + console.log("STATUS ACTION password: ", storageSessionPassword.password); + + // const unlocked = state.getState().password !== null; + const unlocked = storageSessionPassword.password !== null; const account = state.getState().getAccount(); const currentAccountId = state.getState().currentAccountId; const configured = account != null; From 117a7dc90745e117ba2a675689d148a1708f4264 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Fri, 11 Nov 2022 15:08:26 +0100 Subject: [PATCH 16/47] chore: messy storage.session progress #1051 --- src/app/context/AccountContext.tsx | 5 ++- src/app/context/SettingsContext.tsx | 40 +++++++++++-------- src/app/utils/index.ts | 6 ++- .../background-script/actions/accounts/add.ts | 4 +- .../background-script/actions/accounts/all.ts | 3 ++ .../actions/accounts/decryptedDetails.ts | 4 +- .../actions/allowances/enable.ts | 2 +- .../actions/cache/getCurrencyRate.ts | 4 ++ .../actions/ln/makeInvoice.js | 7 ++++ .../actions/lnurl/authOrPrompt.ts | 2 +- .../actions/settings/changePassword.ts | 8 +++- src/extension/background-script/index.ts | 24 ++++++----- src/extension/background-script/state.ts | 30 ++++++++++---- 13 files changed, 95 insertions(+), 44 deletions(-) diff --git a/src/app/context/AccountContext.tsx b/src/app/context/AccountContext.tsx index 58d42d818f..0e7852efa4 100644 --- a/src/app/context/AccountContext.tsx +++ b/src/app/context/AccountContext.tsx @@ -75,7 +75,10 @@ export function AccountProvider({ children }: { children: React.ReactNode }) { const updateFiatValue = useCallback( async (balance: string | number) => { + console.log("updateFiatValue - balance", balance); const fiat = await getFiatValue(balance); + console.log("updateFiatValue - fiat", fiat); + setFiatBalance(fiat); }, [getFiatValue] @@ -130,7 +133,7 @@ export function AccountProvider({ children }: { children: React.ReactNode }) { .finally(() => { setLoading(false); }); - }, 500); + }, 1000); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/src/app/context/SettingsContext.tsx b/src/app/context/SettingsContext.tsx index db71870f00..2c5ebedfeb 100644 --- a/src/app/context/SettingsContext.tsx +++ b/src/app/context/SettingsContext.tsx @@ -2,6 +2,7 @@ import dayjs from "dayjs"; import i18n from "i18next"; import { useState, useEffect, createContext, useContext } from "react"; import { toast } from "react-toastify"; +import browser from "webextension-polyfill"; import { getTheme } from "~/app/utils"; import api from "~/common/lib/api"; import { getFiatValue as getFiatValueFunc } from "~/common/utils/currencyConvert"; @@ -40,27 +41,34 @@ export const SettingsProvider = ({ // Invoked only on on mount. useEffect(() => { - setTimeout(() => { - console.log("SETTIMGS CONTEXT EFFECT"); - api - .getSettings() - .then((response) => { - setSettings(response); - }) - .catch((e) => { - // toast.error( - // `SettingsProvider: An unexpected error occurred (${e.message})` - // ); - }) - .finally(() => { - setIsLoading(false); - }); - }, 500); + // setTimeout(() => { + // console.log("SETTIMGS CONTEXT EFFECT 123"); + // api + // .getSettings() + browser.storage.sync + .get("settings") + .then(({ settings }) => { + // console.log("SETTINGS RESPONSE: ", settings); + + setSettings(settings); + }) + .catch((e) => { + toast.error( + `SettingsProvider: An unexpected error occurred (${e.message})` + ); + }) + .finally(() => { + setIsLoading(false); + }); + // }, 1000); }, []); // update rate useEffect(() => { + console.log("effect - getCurrencyRate"); + api.getCurrencyRate().then((response) => { + console.log("effect - getCurrencyRate - response", response); setCurrencyRate(response.rate); }); }, [settings.currency]); diff --git a/src/app/utils/index.ts b/src/app/utils/index.ts index 6e743580e4..8edae6eb2e 100644 --- a/src/app/utils/index.ts +++ b/src/app/utils/index.ts @@ -1,4 +1,5 @@ -import api from "~/common/lib/api"; +// import api from "~/common/lib/api"; +import browser from "webextension-polyfill"; export function classNames(...classes: (string | boolean)[]) { return classes.filter(Boolean).join(" "); @@ -8,7 +9,8 @@ export function classNames(...classes: (string | boolean)[]) { * Get the active theme and apply corresponding Tailwind classes to the document. */ export function getTheme() { - api.getSettings().then((settings) => { + // api.getSettings() + browser.storage.sync.get("settings").then(({ settings }) => { // check if settings theme selection is system (this is the default) if (settings.theme === "system") { // checks if the users prefers dark mode and if true then adds dark class to HTML element diff --git a/src/extension/background-script/actions/accounts/add.ts b/src/extension/background-script/actions/accounts/add.ts index d6f91aac12..33ddabc8f9 100644 --- a/src/extension/background-script/actions/accounts/add.ts +++ b/src/extension/background-script/actions/accounts/add.ts @@ -11,7 +11,9 @@ const add = async (message: MessageAccountAdd) => { // TODO: add validations // TODO: make sure a password is set - const password = state.getState().password; + // const password = state.getState().password; + const storageSessionPassword = await chrome.storage.session.get("password"); + const password = storageSessionPassword.password; const currentAccountId = state.getState().currentAccountId; if (!password) return { error: "Password is missing" }; diff --git a/src/extension/background-script/actions/accounts/all.ts b/src/extension/background-script/actions/accounts/all.ts index 6145b0f946..cb2bba72f2 100644 --- a/src/extension/background-script/actions/accounts/all.ts +++ b/src/extension/background-script/actions/accounts/all.ts @@ -3,6 +3,9 @@ import type { MessageAccountAll } from "~/types"; const all = async (_message: MessageAccountAll) => { const accounts = await state.getState().accounts; + // console.log("MV3: account all action - accounts: ", accounts); + const tmp = await state.getState().getConnector(); + // console.log("MV3: account all action - tmp: ", tmp); return { data: accounts, }; diff --git a/src/extension/background-script/actions/accounts/decryptedDetails.ts b/src/extension/background-script/actions/accounts/decryptedDetails.ts index 1a4a7bd4ca..8d13948fdf 100644 --- a/src/extension/background-script/actions/accounts/decryptedDetails.ts +++ b/src/extension/background-script/actions/accounts/decryptedDetails.ts @@ -4,7 +4,9 @@ import type { MessageAccountDecryptedDetails } from "~/types"; const decryptedDetails = async (message: MessageAccountDecryptedDetails) => { const accounts = state.getState().accounts; - const password = state.getState().password as string; + // const password = state.getState().password as string; + const storageSessionPassword = await chrome.storage.session.get("password"); + const password = storageSessionPassword.password; const accountId = message.args.id; if (accountId in accounts) { diff --git a/src/extension/background-script/actions/allowances/enable.ts b/src/extension/background-script/actions/allowances/enable.ts index 45dc9b2b3c..16ff4220d8 100644 --- a/src/extension/background-script/actions/allowances/enable.ts +++ b/src/extension/background-script/actions/allowances/enable.ts @@ -10,7 +10,7 @@ const enable = async ( message: MessageAllowanceEnable, sender: Runtime.MessageSender ) => { - const isUnlocked = state.getState().isUnlocked(); + const isUnlocked = await state.getState().isUnlocked(); const host = message.origin.host || message.args.host; const allowance = await db.allowances .where("host") diff --git a/src/extension/background-script/actions/cache/getCurrencyRate.ts b/src/extension/background-script/actions/cache/getCurrencyRate.ts index cbdf7be2d6..bfa3565563 100644 --- a/src/extension/background-script/actions/cache/getCurrencyRate.ts +++ b/src/extension/background-script/actions/cache/getCurrencyRate.ts @@ -96,10 +96,14 @@ export const getCurrencyRateWithCache = async (currency: CURRENCIES) => { }; const getCurrencyRate = async (message: MessageCurrencyRateGet) => { + console.log("BG ACTION - getCurrencyRate"); + const settings = state.getState().settings; + // const { settings } = await browser.storage.sync.get("settings"); const { currency } = settings; const rate = await getCurrencyRateWithCache(currency); + // const rate = 1; return { data: { rate }, diff --git a/src/extension/background-script/actions/ln/makeInvoice.js b/src/extension/background-script/actions/ln/makeInvoice.js index 7d7c37a91c..5b89bd8b66 100644 --- a/src/extension/background-script/actions/ln/makeInvoice.js +++ b/src/extension/background-script/actions/ln/makeInvoice.js @@ -1,4 +1,5 @@ import PubSub from "pubsub-js"; +// import browser from "webextension-polyfill"; import utils from "~/common/lib/utils"; import state from "../../state"; @@ -10,14 +11,20 @@ const makeInvoice = async (message, sender) => { const memo = message.args.memo || message.args.defaultMemo || "Alby invoice"; if (message.args.amount) { + console.log("TRY IT - haz amount"); + amount = parseInt(message.args.amount); const connector = await state.getState().getConnector(); + // const connector = await browser.storage.sync.get("connector"); + console.log("TRY IT - getConnector?", connector); + try { const response = await connector.makeInvoice({ amount, memo, }); + return response; } catch (e) { return { error: e.message }; diff --git a/src/extension/background-script/actions/lnurl/authOrPrompt.ts b/src/extension/background-script/actions/lnurl/authOrPrompt.ts index 8c3f903b00..7833c0b9b0 100644 --- a/src/extension/background-script/actions/lnurl/authOrPrompt.ts +++ b/src/extension/background-script/actions/lnurl/authOrPrompt.ts @@ -26,7 +26,7 @@ async function authOrPrompt( // we have the check the unlock status manually. The account can still be locked // If it is locked we must show a prompt to unlock - const isUnlocked = state.getState().isUnlocked(); + const isUnlocked = await state.getState().isUnlocked(); // check if there is a publisher and lnurlAuth is enabled, // otherwise we we prompt the user diff --git a/src/extension/background-script/actions/settings/changePassword.ts b/src/extension/background-script/actions/settings/changePassword.ts index d0bd225ffd..a29a227fc0 100644 --- a/src/extension/background-script/actions/settings/changePassword.ts +++ b/src/extension/background-script/actions/settings/changePassword.ts @@ -5,7 +5,9 @@ import state from "../../state"; const changePassword = async (message: Message) => { const accounts = state.getState().accounts; - const password = state.getState().password as string; + // const password = state.getState().password as string; + const storageSessionPassword = await chrome.storage.session.get("password"); + const password = storageSessionPassword.password; const newPassword = message.args.password as string; const tmpAccounts = { ...accounts }; @@ -16,7 +18,9 @@ const changePassword = async (message: Message) => { ); tmpAccounts[accountId].config = encryptData(accountConfig, newPassword); } - state.setState({ accounts: tmpAccounts, password: newPassword }); + await chrome.storage.session.set({ password: newPassword }); + // state.setState({ accounts: tmpAccounts, password: newPassword }); + state.setState({ accounts: tmpAccounts }); // make sure we immediately persist the updated accounts await state.getState().saveToStorage(); diff --git a/src/extension/background-script/index.ts b/src/extension/background-script/index.ts index 585a2b6d02..d23cf97595 100644 --- a/src/extension/background-script/index.ts +++ b/src/extension/background-script/index.ts @@ -93,11 +93,13 @@ const routeCalls = ( }, sender: Runtime.MessageSender ) => { + console.log("---> routeCalls", message); + // if the application does not match or if it is not a prompt we ignore the call if (message.application !== "LBE" || !message.prompt) { return; } - const debug = state.getState().settings.debug; + const debug = true; //state.getState().settings.debug; if (message.type) { console.error("Invalid message, using type: ", message); @@ -133,7 +135,7 @@ async function init() { browser.runtime.onMessage.addListener(debugLogger); // this is the only handler that may and must return a Promise which resolve with the response to the content script - browser.runtime.onMessage.addListener(routeCalls); + browser.runtime.onMessage.addListener(routeCalls); // all go through here // Update the extension icon browser.tabs.onUpdated.addListener(updateIcon); @@ -141,15 +143,15 @@ async function init() { // Notify the content script that the tab has been updated. browser.tabs.onUpdated.addListener(extractLightningData); - if (state.getState().settings.debug) { - console.info("Debug mode enabled, use window.debugAlby"); - window.debugAlby = { - state, - db, - connectors, - router, - }; - } + // if (state.getState().settings.debug) { + // console.info("Debug mode enabled, use window.debugAlby"); + // window.debugAlby = { + // state, + // db, + // connectors, + // router, + // }; + // } console.info("Loading completed"); } diff --git a/src/extension/background-script/state.ts b/src/extension/background-script/state.ts index 09b2e7c319..a6b540d6a0 100644 --- a/src/extension/background-script/state.ts +++ b/src/extension/background-script/state.ts @@ -20,9 +20,9 @@ interface State { getAccount: () => Account | null; getConnector: () => Promise; init: () => Promise; - isUnlocked: () => boolean; + isUnlocked: () => Promise; lock: () => Promise; - password: string | null; + // password: string | null; saveToStorage: () => Promise; settings: SettingsStorage; reset: () => Promise; @@ -70,7 +70,7 @@ const state = createState((set, get) => ({ migrations: [], accounts: {}, currentAccountId: null, - password: null, + // password: null, getAccount: () => { const currentAccountId = get().currentAccountId as string; let account = null; @@ -80,14 +80,25 @@ const state = createState((set, get) => ({ return account; }, getConnector: async () => { + // console.log("MV3: si es un connectore"); + if (get().connector) { return get().connector as Connector; } const currentAccountId = get().currentAccountId as string; const account = get().accounts[currentAccountId]; - const password = get().password as string; - const config = decryptData(account.config as string, password); + // const password = get().password as string; + + const storageSessionPassword = await chrome.storage.session.get("password"); + // console.log( + // "MV3: si es un connectore - storageSessionPassword", + // storageSessionPassword.password + // ); + const config = decryptData( + account.config as string, + storageSessionPassword.password + ); const connector = new connectors[account.connector](config); await connector.init(); @@ -97,14 +108,17 @@ const state = createState((set, get) => ({ return connector; }, lock: async () => { + await chrome.storage.session.set({ password: null }); const connector = get().connector; if (connector) { await connector.unload(); } - set({ password: null, connector: null, account: null }); + set({ connector: null, account: null }); }, - isUnlocked: () => { - return get().password !== null; + isUnlocked: async () => { + // return get().password !== null; + const storageSessionPassword = await chrome.storage.session.get("password"); + return storageSessionPassword.password !== null; }, init: () => { return browser.storage.sync.get(browserStorageKeys).then((result) => { From d1d04d2ec6e5b8192f3a7bb3db6b8d9be3411e00 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Fri, 11 Nov 2022 15:56:36 +0100 Subject: [PATCH 17/47] chore: move addListeners to teeh top #1051 --- src/extension/background-script/index.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/extension/background-script/index.ts b/src/extension/background-script/index.ts index d23cf97595..8c52050988 100644 --- a/src/extension/background-script/index.ts +++ b/src/extension/background-script/index.ts @@ -122,9 +122,21 @@ const routeCalls = ( async function init() { console.info("Loading background script"); + // this is the only handler that may and must return a Promise which resolve with the response to the content script + browser.runtime.onMessage.addListener(routeCalls); // all go through here + + browser.runtime.onMessage.addListener(debugLogger); + + // Update the extension icon + browser.tabs.onUpdated.addListener(updateIcon); + + // Notify the content script that the tab has been updated. + browser.tabs.onUpdated.addListener(extractLightningData); + //await browser.storage.sync.set({ settings: { debug: true }, allowances: [] }); await state.getState().init(); console.info("State loaded"); + await state.getState().connector; await db.open(); console.info("DB opened"); @@ -132,17 +144,6 @@ async function init() { events.subscribe(); console.info("Events subscribed"); - browser.runtime.onMessage.addListener(debugLogger); - - // this is the only handler that may and must return a Promise which resolve with the response to the content script - browser.runtime.onMessage.addListener(routeCalls); // all go through here - - // Update the extension icon - browser.tabs.onUpdated.addListener(updateIcon); - - // Notify the content script that the tab has been updated. - browser.tabs.onUpdated.addListener(extractLightningData); - // if (state.getState().settings.debug) { // console.info("Debug mode enabled, use window.debugAlby"); // window.debugAlby = { From b90d1014608f87e2f69557cee19f21e1f451a4ca Mon Sep 17 00:00:00 2001 From: escapedcat Date: Fri, 11 Nov 2022 16:33:54 +0100 Subject: [PATCH 18/47] chore: revert settings handling and cleanup #1051 --- src/app/context/AccountContext.tsx | 53 +++++++++---------- src/app/context/SettingsContext.tsx | 19 ++----- src/app/utils/index.ts | 12 ++--- .../actions/cache/getCurrencyRate.ts | 8 +-- src/extension/background-script/index.ts | 24 ++++----- src/extension/background-script/state.ts | 12 +---- 6 files changed, 47 insertions(+), 81 deletions(-) diff --git a/src/app/context/AccountContext.tsx b/src/app/context/AccountContext.tsx index 0e7852efa4..f785e949d1 100644 --- a/src/app/context/AccountContext.tsx +++ b/src/app/context/AccountContext.tsx @@ -105,35 +105,32 @@ export function AccountProvider({ children }: { children: React.ReactNode }) { // Invoked only on on mount. useEffect(() => { - setTimeout(() => { - console.log("ACCOUNT CONTEXT EFFECT"); - api - .getStatus() - .then((response) => { - const onWelcomePage = - window.location.pathname.indexOf("welcome.html") >= 0; - if (!response.configured && !onWelcomePage) { - utils.openPage("welcome.html"); - window.close(); - } else if (response.unlocked) { - if (response.configured && onWelcomePage) { - utils.redirectPage("options.html"); - } - setAccountId(response.currentAccountId); - fetchAccountInfo({ accountId: response.currentAccountId }); - } else { - setAccount(null); + api + .getStatus() + .then((response) => { + const onWelcomePage = + window.location.pathname.indexOf("welcome.html") >= 0; + if (!response.configured && !onWelcomePage) { + utils.openPage("welcome.html"); + window.close(); + } else if (response.unlocked) { + if (response.configured && onWelcomePage) { + utils.redirectPage("options.html"); } - }) - .catch((e) => { - toast.error( - `AccountContext: An unexpected error occurred (${e.message})` - ); - }) - .finally(() => { - setLoading(false); - }); - }, 1000); + setAccountId(response.currentAccountId); + fetchAccountInfo({ accountId: response.currentAccountId }); + } else { + setAccount(null); + } + }) + .catch((e) => { + toast.error( + `AccountContext: An unexpected error occurred (${e.message})` + ); + }) + .finally(() => { + setLoading(false); + }); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/src/app/context/SettingsContext.tsx b/src/app/context/SettingsContext.tsx index 2c5ebedfeb..8abda2026c 100644 --- a/src/app/context/SettingsContext.tsx +++ b/src/app/context/SettingsContext.tsx @@ -2,7 +2,6 @@ import dayjs from "dayjs"; import i18n from "i18next"; import { useState, useEffect, createContext, useContext } from "react"; import { toast } from "react-toastify"; -import browser from "webextension-polyfill"; import { getTheme } from "~/app/utils"; import api from "~/common/lib/api"; import { getFiatValue as getFiatValueFunc } from "~/common/utils/currencyConvert"; @@ -41,16 +40,10 @@ export const SettingsProvider = ({ // Invoked only on on mount. useEffect(() => { - // setTimeout(() => { - // console.log("SETTIMGS CONTEXT EFFECT 123"); - // api - // .getSettings() - browser.storage.sync - .get("settings") - .then(({ settings }) => { - // console.log("SETTINGS RESPONSE: ", settings); - - setSettings(settings); + api + .getSettings() + .then((response) => { + setSettings(response); }) .catch((e) => { toast.error( @@ -60,15 +53,11 @@ export const SettingsProvider = ({ .finally(() => { setIsLoading(false); }); - // }, 1000); }, []); // update rate useEffect(() => { - console.log("effect - getCurrencyRate"); - api.getCurrencyRate().then((response) => { - console.log("effect - getCurrencyRate - response", response); setCurrencyRate(response.rate); }); }, [settings.currency]); diff --git a/src/app/utils/index.ts b/src/app/utils/index.ts index 8edae6eb2e..8b62dbeb42 100644 --- a/src/app/utils/index.ts +++ b/src/app/utils/index.ts @@ -1,5 +1,4 @@ -// import api from "~/common/lib/api"; -import browser from "webextension-polyfill"; +import api from "~/common/lib/api"; export function classNames(...classes: (string | boolean)[]) { return classes.filter(Boolean).join(" "); @@ -9,10 +8,9 @@ export function classNames(...classes: (string | boolean)[]) { * Get the active theme and apply corresponding Tailwind classes to the document. */ export function getTheme() { - // api.getSettings() - browser.storage.sync.get("settings").then(({ settings }) => { + api.getSettings().then((response) => { // check if settings theme selection is system (this is the default) - if (settings.theme === "system") { + if (response.theme === "system") { // checks if the users prefers dark mode and if true then adds dark class to HTML element if (window.matchMedia("(prefers-color-scheme: dark)").matches) { document.documentElement.classList.add("dark"); @@ -23,9 +21,9 @@ export function getTheme() { } } // last two conditionals for if user selects light or dark mode - else if (settings.theme === "dark") { + else if (response.theme === "dark") { document.documentElement.classList.add("dark"); - } else if (settings.theme === "light") { + } else if (response.theme === "light") { document.documentElement.classList.remove("dark"); } }); diff --git a/src/extension/background-script/actions/cache/getCurrencyRate.ts b/src/extension/background-script/actions/cache/getCurrencyRate.ts index bfa3565563..41f70ffd21 100644 --- a/src/extension/background-script/actions/cache/getCurrencyRate.ts +++ b/src/extension/background-script/actions/cache/getCurrencyRate.ts @@ -96,14 +96,8 @@ export const getCurrencyRateWithCache = async (currency: CURRENCIES) => { }; const getCurrencyRate = async (message: MessageCurrencyRateGet) => { - console.log("BG ACTION - getCurrencyRate"); - - const settings = state.getState().settings; - // const { settings } = await browser.storage.sync.get("settings"); - const { currency } = settings; - + const { currency } = state.getState().settings; const rate = await getCurrencyRateWithCache(currency); - // const rate = 1; return { data: { rate }, diff --git a/src/extension/background-script/index.ts b/src/extension/background-script/index.ts index 8c52050988..dabceac764 100644 --- a/src/extension/background-script/index.ts +++ b/src/extension/background-script/index.ts @@ -93,13 +93,11 @@ const routeCalls = ( }, sender: Runtime.MessageSender ) => { - console.log("---> routeCalls", message); - // if the application does not match or if it is not a prompt we ignore the call if (message.application !== "LBE" || !message.prompt) { return; } - const debug = true; //state.getState().settings.debug; + const debug = state.getState().settings.debug; if (message.type) { console.error("Invalid message, using type: ", message); @@ -136,7 +134,6 @@ async function init() { //await browser.storage.sync.set({ settings: { debug: true }, allowances: [] }); await state.getState().init(); console.info("State loaded"); - await state.getState().connector; await db.open(); console.info("DB opened"); @@ -144,15 +141,16 @@ async function init() { events.subscribe(); console.info("Events subscribed"); - // if (state.getState().settings.debug) { - // console.info("Debug mode enabled, use window.debugAlby"); - // window.debugAlby = { - // state, - // db, - // connectors, - // router, - // }; - // } + if (state.getState().settings.debug) { + console.info("Debug mode enabled, use window.debugAlby"); + window.debugAlby = { + state, + db, + connectors, + router, + }; + } + console.info("Loading completed"); } diff --git a/src/extension/background-script/state.ts b/src/extension/background-script/state.ts index a6b540d6a0..21b6827c3f 100644 --- a/src/extension/background-script/state.ts +++ b/src/extension/background-script/state.ts @@ -22,7 +22,6 @@ interface State { init: () => Promise; isUnlocked: () => Promise; lock: () => Promise; - // password: string | null; saveToStorage: () => Promise; settings: SettingsStorage; reset: () => Promise; @@ -70,7 +69,6 @@ const state = createState((set, get) => ({ migrations: [], accounts: {}, currentAccountId: null, - // password: null, getAccount: () => { const currentAccountId = get().currentAccountId as string; let account = null; @@ -80,21 +78,14 @@ const state = createState((set, get) => ({ return account; }, getConnector: async () => { - // console.log("MV3: si es un connectore"); - if (get().connector) { return get().connector as Connector; } const currentAccountId = get().currentAccountId as string; const account = get().accounts[currentAccountId]; - // const password = get().password as string; - const storageSessionPassword = await chrome.storage.session.get("password"); - // console.log( - // "MV3: si es un connectore - storageSessionPassword", - // storageSessionPassword.password - // ); + const config = decryptData( account.config as string, storageSessionPassword.password @@ -116,7 +107,6 @@ const state = createState((set, get) => ({ set({ connector: null, account: null }); }, isUnlocked: async () => { - // return get().password !== null; const storageSessionPassword = await chrome.storage.session.get("password"); return storageSessionPassword.password !== null; }, From 231e5a3f8de19c48af01ba0c00040b0c1cdf5eff Mon Sep 17 00:00:00 2001 From: escapedcat Date: Fri, 11 Nov 2022 16:51:51 +0100 Subject: [PATCH 19/47] feat: support pw-change and further cleanup #1051 --- src/app/context/AccountContext.tsx | 3 --- src/app/context/SettingsContext.tsx | 8 ++++---- src/app/utils/index.ts | 8 ++++---- src/extension/background-script/actions/accounts/all.ts | 3 --- .../actions/accounts/decryptedDetails.ts | 1 - src/extension/background-script/actions/accounts/lock.ts | 5 ++--- .../background-script/actions/accounts/unlock.ts | 1 - src/extension/background-script/actions/ln/makeInvoice.js | 6 ------ .../background-script/actions/settings/changePassword.ts | 2 -- .../background-script/actions/setup/setPassword.js | 6 ++---- src/extension/background-script/actions/setup/status.js | 4 ---- 11 files changed, 12 insertions(+), 35 deletions(-) diff --git a/src/app/context/AccountContext.tsx b/src/app/context/AccountContext.tsx index f785e949d1..abed001166 100644 --- a/src/app/context/AccountContext.tsx +++ b/src/app/context/AccountContext.tsx @@ -75,10 +75,7 @@ export function AccountProvider({ children }: { children: React.ReactNode }) { const updateFiatValue = useCallback( async (balance: string | number) => { - console.log("updateFiatValue - balance", balance); const fiat = await getFiatValue(balance); - console.log("updateFiatValue - fiat", fiat); - setFiatBalance(fiat); }, [getFiatValue] diff --git a/src/app/context/SettingsContext.tsx b/src/app/context/SettingsContext.tsx index 8abda2026c..ff249eaf89 100644 --- a/src/app/context/SettingsContext.tsx +++ b/src/app/context/SettingsContext.tsx @@ -42,8 +42,8 @@ export const SettingsProvider = ({ useEffect(() => { api .getSettings() - .then((response) => { - setSettings(response); + .then((settings) => { + setSettings(settings); }) .catch((e) => { toast.error( @@ -57,8 +57,8 @@ export const SettingsProvider = ({ // update rate useEffect(() => { - api.getCurrencyRate().then((response) => { - setCurrencyRate(response.rate); + api.getCurrencyRate().then(({ rate }) => { + setCurrencyRate(rate); }); }, [settings.currency]); diff --git a/src/app/utils/index.ts b/src/app/utils/index.ts index 8b62dbeb42..6e743580e4 100644 --- a/src/app/utils/index.ts +++ b/src/app/utils/index.ts @@ -8,9 +8,9 @@ export function classNames(...classes: (string | boolean)[]) { * Get the active theme and apply corresponding Tailwind classes to the document. */ export function getTheme() { - api.getSettings().then((response) => { + api.getSettings().then((settings) => { // check if settings theme selection is system (this is the default) - if (response.theme === "system") { + if (settings.theme === "system") { // checks if the users prefers dark mode and if true then adds dark class to HTML element if (window.matchMedia("(prefers-color-scheme: dark)").matches) { document.documentElement.classList.add("dark"); @@ -21,9 +21,9 @@ export function getTheme() { } } // last two conditionals for if user selects light or dark mode - else if (response.theme === "dark") { + else if (settings.theme === "dark") { document.documentElement.classList.add("dark"); - } else if (response.theme === "light") { + } else if (settings.theme === "light") { document.documentElement.classList.remove("dark"); } }); diff --git a/src/extension/background-script/actions/accounts/all.ts b/src/extension/background-script/actions/accounts/all.ts index cb2bba72f2..6145b0f946 100644 --- a/src/extension/background-script/actions/accounts/all.ts +++ b/src/extension/background-script/actions/accounts/all.ts @@ -3,9 +3,6 @@ import type { MessageAccountAll } from "~/types"; const all = async (_message: MessageAccountAll) => { const accounts = await state.getState().accounts; - // console.log("MV3: account all action - accounts: ", accounts); - const tmp = await state.getState().getConnector(); - // console.log("MV3: account all action - tmp: ", tmp); return { data: accounts, }; diff --git a/src/extension/background-script/actions/accounts/decryptedDetails.ts b/src/extension/background-script/actions/accounts/decryptedDetails.ts index 8d13948fdf..dd0c6e540c 100644 --- a/src/extension/background-script/actions/accounts/decryptedDetails.ts +++ b/src/extension/background-script/actions/accounts/decryptedDetails.ts @@ -4,7 +4,6 @@ import type { MessageAccountDecryptedDetails } from "~/types"; const decryptedDetails = async (message: MessageAccountDecryptedDetails) => { const accounts = state.getState().accounts; - // const password = state.getState().password as string; const storageSessionPassword = await chrome.storage.session.get("password"); const password = storageSessionPassword.password; const accountId = message.args.id; diff --git a/src/extension/background-script/actions/accounts/lock.ts b/src/extension/background-script/actions/accounts/lock.ts index 125e2bd48d..1081218008 100644 --- a/src/extension/background-script/actions/accounts/lock.ts +++ b/src/extension/background-script/actions/accounts/lock.ts @@ -1,10 +1,9 @@ import type { MessageAccountLock } from "~/types"; -// import state from "../../state"; +import state from "../../state"; const lock = async (message: MessageAccountLock) => { - // await state.getState().lock(); - await chrome.storage.session.set({ password: null }); + await state.getState().lock(); return { data: { unlocked: false }, }; diff --git a/src/extension/background-script/actions/accounts/unlock.ts b/src/extension/background-script/actions/accounts/unlock.ts index f208dac584..579c8d94fd 100644 --- a/src/extension/background-script/actions/accounts/unlock.ts +++ b/src/extension/background-script/actions/accounts/unlock.ts @@ -31,7 +31,6 @@ const unlock = async (message: MessageAccountUnlock) => { } // if everything is fine we keep the password in memory - // state.setState({ password }); await chrome.storage.session.set({ password }); return Promise.resolve({ data: { unlocked: true, currentAccountId } }); diff --git a/src/extension/background-script/actions/ln/makeInvoice.js b/src/extension/background-script/actions/ln/makeInvoice.js index 5b89bd8b66..17796ef040 100644 --- a/src/extension/background-script/actions/ln/makeInvoice.js +++ b/src/extension/background-script/actions/ln/makeInvoice.js @@ -1,5 +1,4 @@ import PubSub from "pubsub-js"; -// import browser from "webextension-polyfill"; import utils from "~/common/lib/utils"; import state from "../../state"; @@ -11,13 +10,8 @@ const makeInvoice = async (message, sender) => { const memo = message.args.memo || message.args.defaultMemo || "Alby invoice"; if (message.args.amount) { - console.log("TRY IT - haz amount"); - amount = parseInt(message.args.amount); - const connector = await state.getState().getConnector(); - // const connector = await browser.storage.sync.get("connector"); - console.log("TRY IT - getConnector?", connector); try { const response = await connector.makeInvoice({ diff --git a/src/extension/background-script/actions/settings/changePassword.ts b/src/extension/background-script/actions/settings/changePassword.ts index a29a227fc0..d34f1ad870 100644 --- a/src/extension/background-script/actions/settings/changePassword.ts +++ b/src/extension/background-script/actions/settings/changePassword.ts @@ -5,7 +5,6 @@ import state from "../../state"; const changePassword = async (message: Message) => { const accounts = state.getState().accounts; - // const password = state.getState().password as string; const storageSessionPassword = await chrome.storage.session.get("password"); const password = storageSessionPassword.password; const newPassword = message.args.password as string; @@ -19,7 +18,6 @@ const changePassword = async (message: Message) => { tmpAccounts[accountId].config = encryptData(accountConfig, newPassword); } await chrome.storage.session.set({ password: newPassword }); - // state.setState({ accounts: tmpAccounts, password: newPassword }); state.setState({ accounts: tmpAccounts }); // make sure we immediately persist the updated accounts await state.getState().saveToStorage(); diff --git a/src/extension/background-script/actions/setup/setPassword.js b/src/extension/background-script/actions/setup/setPassword.js index 5e04d7e999..5d074bd4c8 100644 --- a/src/extension/background-script/actions/setup/setPassword.js +++ b/src/extension/background-script/actions/setup/setPassword.js @@ -1,11 +1,9 @@ -import state from "../../state"; - -const setPassword = (message, sender) => { +const setPassword = async (message, sender) => { // TODO: This action should be used to initially validate and define a password. // We might want to validate that no account was already configured with a different password const password = message.args.password; - state.setState({ password }); + await chrome.storage.session.set({ password }); return Promise.resolve({ data: { unlocked: true } }); }; diff --git a/src/extension/background-script/actions/setup/status.js b/src/extension/background-script/actions/setup/status.js index 1808487a5e..cbe6678295 100644 --- a/src/extension/background-script/actions/setup/status.js +++ b/src/extension/background-script/actions/setup/status.js @@ -2,10 +2,6 @@ import state from "../../state"; const status = async (message, sender) => { const storageSessionPassword = await chrome.storage.session.get("password"); - - console.log("STATUS ACTION password: ", storageSessionPassword.password); - - // const unlocked = state.getState().password !== null; const unlocked = storageSessionPassword.password !== null; const account = state.getState().getAccount(); const currentAccountId = state.getState().currentAccountId; From 6eb2ed0d4511f4dcfd0b2886eeb2bb035ee596dc Mon Sep 17 00:00:00 2001 From: escapedcat Date: Mon, 14 Nov 2022 15:28:21 +0100 Subject: [PATCH 20/47] chore: update unit-tests --- jest.setup.js | 15 +++++++++++++++ .../actions/accounts/__tests__/add.test.ts | 4 +++- .../accounts/__tests__/decryptedDetails.test.ts | 8 ++++++++ .../actions/accounts/__tests__/edit.test.ts | 5 ++++- .../actions/accounts/__tests__/unlock.test.ts | 7 +++++-- 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/jest.setup.js b/jest.setup.js index 3d34fbe9d2..7081b269b7 100644 --- a/jest.setup.js +++ b/jest.setup.js @@ -13,6 +13,20 @@ if (!chrome.runtime.id) chrome.runtime.id = "history-delete"; beforeAll(() => { // Enable the mocking in tests. server.listen(); + const get = jest.fn(); + const set = jest.fn(); + global.chrome = { + storage: { + local: { + set, + get, + }, + session: { + set, + get, + }, + }, + }; }); afterEach(() => { @@ -23,4 +37,5 @@ afterEach(() => { afterAll(() => { // Clean up once the tests are done. server.close(); + jest.restoreAllMocks(); }); diff --git a/src/extension/background-script/actions/accounts/__tests__/add.test.ts b/src/extension/background-script/actions/accounts/__tests__/add.test.ts index b245ddc854..9cf9c9b378 100644 --- a/src/extension/background-script/actions/accounts/__tests__/add.test.ts +++ b/src/extension/background-script/actions/accounts/__tests__/add.test.ts @@ -16,7 +16,6 @@ jest.mock("~/common/lib/crypto", () => { }); const defaultMockState = { - password: "123456", saveToStorage: jest.fn, accounts: {}, }; @@ -39,6 +38,9 @@ describe("add account to account-list", () => { }); test("add first account to empty list", async () => { + (chrome.storage.session.get as jest.Mock).mockResolvedValue({ + password: 123456, + }); const mockState = defaultMockState; state.getState = jest.fn().mockReturnValue(mockState); diff --git a/src/extension/background-script/actions/accounts/__tests__/decryptedDetails.test.ts b/src/extension/background-script/actions/accounts/__tests__/decryptedDetails.test.ts index 65eba873db..59a59b8176 100644 --- a/src/extension/background-script/actions/accounts/__tests__/decryptedDetails.test.ts +++ b/src/extension/background-script/actions/accounts/__tests__/decryptedDetails.test.ts @@ -45,6 +45,10 @@ describe("export account", () => { }); test("export existing lndhub account", async () => { + (chrome.storage.session.get as jest.Mock).mockResolvedValue({ + password: 123456, + }); + const message: MessageAccountDecryptedDetails = { application: "LBE", args: { @@ -69,6 +73,10 @@ describe("export account", () => { }); test("export non-existing account should error", async () => { + (chrome.storage.session.get as jest.Mock).mockResolvedValue({ + password: 123456, + }); + const message: MessageAccountDecryptedDetails = { application: "LBE", args: { diff --git a/src/extension/background-script/actions/accounts/__tests__/edit.test.ts b/src/extension/background-script/actions/accounts/__tests__/edit.test.ts index 3e1f22506c..403ddfe30f 100644 --- a/src/extension/background-script/actions/accounts/__tests__/edit.test.ts +++ b/src/extension/background-script/actions/accounts/__tests__/edit.test.ts @@ -16,7 +16,6 @@ jest.mock("~/common/lib/crypto", () => { }); const mockState = { - password: "123456", saveToStorage: jest.fn, accounts: { "888": { @@ -38,6 +37,10 @@ describe("edit account", () => { }); test("edit existing account", async () => { + (chrome.storage.session.get as jest.Mock).mockResolvedValue({ + password: 123456, + }); + const message: MessageAccountEdit = { application: "LBE", args: { diff --git a/src/extension/background-script/actions/accounts/__tests__/unlock.test.ts b/src/extension/background-script/actions/accounts/__tests__/unlock.test.ts index 09ad7f6f56..5a55a13791 100644 --- a/src/extension/background-script/actions/accounts/__tests__/unlock.test.ts +++ b/src/extension/background-script/actions/accounts/__tests__/unlock.test.ts @@ -6,7 +6,6 @@ import unlock from "../unlock"; jest.mock("~/extension/background-script/state"); const mockState = { - password: "123456", currentAccountId: "1e1e8ea6-493e-480b-9855-303d37506e97", getAccount: () => ({ config: @@ -23,6 +22,10 @@ describe("edit account", () => { }); test("edit existing account", async () => { + (chrome.storage.session.get as jest.Mock).mockResolvedValue({ + password: 123456, + }); + const message: MessageAccountUnlock = { application: "LBE", args: { password: 1 }, @@ -34,7 +37,7 @@ describe("edit account", () => { state.getState = jest.fn().mockReturnValue(mockState); state.setState = () => jest.fn; - const spy = jest.spyOn(state, "setState"); + const spy = jest.spyOn(chrome.storage.session, "set"); expect(await unlock(message)).toStrictEqual({ data: { From c5f326248aa1d81d15473c1f6d26fa62085c1ec4 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Mon, 14 Nov 2022 18:05:39 +0100 Subject: [PATCH 21/47] refactor: centralize chrome.storage.session usage #1051 --- .../background-script/actions/accounts/add.ts | 7 ++---- .../actions/accounts/decryptedDetails.ts | 4 +-- .../actions/accounts/unlock.ts | 3 +-- .../actions/settings/changePassword.ts | 6 ++--- .../actions/setup/setPassword.js | 4 ++- .../background-script/actions/setup/status.js | 3 +-- .../background-script/nostr/index.ts | 8 +++--- src/extension/background-script/state.ts | 25 +++++++++++-------- 8 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/extension/background-script/actions/accounts/add.ts b/src/extension/background-script/actions/accounts/add.ts index ea163ac2b8..91f15c68d4 100644 --- a/src/extension/background-script/actions/accounts/add.ts +++ b/src/extension/background-script/actions/accounts/add.ts @@ -10,13 +10,10 @@ const add = async (message: MessageAccountAdd) => { // TODO: add validations // TODO: make sure a password is set - - const storageSessionPassword = await chrome.storage.session.get("password"); - const password = storageSessionPassword.password; - const currentAccountId = state.getState().currentAccountId; - + const password = await state.getState().password(); if (!password) return { error: "Password is missing" }; + const currentAccountId = state.getState().currentAccountId; const accountId = uuidv4(); newAccount.config = encryptData(newAccount.config, password); tmpAccounts[accountId] = { diff --git a/src/extension/background-script/actions/accounts/decryptedDetails.ts b/src/extension/background-script/actions/accounts/decryptedDetails.ts index dd0c6e540c..f948c74c12 100644 --- a/src/extension/background-script/actions/accounts/decryptedDetails.ts +++ b/src/extension/background-script/actions/accounts/decryptedDetails.ts @@ -4,8 +4,8 @@ import type { MessageAccountDecryptedDetails } from "~/types"; const decryptedDetails = async (message: MessageAccountDecryptedDetails) => { const accounts = state.getState().accounts; - const storageSessionPassword = await chrome.storage.session.get("password"); - const password = storageSessionPassword.password; + const password = await state.getState().password(); + if (!password) return { error: "Password is missing" }; const accountId = message.args.id; if (accountId in accounts) { diff --git a/src/extension/background-script/actions/accounts/unlock.ts b/src/extension/background-script/actions/accounts/unlock.ts index 579c8d94fd..5c0549ba58 100644 --- a/src/extension/background-script/actions/accounts/unlock.ts +++ b/src/extension/background-script/actions/accounts/unlock.ts @@ -30,8 +30,7 @@ const unlock = async (message: MessageAccountUnlock) => { }); } - // if everything is fine we keep the password in memory - await chrome.storage.session.set({ password }); + await state.getState().password(password); return Promise.resolve({ data: { unlocked: true, currentAccountId } }); }; diff --git a/src/extension/background-script/actions/settings/changePassword.ts b/src/extension/background-script/actions/settings/changePassword.ts index d34f1ad870..3a096d78a6 100644 --- a/src/extension/background-script/actions/settings/changePassword.ts +++ b/src/extension/background-script/actions/settings/changePassword.ts @@ -5,8 +5,8 @@ import state from "../../state"; const changePassword = async (message: Message) => { const accounts = state.getState().accounts; - const storageSessionPassword = await chrome.storage.session.get("password"); - const password = storageSessionPassword.password; + const password = await state.getState().password(); + if (!password) return { error: "Password is missing" }; const newPassword = message.args.password as string; const tmpAccounts = { ...accounts }; @@ -17,7 +17,7 @@ const changePassword = async (message: Message) => { ); tmpAccounts[accountId].config = encryptData(accountConfig, newPassword); } - await chrome.storage.session.set({ password: newPassword }); + await state.getState().password(newPassword); state.setState({ accounts: tmpAccounts }); // make sure we immediately persist the updated accounts await state.getState().saveToStorage(); diff --git a/src/extension/background-script/actions/setup/setPassword.js b/src/extension/background-script/actions/setup/setPassword.js index 5d074bd4c8..f286fe5461 100644 --- a/src/extension/background-script/actions/setup/setPassword.js +++ b/src/extension/background-script/actions/setup/setPassword.js @@ -1,9 +1,11 @@ +import state from "~/extension/background-script/state"; + const setPassword = async (message, sender) => { // TODO: This action should be used to initially validate and define a password. // We might want to validate that no account was already configured with a different password const password = message.args.password; - await chrome.storage.session.set({ password }); + await state.getState().password(password); return Promise.resolve({ data: { unlocked: true } }); }; diff --git a/src/extension/background-script/actions/setup/status.js b/src/extension/background-script/actions/setup/status.js index cbe6678295..c83e84d608 100644 --- a/src/extension/background-script/actions/setup/status.js +++ b/src/extension/background-script/actions/setup/status.js @@ -1,8 +1,7 @@ import state from "../../state"; const status = async (message, sender) => { - const storageSessionPassword = await chrome.storage.session.get("password"); - const unlocked = storageSessionPassword.password !== null; + const unlocked = await state.getState().isUnlocked(); const account = state.getState().getAccount(); const currentAccountId = state.getState().currentAccountId; const configured = account != null; diff --git a/src/extension/background-script/nostr/index.ts b/src/extension/background-script/nostr/index.ts index f5f6eb2b87..38ed67d21a 100644 --- a/src/extension/background-script/nostr/index.ts +++ b/src/extension/background-script/nostr/index.ts @@ -7,8 +7,8 @@ import state from "../state"; class Nostr { async getPrivateKey() { - const storageSessionPassword = await chrome.storage.session.get("password"); - const password = storageSessionPassword.password; + const password = await state.getState().password(); + if (!password) throw new Error("Pasword is missing"); const encryptedKey = state.getState().nostrPrivateKey as string; if (encryptedKey) { return decryptData(encryptedKey, password); @@ -26,8 +26,8 @@ class Nostr { } async setPrivateKey(privateKey: string) { - const storageSessionPassword = await chrome.storage.session.get("password"); - const password = storageSessionPassword.password; + const password = await state.getState().password(); + if (!password) throw new Error("Pasword is missing"); state.setState({ nostrPrivateKey: encryptData(privateKey, password) }); await state.getState().saveToStorage(); diff --git a/src/extension/background-script/state.ts b/src/extension/background-script/state.ts index fd8afa542c..c4332d6e57 100644 --- a/src/extension/background-script/state.ts +++ b/src/extension/background-script/state.ts @@ -20,6 +20,7 @@ interface State { currentAccountId: string | null; nostrPrivateKey: string | null; nostr: Nostr | null; + password: (password?: string | null) => Promise; getAccount: () => Account | null; getConnector: () => Promise; getNostr: () => Nostr; @@ -76,9 +77,16 @@ const state = createState((set, get) => ({ migrations: [], accounts: {}, currentAccountId: null, - password: null, nostr: null, nostrPrivateKey: null, + password: async (password) => { + if (password) { + await chrome.storage.session.set({ password }); + } + const storageSessionPassword = await chrome.storage.session.get("password"); + + return storageSessionPassword.password; + }, getAccount: () => { const currentAccountId = get().currentAccountId as string; let account = null; @@ -93,13 +101,10 @@ const state = createState((set, get) => ({ } const currentAccountId = get().currentAccountId as string; const account = get().accounts[currentAccountId]; + const password = await get().password(); - const storageSessionPassword = await chrome.storage.session.get("password"); - - const config = decryptData( - account.config as string, - storageSessionPassword.password - ); + if (!password) throw new Error("Password is not set"); + const config = decryptData(account.config as string, password); const connector = new connectors[account.connector](config); await connector.init(); @@ -120,15 +125,15 @@ const state = createState((set, get) => ({ }, lock: async () => { await chrome.storage.session.set({ password: null }); - const connector = get().connector; + const connector = await get().connector; if (connector) { await connector.unload(); } set({ connector: null, account: null }); }, isUnlocked: async () => { - const storageSessionPassword = await chrome.storage.session.get("password"); - return storageSessionPassword.password !== null; + const password = await await get().password(null); + return password !== null; }, init: () => { return browser.storage.sync.get(browserStorageKeys).then((result) => { From 05fa22086b8aebbdf7636c0ff2379f53731908d3 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Tue, 15 Nov 2022 14:28:25 +0100 Subject: [PATCH 22/47] refactor: use polyfill but ignore type #1051 --- .eslintrc.json | 6 ++++++ src/extension/background-script/state.ts | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 5aa2e237ab..0fb77b0522 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -19,6 +19,12 @@ "jest": true }, "rules": { + "@typescript-eslint/ban-ts-comment": [ + "error", + { + "ts-ignore": "allow-with-description" + } + ], "@typescript-eslint/no-unused-vars": ["warn", { "args": "none" }], // No warnings for unused function arguments, which might be used in the future. "no-console": ["error", { "allow": ["info", "warn", "error"] }], "no-constant-binary-expression": "error", diff --git a/src/extension/background-script/state.ts b/src/extension/background-script/state.ts index c4332d6e57..6a165eb283 100644 --- a/src/extension/background-script/state.ts +++ b/src/extension/background-script/state.ts @@ -81,9 +81,13 @@ const state = createState((set, get) => ({ nostrPrivateKey: null, password: async (password) => { if (password) { - await chrome.storage.session.set({ password }); + // @ts-ignore: https://github.com/mozilla/webextension-polyfill/issues/329 + await browser.storage.session.set({ password }); } - const storageSessionPassword = await chrome.storage.session.get("password"); + // @ts-ignore: https://github.com/mozilla/webextension-polyfill/issues/329 + const storageSessionPassword = await browser.storage.session.get( + "password" + ); return storageSessionPassword.password; }, @@ -124,7 +128,8 @@ const state = createState((set, get) => ({ return nostr; }, lock: async () => { - await chrome.storage.session.set({ password: null }); + // @ts-ignore: https://github.com/mozilla/webextension-polyfill/issues/329 + await browser.storage.session.set({ password: null }); const connector = await get().connector; if (connector) { await connector.unload(); From 54edc6d3d698b405fb2a5c7847ade73aaff449c3 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Tue, 15 Nov 2022 14:35:39 +0100 Subject: [PATCH 23/47] feat: add mv3 check #1051 --- src/extension/background-script/state.ts | 38 +++++++++++++++++------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/extension/background-script/state.ts b/src/extension/background-script/state.ts index 6a165eb283..8f01a93c61 100644 --- a/src/extension/background-script/state.ts +++ b/src/extension/background-script/state.ts @@ -12,6 +12,9 @@ import connectors from "./connectors"; import type Connector from "./connectors/connector.interface"; import Nostr from "./nostr"; +export const isManifestV3 = + browser.runtime.getManifest().manifest_version === 3; + interface State { account: Account | null; accounts: Accounts; @@ -20,6 +23,7 @@ interface State { currentAccountId: string | null; nostrPrivateKey: string | null; nostr: Nostr | null; + mv2Password: string | null; password: (password?: string | null) => Promise; getAccount: () => Account | null; getConnector: () => Promise; @@ -79,17 +83,25 @@ const state = createState((set, get) => ({ currentAccountId: null, nostr: null, nostrPrivateKey: null, + mv2Password: null, password: async (password) => { - if (password) { + if (isManifestV3) { + if (password) { + // @ts-ignore: https://github.com/mozilla/webextension-polyfill/issues/329 + await browser.storage.session.set({ password }); + } // @ts-ignore: https://github.com/mozilla/webextension-polyfill/issues/329 - await browser.storage.session.set({ password }); - } - // @ts-ignore: https://github.com/mozilla/webextension-polyfill/issues/329 - const storageSessionPassword = await browser.storage.session.get( - "password" - ); + const storageSessionPassword = await browser.storage.session.get( + "password" + ); - return storageSessionPassword.password; + return storageSessionPassword.password; + } else { + if (password) { + set({ mv2Password: password }); + } + return get().mv2Password; + } }, getAccount: () => { const currentAccountId = get().currentAccountId as string; @@ -128,8 +140,12 @@ const state = createState((set, get) => ({ return nostr; }, lock: async () => { - // @ts-ignore: https://github.com/mozilla/webextension-polyfill/issues/329 - await browser.storage.session.set({ password: null }); + if (isManifestV3) { + // @ts-ignore: https://github.com/mozilla/webextension-polyfill/issues/329 + await browser.storage.session.set({ password: null }); + } else { + set({ mv2Password: null }); + } const connector = await get().connector; if (connector) { await connector.unload(); @@ -137,7 +153,7 @@ const state = createState((set, get) => ({ set({ connector: null, account: null }); }, isUnlocked: async () => { - const password = await await get().password(null); + const password = await await get().password(); return password !== null; }, init: () => { From 077200cfd68bd145495c4c4b9cba98364db4ef3c Mon Sep 17 00:00:00 2001 From: escapedcat Date: Wed, 16 Nov 2022 10:36:28 +0100 Subject: [PATCH 24/47] feat: support seticon for v2 and v3 #1051 --- src/common/utils/mv3.ts | 4 ++++ .../background-script/actions/setup/setIcon.ts | 10 +++++++--- src/extension/background-script/state.ts | 4 +--- 3 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 src/common/utils/mv3.ts diff --git a/src/common/utils/mv3.ts b/src/common/utils/mv3.ts new file mode 100644 index 0000000000..7886d48528 --- /dev/null +++ b/src/common/utils/mv3.ts @@ -0,0 +1,4 @@ +import browser from "webextension-polyfill"; + +export const isManifestV3 = + browser.runtime.getManifest().manifest_version === 3; diff --git a/src/extension/background-script/actions/setup/setIcon.ts b/src/extension/background-script/actions/setup/setIcon.ts index 800145a715..8eae2c5a82 100644 --- a/src/extension/background-script/actions/setup/setIcon.ts +++ b/src/extension/background-script/actions/setup/setIcon.ts @@ -1,4 +1,5 @@ import browser, { Runtime } from "webextension-polyfill"; +import { isManifestV3 } from "~/common/utils/mv3"; import { MessageSetIcon } from "~/types"; import state from "../../state"; @@ -45,8 +46,7 @@ const setIcon = async (icon: string, tabId: number): Promise => { tabIcons.set(tabId, icon); const theme = state.getState().settings.theme == "dark" ? "_dark" : ""; - - return browser.action.setIcon({ + const iconsParams = { path: { // it's looking relative from the "js" folder 16: `../assets/icons/${icon}${theme}_16x16.png`, @@ -55,7 +55,11 @@ const setIcon = async (icon: string, tabId: number): Promise => { 128: `../assets/icons/${icon}${theme}_128x128.png`, }, tabId, - }); + }; + + return isManifestV3 + ? browser.action.setIcon(iconsParams) + : browser.browserAction.setIcon(iconsParams); }; export { setIcon, setIconMessageHandler, ExtensionIcon }; diff --git a/src/extension/background-script/state.ts b/src/extension/background-script/state.ts index 8f01a93c61..d132afde48 100644 --- a/src/extension/background-script/state.ts +++ b/src/extension/background-script/state.ts @@ -4,6 +4,7 @@ import browser from "webextension-polyfill"; import createState from "zustand"; import { CURRENCIES } from "~/common/constants"; import { decryptData } from "~/common/lib/crypto"; +import { isManifestV3 } from "~/common/utils/mv3"; import { Migration } from "~/extension/background-script/migrations"; import i18n from "~/i18n/i18nConfig"; import type { Account, Accounts, SettingsStorage } from "~/types"; @@ -12,9 +13,6 @@ import connectors from "./connectors"; import type Connector from "./connectors/connector.interface"; import Nostr from "./nostr"; -export const isManifestV3 = - browser.runtime.getManifest().manifest_version === 3; - interface State { account: Account | null; accounts: Accounts; From 62106e8dac34aa5d10e898dc3ce4366f26c80c17 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Wed, 16 Nov 2022 13:07:43 +0100 Subject: [PATCH 25/47] test: update test for v3 #1051 --- jest.setup.js | 18 +++++------------- .../actions/accounts/__tests__/add.test.ts | 4 +--- .../__tests__/decryptedDetails.test.ts | 2 +- .../actions/accounts/__tests__/unlock.test.ts | 15 +++++---------- .../actions/cache/getCurrencyRate.ts | 3 +++ 5 files changed, 15 insertions(+), 27 deletions(-) diff --git a/jest.setup.js b/jest.setup.js index 7081b269b7..301be1c9d1 100644 --- a/jest.setup.js +++ b/jest.setup.js @@ -13,19 +13,11 @@ if (!chrome.runtime.id) chrome.runtime.id = "history-delete"; beforeAll(() => { // Enable the mocking in tests. server.listen(); - const get = jest.fn(); - const set = jest.fn(); - global.chrome = { - storage: { - local: { - set, - get, - }, - session: { - set, - get, - }, - }, + + //https://github.com/mozilla/webextension-polyfill/issues/329 + global.chrome.storage.session = { + set: jest.fn(), + get: jest.fn(), }; }); diff --git a/src/extension/background-script/actions/accounts/__tests__/add.test.ts b/src/extension/background-script/actions/accounts/__tests__/add.test.ts index 9cf9c9b378..321539251d 100644 --- a/src/extension/background-script/actions/accounts/__tests__/add.test.ts +++ b/src/extension/background-script/actions/accounts/__tests__/add.test.ts @@ -17,6 +17,7 @@ jest.mock("~/common/lib/crypto", () => { const defaultMockState = { saveToStorage: jest.fn, + password: () => "123456", accounts: {}, }; @@ -38,9 +39,6 @@ describe("add account to account-list", () => { }); test("add first account to empty list", async () => { - (chrome.storage.session.get as jest.Mock).mockResolvedValue({ - password: 123456, - }); const mockState = defaultMockState; state.getState = jest.fn().mockReturnValue(mockState); diff --git a/src/extension/background-script/actions/accounts/__tests__/decryptedDetails.test.ts b/src/extension/background-script/actions/accounts/__tests__/decryptedDetails.test.ts index 59a59b8176..e0134ee133 100644 --- a/src/extension/background-script/actions/accounts/__tests__/decryptedDetails.test.ts +++ b/src/extension/background-script/actions/accounts/__tests__/decryptedDetails.test.ts @@ -23,7 +23,7 @@ jest.mock("~/common/lib/crypto", () => { }); const mockState = { - password: "123456", + password: jest.fn, saveToStorage: jest.fn, accounts: { "888": { diff --git a/src/extension/background-script/actions/accounts/__tests__/unlock.test.ts b/src/extension/background-script/actions/accounts/__tests__/unlock.test.ts index 5a55a13791..a46b395ae9 100644 --- a/src/extension/background-script/actions/accounts/__tests__/unlock.test.ts +++ b/src/extension/background-script/actions/accounts/__tests__/unlock.test.ts @@ -5,7 +5,10 @@ import unlock from "../unlock"; jest.mock("~/extension/background-script/state"); +const passwordMock = jest.fn; + const mockState = { + password: passwordMock, currentAccountId: "1e1e8ea6-493e-480b-9855-303d37506e97", getAccount: () => ({ config: @@ -22,10 +25,6 @@ describe("edit account", () => { }); test("edit existing account", async () => { - (chrome.storage.session.get as jest.Mock).mockResolvedValue({ - password: 123456, - }); - const message: MessageAccountUnlock = { application: "LBE", args: { password: 1 }, @@ -35,9 +34,7 @@ describe("edit account", () => { }; state.getState = jest.fn().mockReturnValue(mockState); - state.setState = () => jest.fn; - - const spy = jest.spyOn(chrome.storage.session, "set"); + const spy = jest.spyOn(mockState, "password"); expect(await unlock(message)).toStrictEqual({ data: { @@ -46,9 +43,7 @@ describe("edit account", () => { }, }); - expect(spy).toHaveBeenNthCalledWith(1, { - password: "1", - }); + expect(spy).toHaveBeenNthCalledWith(1, "1"); expect(spy).toHaveBeenCalledTimes(1); }); diff --git a/src/extension/background-script/actions/cache/getCurrencyRate.ts b/src/extension/background-script/actions/cache/getCurrencyRate.ts index 41f70ffd21..bb5b4eaee2 100644 --- a/src/extension/background-script/actions/cache/getCurrencyRate.ts +++ b/src/extension/background-script/actions/cache/getCurrencyRate.ts @@ -7,6 +7,9 @@ import type { CURRENCIES } from "~/common/constants"; import state from "~/extension/background-script/state"; import type { MessageCurrencyRateGet } from "~/types"; +// eslint-disable-next-line @typescript-eslint/no-empty-function +jest.mock("@vespaiach/axios-fetch-adapter", () => {}); + dayjs.extend(isSameOrBefore); interface CurrencyRate { From 54d33703d6181818dc1dceab18b8c403898e71c0 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Wed, 16 Nov 2022 13:31:50 +0100 Subject: [PATCH 26/47] fix: patch jest-webextension-mock getManifest support #1051 --- package.json | 4 +- patches/jest-webextension-mock+3.7.22.patch | 14 ++ yarn.lock | 138 ++++++++++++++++++-- 3 files changed, 146 insertions(+), 10 deletions(-) create mode 100644 patches/jest-webextension-mock+3.7.22.patch diff --git a/package.json b/package.json index 84e80f827c..2adf4f9b18 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "yarn": ">= 1.0.0" }, "scripts": { + "postinstall": "patch-package", "dev:chrome": "cross-env NODE_ENV=development TARGET_BROWSER=chrome webpack --watch", "dev:firefox": "cross-env NODE_ENV=development TARGET_BROWSER=firefox webpack --watch", "dev:opera": "cross-env NODE_ENV=development TARGET_BROWSER=opera webpack --watch", @@ -36,8 +37,8 @@ }, "dependencies": { "@bitcoin-design/bitcoin-icons-react": "^0.1.9", - "@noble/secp256k1": "^1.7.0", "@headlessui/react": "^1.7.4", + "@noble/secp256k1": "^1.7.0", "@tailwindcss/forms": "^0.5.3", "@tailwindcss/line-clamp": "^0.4.2", "@vespaiach/axios-fetch-adapter": "^0.3.0", @@ -119,6 +120,7 @@ "lint-staged": "^13.0.3", "mini-css-extract-plugin": "^2.6.1", "msw": "^0.48.0", + "patch-package": "^6.5.0", "postcss": "^8.4.18", "postcss-cli": "^10.0.0", "postcss-loader": "^7.0.1", diff --git a/patches/jest-webextension-mock+3.7.22.patch b/patches/jest-webextension-mock+3.7.22.patch new file mode 100644 index 0000000000..eaed57401e --- /dev/null +++ b/patches/jest-webextension-mock+3.7.22.patch @@ -0,0 +1,14 @@ +diff --git a/node_modules/jest-webextension-mock/dist/setup.js b/node_modules/jest-webextension-mock/dist/setup.js +index cd0c2eb..3132e44 100644 +--- a/node_modules/jest-webextension-mock/dist/setup.js ++++ b/node_modules/jest-webextension-mock/dist/setup.js +@@ -72,7 +72,8 @@ var runtime = { + getURL: jest.fn(function (path) { + return path; + }), +- openOptionsPage: jest.fn() ++ openOptionsPage: jest.fn(), ++ getManifest: jest.fn(() => ({manifest_version: 3})) + }; + + // https://developer.chrome.com/extensions/tabs diff --git a/yarn.lock b/yarn.lock index 8f91aea006..a0a43cc5e7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2027,6 +2027,11 @@ resolved "https://registry.npmjs.org/@xtuc/long/-/long-4.2.2.tgz" integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ== +"@yarnpkg/lockfile@^1.1.0": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31" + integrity sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ== + "@zxing/text-encoding@0.9.0": version "0.9.0" resolved "https://registry.yarnpkg.com/@zxing/text-encoding/-/text-encoding-0.9.0.tgz#fb50ffabc6c7c66a0c96b4c03e3d9be74864b70b" @@ -2934,7 +2939,7 @@ chalk@^3.0.0: ansi-styles "^4.1.0" supports-color "^7.1.0" -chalk@^4.0.0, chalk@^4.1.1: +chalk@^4.0.0, chalk@^4.1.1, chalk@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== @@ -2992,6 +2997,11 @@ chrome-trace-event@^1.0.2: resolved "https://registry.npmjs.org/chrome-trace-event/-/chrome-trace-event-1.0.3.tgz" integrity sha512-p3KULyQg4S7NIHixdwbGX+nFHkoBiA4YQmyWtjb8XngSKV124nJmRysgAeujbUVb15vh+RvFUfCPqU7rXk+hZg== +ci-info@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46" + integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ== + ci-info@^3.2.0: version "3.3.2" resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.3.2.tgz#6d2967ffa407466481c6c90b6e16b3098f080128" @@ -3413,6 +3423,17 @@ cross-fetch@3.1.5: dependencies: node-fetch "2.6.7" +cross-spawn@^6.0.5: + version "6.0.5" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" + integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ== + dependencies: + nice-try "^1.0.4" + path-key "^2.0.1" + semver "^5.5.0" + shebang-command "^1.2.0" + which "^1.2.9" + cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" @@ -4688,6 +4709,13 @@ find-up@^5.0.0: locate-path "^6.0.0" path-exists "^4.0.0" +find-yarn-workspace-root@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/find-yarn-workspace-root/-/find-yarn-workspace-root-2.0.0.tgz#f47fb8d239c900eb78179aa81b66673eac88f7bd" + integrity sha512-1IMnbjt4KzsQfnhnzNd8wUEgXZ44IzZaZmnLYx7D5FZlaHt2gW20Cri8Q+E/t5tIj4+epTBub+2Zxu/vNILzqQ== + dependencies: + micromatch "^4.0.2" + flat-cache@^3.0.4: version "3.0.4" resolved "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz" @@ -4756,6 +4784,15 @@ fs-extra@^10.0.0, fs-extra@^10.1.0: jsonfile "^6.0.1" universalify "^2.0.0" +fs-extra@^7.0.1: + version "7.0.1" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" + integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw== + dependencies: + graceful-fs "^4.1.2" + jsonfile "^4.0.0" + universalify "^0.1.0" + fs-monkey@1.0.3: version "1.0.3" resolved "https://registry.npmjs.org/fs-monkey/-/fs-monkey-1.0.3.tgz" @@ -4965,16 +5002,16 @@ globby@^6.1.0: pify "^2.0.0" pinkie-promise "^2.0.0" +graceful-fs@^4.1.11, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.10, graceful-fs@^4.2.9: + version "4.2.10" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c" + integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA== + graceful-fs@^4.1.2, graceful-fs@^4.2.4: version "4.2.6" resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz" integrity sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ== -graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.10, graceful-fs@^4.2.9: - version "4.2.10" - resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c" - integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA== - graceful-fs@^4.2.6: version "4.2.8" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a" @@ -5444,6 +5481,13 @@ is-callable@^1.1.4, is-callable@^1.2.3: resolved "https://registry.npmjs.org/is-callable/-/is-callable-1.2.3.tgz" integrity sha512-J1DcMe8UYTBSrKezuIUTUwjXsho29693unXM2YhJUTR2txK/eG47bvNa/wipPFmZFgr/N6f1GA66dv0mEyTIyQ== +is-ci@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-2.0.0.tgz#6bc6334181810e04b5c22b3d589fdca55026404c" + integrity sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w== + dependencies: + ci-info "^2.0.0" + is-core-module@^2.2.0, is-core-module@^2.5.0, is-core-module@^2.8.1, is-core-module@^2.9.0: version "2.9.0" resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.9.0.tgz#e1c34429cd51c6dd9e09e0799e396e27b19a9c69" @@ -5687,7 +5731,7 @@ is-weakref@^1.0.2: dependencies: call-bind "^1.0.2" -is-wsl@^2.2.0: +is-wsl@^2.1.1, is-wsl@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271" integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww== @@ -6306,6 +6350,13 @@ jsonc-parser@^3.2.0: resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.2.0.tgz#31ff3f4c2b9793f89c67212627c51c6394f88e76" integrity sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w== +jsonfile@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb" + integrity sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg== + optionalDependencies: + graceful-fs "^4.1.6" + jsonfile@^6.0.1: version "6.1.0" resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae" @@ -6333,6 +6384,13 @@ kind-of@^6.0.2, kind-of@^6.0.3: resolved "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz" integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw== +klaw-sync@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/klaw-sync/-/klaw-sync-6.0.0.tgz#1fd2cfd56ebb6250181114f0a581167099c2b28c" + integrity sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ== + dependencies: + graceful-fs "^4.1.11" + kleur@^3.0.3: version "3.0.3" resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e" @@ -6910,6 +6968,11 @@ neo-async@^2.6.2: resolved "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz" integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== +nice-try@^1.0.4: + version "1.0.5" + resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" + integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== + no-case@^3.0.4: version "3.0.4" resolved "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz" @@ -7134,6 +7197,14 @@ onetime@^6.0.0: dependencies: mimic-fn "^4.0.0" +open@^7.4.2: + version "7.4.2" + resolved "https://registry.yarnpkg.com/open/-/open-7.4.2.tgz#b8147e26dcf3e426316c730089fd71edd29c2321" + integrity sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q== + dependencies: + is-docker "^2.0.0" + is-wsl "^2.1.1" + open@^8.0.9: version "8.2.1" resolved "https://registry.yarnpkg.com/open/-/open-8.2.1.tgz#82de42da0ccbf429bc12d099dad2e0975e14e8af" @@ -7327,6 +7398,26 @@ pascal-case@^3.1.2: no-case "^3.0.4" tslib "^2.0.3" +patch-package@^6.5.0: + version "6.5.0" + resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-6.5.0.tgz#feb058db56f0005da59cfa316488321de585e88a" + integrity sha512-tC3EqJmo74yKqfsMzELaFwxOAu6FH6t+FzFOsnWAuARm7/n2xB5AOeOueE221eM9gtMuIKMKpF9tBy/X2mNP0Q== + dependencies: + "@yarnpkg/lockfile" "^1.1.0" + chalk "^4.1.2" + cross-spawn "^6.0.5" + find-yarn-workspace-root "^2.0.0" + fs-extra "^7.0.1" + is-ci "^2.0.0" + klaw-sync "^6.0.0" + minimist "^1.2.6" + open "^7.4.2" + rimraf "^2.6.3" + semver "^5.6.0" + slash "^2.0.0" + tmp "^0.0.33" + yaml "^1.10.2" + path-exists@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz" @@ -7347,6 +7438,11 @@ path-is-inside@^1.0.2: resolved "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz" integrity sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM= +path-key@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40" + integrity sha512-fEHGKCSmUSDPv4uoj8AlD+joPlq3peND+HRYyxFz4KPw4z926S/b8rIuFs2FYJg3BwsxJf6A9/3eIdLaYC+9Dw== + path-key@^3.0.0, path-key@^3.1.0: version "3.1.1" resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375" @@ -8576,7 +8672,7 @@ selfsigned@^2.1.1: dependencies: node-forge "^1" -"semver@2 || 3 || 4 || 5": +"semver@2 || 3 || 4 || 5", semver@^5.5.0, semver@^5.6.0: version "5.7.1" resolved "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== @@ -8679,6 +8775,13 @@ shallow-clone@^3.0.0: dependencies: kind-of "^6.0.2" +shebang-command@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea" + integrity sha512-EV3L1+UQWGor21OmnvojK36mhg+TyIKDh3iFBKBohr5xeXIhNBcx8oWdgkTEEQ+BEFFYdLRuqMfd5L84N1V5Vg== + dependencies: + shebang-regex "^1.0.0" + shebang-command@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea" @@ -8686,6 +8789,11 @@ shebang-command@^2.0.0: dependencies: shebang-regex "^3.0.0" +shebang-regex@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" + integrity sha512-wpoSFAxys6b2a2wHZ1XpDSgD7N9iVjg29Ph9uV/uaP9Ex/KXlkTZTeddxDPSYQpgvzKLGJke2UU0AzoGCjNIvQ== + shebang-regex@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" @@ -8710,6 +8818,11 @@ sisteransi@^1.0.5: resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed" integrity sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg== +slash@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44" + integrity sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A== + slash@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" @@ -9495,7 +9608,7 @@ unbzip2-stream@1.4.3: buffer "^5.2.1" through "^2.3.8" -universalify@^0.1.2: +universalify@^0.1.0, universalify@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== @@ -9894,6 +10007,13 @@ which-typed-array@^1.1.2: has-tostringtag "^1.0.0" is-typed-array "^1.1.9" +which@^1.2.9: + version "1.3.1" + resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" + integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ== + dependencies: + isexe "^2.0.0" + which@^2.0.1: version "2.0.2" resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" From 5d0481dc8ffbfe9d65bc528e2b14c93b59d0e15b Mon Sep 17 00:00:00 2001 From: escapedcat Date: Wed, 16 Nov 2022 14:00:12 +0100 Subject: [PATCH 27/47] fix: getCurrency test-setup #1051 --- .../actions/cache/__tests__/getCurrencyRate.test.ts | 3 +++ .../background-script/actions/cache/getCurrencyRate.ts | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/extension/background-script/actions/cache/__tests__/getCurrencyRate.test.ts b/src/extension/background-script/actions/cache/__tests__/getCurrencyRate.test.ts index 4b306a2f91..d83c9da0f1 100644 --- a/src/extension/background-script/actions/cache/__tests__/getCurrencyRate.test.ts +++ b/src/extension/background-script/actions/cache/__tests__/getCurrencyRate.test.ts @@ -8,6 +8,9 @@ const mockState = { settings: { exchange: "coindesk", currency: CURRENCIES["USD"] }, }; +// eslint-disable-next-line @typescript-eslint/no-empty-function +jest.mock("@vespaiach/axios-fetch-adapter", () => {}); + state.getState = jest.fn().mockReturnValue(mockState); jest.useFakeTimers().setSystemTime(new Date(1577836800000)); // Wed Jan 01 2020 08:00:00 diff --git a/src/extension/background-script/actions/cache/getCurrencyRate.ts b/src/extension/background-script/actions/cache/getCurrencyRate.ts index bb5b4eaee2..41f70ffd21 100644 --- a/src/extension/background-script/actions/cache/getCurrencyRate.ts +++ b/src/extension/background-script/actions/cache/getCurrencyRate.ts @@ -7,9 +7,6 @@ import type { CURRENCIES } from "~/common/constants"; import state from "~/extension/background-script/state"; import type { MessageCurrencyRateGet } from "~/types"; -// eslint-disable-next-line @typescript-eslint/no-empty-function -jest.mock("@vespaiach/axios-fetch-adapter", () => {}); - dayjs.extend(isSameOrBefore); interface CurrencyRate { From 56b901c523df30a879ae7bf8be6a40614c35f38d Mon Sep 17 00:00:00 2001 From: escapedcat Date: Thu, 17 Nov 2022 11:15:52 +0100 Subject: [PATCH 28/47] fix: check for null and undefined password #1051 --- src/extension/background-script/state.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/extension/background-script/state.ts b/src/extension/background-script/state.ts index d132afde48..204a1db32d 100644 --- a/src/extension/background-script/state.ts +++ b/src/extension/background-script/state.ts @@ -116,7 +116,6 @@ const state = createState((set, get) => ({ const currentAccountId = get().currentAccountId as string; const account = get().accounts[currentAccountId]; const password = await get().password(); - if (!password) throw new Error("Password is not set"); const config = decryptData(account.config as string, password); @@ -152,7 +151,7 @@ const state = createState((set, get) => ({ }, isUnlocked: async () => { const password = await await get().password(); - return password !== null; + return !!password; }, init: () => { return browser.storage.sync.get(browserStorageKeys).then((result) => { From 253eccef0334e20ffa18e9968f27c48a248c7e8a Mon Sep 17 00:00:00 2001 From: escapedcat Date: Thu, 17 Nov 2022 11:19:02 +0100 Subject: [PATCH 29/47] chore: add linting for tests #1051 --- package.json | 2 +- tests/e2e/001-createWallets.spec.ts | 20 ++++++-------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 2adf4f9b18..7c3d0ae4c1 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "lint:js:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix", "tsc:compile": "tsc --noEmit", "format": "prettier --check '**/*.(md|json)' 'src/**/*.(js|ts|jsx|tsx)'", - "format:fix": "prettier --loglevel silent --write '**/*.(md|json)' 'src/**/*.(js|ts|jsx|tsx)'", + "format:fix": "prettier --loglevel silent --write '**/*.(md|json)' '(src|tests)/**/*.(js|ts|jsx|tsx)'", "test:unit": "jest", "test:e2e": "del-cli ./puppeteer-user-data-dir && npx playwright test", "test": "yarn test:unit && yarn test:e2e", diff --git a/tests/e2e/001-createWallets.spec.ts b/tests/e2e/001-createWallets.spec.ts index 116ae41d29..b0a1649f84 100644 --- a/tests/e2e/001-createWallets.spec.ts +++ b/tests/e2e/001-createWallets.spec.ts @@ -163,26 +163,18 @@ test.describe("Create or connect wallets", () => { await findByText($document, "Host"); const host = "143.244.206.7"; - const pubkey = "032e2444c5bb14c5eb2bf8ebdfd102c162609956aa995b7c7d373ca378deedb5c7"; + const pubkey = + "032e2444c5bb14c5eb2bf8ebdfd102c162609956aa995b7c7d373ca378deedb5c7"; const rune = "vrrgKshH1sPZ7wjQnCWjdEtB2PCcM48Gs05FuVPln8g9MTE="; - const lndUrlField = await getByLabelText( - $document, - "Host" - ); + const lndUrlField = await getByLabelText($document, "Host"); await lndUrlField.type(host); - const pubkeyField = await getByLabelText( - $document, - "Public key" - ); + const pubkeyField = await getByLabelText($document, "Public key"); await pubkeyField.type(pubkey); - const runeField = await getByLabelText( - $document, - "Rune" - ); - await runeField.type(rune) + const runeField = await getByLabelText($document, "Rune"); + await runeField.type(rune); await commonCreateWalletSuccessCheck({ page, $document }); From f490aa89f074f912ffb76e49d4ba549050f87962 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Thu, 17 Nov 2022 14:53:51 +0100 Subject: [PATCH 30/47] fix: patch lnmessage for comando #1051 --- patches/lnmessage+0.0.13.patch | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 patches/lnmessage+0.0.13.patch diff --git a/patches/lnmessage+0.0.13.patch b/patches/lnmessage+0.0.13.patch new file mode 100644 index 0000000000..9d430c8858 --- /dev/null +++ b/patches/lnmessage+0.0.13.patch @@ -0,0 +1,35 @@ +diff --git a/node_modules/lnmessage/dist/crypto.js b/node_modules/lnmessage/dist/crypto.js +index 9c21f8c..d5af1ae 100644 +--- a/node_modules/lnmessage/dist/crypto.js ++++ b/node_modules/lnmessage/dist/crypto.js +@@ -10,7 +10,7 @@ export function hmacHash(key, input) { + return Buffer.from(CryptoJS.enc.Hex.stringify(words), 'hex'); + } + export async function sha256(input) { +- const res = await window.crypto.subtle.digest('SHA-256', input); ++ const res = await crypto.subtle.digest('SHA-256', input); + return Buffer.from(res); + } + export function hkdf(ikm, len, salt = Buffer.alloc(0), info = Buffer.alloc(0)) { +@@ -80,7 +80,7 @@ export function createRandomPrivateKey() { + let privKey; + do { + const bytes = Buffer.allocUnsafe(32); +- privKey = window.crypto.getRandomValues(bytes); ++ privKey = crypto.getRandomValues(bytes); + } while (!validPrivateKey(privKey)); + return privKey.toString('hex'); + } +diff --git a/node_modules/lnmessage/dist/index.js b/node_modules/lnmessage/dist/index.js +index 55e8475..ac1a7b7 100644 +--- a/node_modules/lnmessage/dist/index.js ++++ b/node_modules/lnmessage/dist/index.js +@@ -342,7 +342,7 @@ class LnMessage { + if (!reqId) { + // create random id to match request with response + const idBytes = Buffer.allocUnsafe(8); +- const id = window.crypto.getRandomValues(idBytes); ++ const id = crypto.getRandomValues(idBytes); + reqId = id.toString('hex'); + } + // write the type From e17cb3f5f0cb6625797efb75fa3f83f817a42495 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Thu, 17 Nov 2022 15:34:33 +0100 Subject: [PATCH 31/47] feat: create correct manifest for chrome v3 and v2 for FF and opera #1051 --- src/manifest.json | 78 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 12 deletions(-) diff --git a/src/manifest.json b/src/manifest.json index 48eba412b1..69639fdc30 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,5 +1,6 @@ { - "manifest_version": 3, + "manifest_version": 2, + "__chrome__manifest_version": 3, "name": "Alby - Bitcoin Lightning Wallet", "version": "0.0.0", @@ -11,8 +12,14 @@ }, "description": "The Bitcoin Lightning wallet for direct payments across the globe, Bitcoin Lightning applications and passwordless logins.", "homepage_url": "https://getAlby.com/", - "COMMENT_web_accessible_resources": "https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#web-accessible-resources", + "web_accessible_resources": [ + "js/inpageScript.bundle.js", + "js/inpageScriptWebLN.bundle.js", + "js/inpageScriptNostr.bundle.js" + ], + + "__chrome__web_accessible_resources": [ { "resources": [ "js/inpageScript.bundle.js", @@ -22,22 +29,29 @@ "matches": ["https://*/*"] } ], + "permissions": [ - "notifications", "activeTab", - "tabs", + "nativeMessaging", + "notifications", "storage", + "tabs", + "unlimitedStorage", + "*://*/*" + ], + + "__chrome__permissions": [ + "activeTab", "nativeMessaging", + "notifications", + "storage", + "tabs", "unlimitedStorage" ], - "host_permissions": ["*://*/*"], + "__chrome__host_permissions": ["*://*/*"], - "COMMENT_content_security_policy": [ - "TODO: trigger actions", - "https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#content-security-policy", - "https://developer.chrome.com/docs/extensions/mv3/mv3-migration-checklist/#security_checklist" - ], - "content_security_policy.extension_pages": "script-src 'self'; object-src 'self'", + "__firefox|opera__content_security_policy": "script-src 'self'; object-src 'self'", + "__chrome__content_security_policy.extension_pages": "script-src 'self'; object-src 'self'", "__chrome|firefox__author": "Alby", "__opera__developer": { @@ -53,7 +67,7 @@ "__chrome__minimum_chrome_version": "88", "__opera__minimum_opera_version": "74", - "action": { + "__firefox|opera__browser_action": { "default_popup": "popup.html", "default_icon": { "16": "assets/icons/alby_icon_yellow_16x16.png", @@ -84,9 +98,43 @@ } ], "default_title": "Alby - Bitcoin Lightning Wallet", + "__opera__chrome_style": false, "__firefox__browser_style": false }, + "__chrome__action": { + "default_popup": "popup.html", + "default_icon": { + "16": "assets/icons/alby_icon_yellow_16x16.png", + "32": "assets/icons/alby_icon_yellow_32x32.png", + "48": "assets/icons/alby_icon_yellow_48x48.png", + "128": "assets/icons/alby_icon_yellow_128x128.png" + }, + "theme_icons": [ + { + "dark": "assets/icons/alby_icon_yellow_16x16.png", + "light": "assets/icons/alby_icon_yellow_dark_16x16.png", + "size": 16 + }, + { + "dark": "assets/icons/alby_icon_yellow_32x32.png", + "light": "assets/icons/alby_icon_yellow_dark_32x32.png", + "size": 32 + }, + { + "dark": "assets/icons/alby_icon_yellow_48x48.png", + "light": "assets/icons/alby_icon_yellow_dark_48x48.png", + "size": 48 + }, + { + "dark": "assets/icons/alby_icon_yellow_128x128.png", + "light": "assets/icons/alby_icon_yellow_dark_128x128.png", + "size": 128 + } + ], + "default_title": "Alby - Bitcoin Lightning Wallet" + }, + "commands": { "_execute_browser_action": { "suggested_key": { @@ -98,10 +146,16 @@ "options_ui": { "page": "options.html", "open_in_tab": true, + "__opera__chrome_style": false, "__firefox__browser_style": false }, "background": { + "scripts": ["js/background.bundle.js"], + "__opera__persistent": true + }, + + "__chrome__background": { "service_worker": "js/background.bundle.js" }, From 91f62bff1098aabd8f6452ef1a8a1a94bf9bc962 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Fri, 18 Nov 2022 09:54:46 +0100 Subject: [PATCH 32/47] refactor: update to lnmessage v0.14 #1051 --- package.json | 2 +- patches/lnmessage+0.0.13.patch | 35 ---------------------------------- yarn.lock | 8 ++++---- 3 files changed, 5 insertions(+), 40 deletions(-) delete mode 100644 patches/lnmessage+0.0.13.patch diff --git a/package.json b/package.json index 7c3d0ae4c1..b880f61a7e 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "html5-qrcode": "^2.2.3", "i18next": "^21.10.0", "i18next-browser-languagedetector": "^7.0.1", - "lnmessage": "^0.0.13", + "lnmessage": "^0.0.14", "lodash.merge": "^4.6.2", "lodash.pick": "^4.4.0", "pubsub-js": "^1.9.4", diff --git a/patches/lnmessage+0.0.13.patch b/patches/lnmessage+0.0.13.patch deleted file mode 100644 index 9d430c8858..0000000000 --- a/patches/lnmessage+0.0.13.patch +++ /dev/null @@ -1,35 +0,0 @@ -diff --git a/node_modules/lnmessage/dist/crypto.js b/node_modules/lnmessage/dist/crypto.js -index 9c21f8c..d5af1ae 100644 ---- a/node_modules/lnmessage/dist/crypto.js -+++ b/node_modules/lnmessage/dist/crypto.js -@@ -10,7 +10,7 @@ export function hmacHash(key, input) { - return Buffer.from(CryptoJS.enc.Hex.stringify(words), 'hex'); - } - export async function sha256(input) { -- const res = await window.crypto.subtle.digest('SHA-256', input); -+ const res = await crypto.subtle.digest('SHA-256', input); - return Buffer.from(res); - } - export function hkdf(ikm, len, salt = Buffer.alloc(0), info = Buffer.alloc(0)) { -@@ -80,7 +80,7 @@ export function createRandomPrivateKey() { - let privKey; - do { - const bytes = Buffer.allocUnsafe(32); -- privKey = window.crypto.getRandomValues(bytes); -+ privKey = crypto.getRandomValues(bytes); - } while (!validPrivateKey(privKey)); - return privKey.toString('hex'); - } -diff --git a/node_modules/lnmessage/dist/index.js b/node_modules/lnmessage/dist/index.js -index 55e8475..ac1a7b7 100644 ---- a/node_modules/lnmessage/dist/index.js -+++ b/node_modules/lnmessage/dist/index.js -@@ -342,7 +342,7 @@ class LnMessage { - if (!reqId) { - // create random id to match request with response - const idBytes = Buffer.allocUnsafe(8); -- const id = window.crypto.getRandomValues(idBytes); -+ const id = crypto.getRandomValues(idBytes); - reqId = id.toString('hex'); - } - // write the type diff --git a/yarn.lock b/yarn.lock index a0a43cc5e7..8bad947479 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6487,10 +6487,10 @@ listr2@^4.0.5: through "^2.3.8" wrap-ansi "^7.0.0" -lnmessage@^0.0.13: - version "0.0.13" - resolved "https://registry.yarnpkg.com/lnmessage/-/lnmessage-0.0.13.tgz#bb0d4bcaf99e182c76ed3825aebd92bb7635b333" - integrity sha512-0lg68fxRsCPTZwB8cZOwYY0arT8nkcPhxDgbUHitdkwuRomja9wmpX8lFQqPFiB+jd4szwug/N6VPPwzjMOXNA== +lnmessage@^0.0.14: + version "0.0.14" + resolved "https://registry.yarnpkg.com/lnmessage/-/lnmessage-0.0.14.tgz#0c9c96802ad61d0feceb9751b77f3195f7b7056a" + integrity sha512-bD+iUAhYfh7ky2uqIFX4FdhJOxGYItNO2ILH2WKV4LgMzzFyjg+YqEf2ReRjXLepd3zpVBLxLD/PDZxHwgQzbw== dependencies: buffer "^6.0.3" crypto-js "^4.1.1" From f3636471e1ce1b21be2c9ee8ef519ee53fd8392c Mon Sep 17 00:00:00 2001 From: escapedcat Date: Mon, 21 Nov 2022 13:51:42 +0100 Subject: [PATCH 33/47] fix: nostr #1051 --- src/extension/background-script/actions/nostr/getPrivateKey.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension/background-script/actions/nostr/getPrivateKey.ts b/src/extension/background-script/actions/nostr/getPrivateKey.ts index cf093ae274..54b4f930f8 100644 --- a/src/extension/background-script/actions/nostr/getPrivateKey.ts +++ b/src/extension/background-script/actions/nostr/getPrivateKey.ts @@ -1,7 +1,7 @@ import state from "../../state"; const getPrivateKey = async () => { - const privateKey = state.getState().getNostr().getPrivateKey(); + const privateKey = await state.getState().getNostr().getPrivateKey(); return { data: privateKey, }; From 657760bde444b91d55bea828ef3070ed81a708dc Mon Sep 17 00:00:00 2001 From: escapedcat Date: Tue, 22 Nov 2022 10:39:40 +0100 Subject: [PATCH 34/47] fix: manifest warning #1051 --- src/manifest.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/manifest.json b/src/manifest.json index 69639fdc30..e37e9eef73 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -50,8 +50,10 @@ ], "__chrome__host_permissions": ["*://*/*"], - "__firefox|opera__content_security_policy": "script-src 'self'; object-src 'self'", - "__chrome__content_security_policy.extension_pages": "script-src 'self'; object-src 'self'", + "content_security_policy": "script-src 'self'; object-src 'self'", + "__chrome__content_security_policy": { + "extension_pages": "script-src 'self'; object-src 'self'" + }, "__chrome|firefox__author": "Alby", "__opera__developer": { From 9433185dabf4edc3605a17c64ce9859d4f42b931 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Sat, 26 Nov 2022 15:55:18 +0100 Subject: [PATCH 35/47] chore: update jest-webextension-mock getManifest support #1051 --- package.json | 4 +- patches/jest-webextension-mock+3.7.22.patch | 14 -- yarn.lock | 146 ++------------------ 3 files changed, 14 insertions(+), 150 deletions(-) delete mode 100644 patches/jest-webextension-mock+3.7.22.patch diff --git a/package.json b/package.json index bd13022d80..9aa2910063 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "yarn": ">= 1.0.0" }, "scripts": { - "postinstall": "patch-package", "dev:chrome": "cross-env NODE_ENV=development TARGET_BROWSER=chrome webpack --watch", "dev:firefox": "cross-env NODE_ENV=development TARGET_BROWSER=firefox webpack --watch", "dev:opera": "cross-env NODE_ENV=development TARGET_BROWSER=opera webpack --watch", @@ -116,11 +115,10 @@ "husky": "^8.0.2", "jest": "^29.2.2", "jest-environment-jsdom": "^29.2.2", - "jest-webextension-mock": "^3.7.22", + "jest-webextension-mock": "^3.8.6", "lint-staged": "^13.0.3", "mini-css-extract-plugin": "^2.6.1", "msw": "^0.49.0", - "patch-package": "^6.5.0", "postcss": "^8.4.19", "postcss-cli": "^10.0.0", "postcss-loader": "^7.0.1", diff --git a/patches/jest-webextension-mock+3.7.22.patch b/patches/jest-webextension-mock+3.7.22.patch deleted file mode 100644 index eaed57401e..0000000000 --- a/patches/jest-webextension-mock+3.7.22.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/node_modules/jest-webextension-mock/dist/setup.js b/node_modules/jest-webextension-mock/dist/setup.js -index cd0c2eb..3132e44 100644 ---- a/node_modules/jest-webextension-mock/dist/setup.js -+++ b/node_modules/jest-webextension-mock/dist/setup.js -@@ -72,7 +72,8 @@ var runtime = { - getURL: jest.fn(function (path) { - return path; - }), -- openOptionsPage: jest.fn() -+ openOptionsPage: jest.fn(), -+ getManifest: jest.fn(() => ({manifest_version: 3})) - }; - - // https://developer.chrome.com/extensions/tabs diff --git a/yarn.lock b/yarn.lock index e4fb0f4e5f..57d0dbe4e2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2025,11 +2025,6 @@ resolved "https://registry.npmjs.org/@xtuc/long/-/long-4.2.2.tgz" integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ== -"@yarnpkg/lockfile@^1.1.0": - version "1.1.0" - resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31" - integrity sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ== - "@zxing/text-encoding@0.9.0": version "0.9.0" resolved "https://registry.yarnpkg.com/@zxing/text-encoding/-/text-encoding-0.9.0.tgz#fb50ffabc6c7c66a0c96b4c03e3d9be74864b70b" @@ -2937,7 +2932,7 @@ chalk@^3.0.0: ansi-styles "^4.1.0" supports-color "^7.1.0" -chalk@^4.0.0, chalk@^4.1.1, chalk@^4.1.2: +chalk@^4.0.0, chalk@^4.1.1: version "4.1.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== @@ -2995,11 +2990,6 @@ chrome-trace-event@^1.0.2: resolved "https://registry.npmjs.org/chrome-trace-event/-/chrome-trace-event-1.0.3.tgz" integrity sha512-p3KULyQg4S7NIHixdwbGX+nFHkoBiA4YQmyWtjb8XngSKV124nJmRysgAeujbUVb15vh+RvFUfCPqU7rXk+hZg== -ci-info@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46" - integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ== - ci-info@^3.2.0: version "3.3.2" resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.3.2.tgz#6d2967ffa407466481c6c90b6e16b3098f080128" @@ -3426,17 +3416,6 @@ cross-fetch@3.1.5: dependencies: node-fetch "2.6.7" -cross-spawn@^6.0.5: - version "6.0.5" - resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" - integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ== - dependencies: - nice-try "^1.0.4" - path-key "^2.0.1" - semver "^5.5.0" - shebang-command "^1.2.0" - which "^1.2.9" - cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" @@ -4712,13 +4691,6 @@ find-up@^5.0.0: locate-path "^6.0.0" path-exists "^4.0.0" -find-yarn-workspace-root@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/find-yarn-workspace-root/-/find-yarn-workspace-root-2.0.0.tgz#f47fb8d239c900eb78179aa81b66673eac88f7bd" - integrity sha512-1IMnbjt4KzsQfnhnzNd8wUEgXZ44IzZaZmnLYx7D5FZlaHt2gW20Cri8Q+E/t5tIj4+epTBub+2Zxu/vNILzqQ== - dependencies: - micromatch "^4.0.2" - flat-cache@^3.0.4: version "3.0.4" resolved "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz" @@ -4787,15 +4759,6 @@ fs-extra@^10.0.0, fs-extra@^10.1.0: jsonfile "^6.0.1" universalify "^2.0.0" -fs-extra@^7.0.1: - version "7.0.1" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" - integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw== - dependencies: - graceful-fs "^4.1.2" - jsonfile "^4.0.0" - universalify "^0.1.0" - fs-monkey@1.0.3: version "1.0.3" resolved "https://registry.npmjs.org/fs-monkey/-/fs-monkey-1.0.3.tgz" @@ -5005,16 +4968,16 @@ globby@^6.1.0: pify "^2.0.0" pinkie-promise "^2.0.0" -graceful-fs@^4.1.11, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.10, graceful-fs@^4.2.9: - version "4.2.10" - resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c" - integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA== - graceful-fs@^4.1.2, graceful-fs@^4.2.4: version "4.2.6" resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz" integrity sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ== +graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.10, graceful-fs@^4.2.9: + version "4.2.10" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c" + integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA== + graceful-fs@^4.2.6: version "4.2.8" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a" @@ -5484,13 +5447,6 @@ is-callable@^1.1.4, is-callable@^1.2.3: resolved "https://registry.npmjs.org/is-callable/-/is-callable-1.2.3.tgz" integrity sha512-J1DcMe8UYTBSrKezuIUTUwjXsho29693unXM2YhJUTR2txK/eG47bvNa/wipPFmZFgr/N6f1GA66dv0mEyTIyQ== -is-ci@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-2.0.0.tgz#6bc6334181810e04b5c22b3d589fdca55026404c" - integrity sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w== - dependencies: - ci-info "^2.0.0" - is-core-module@^2.2.0, is-core-module@^2.5.0, is-core-module@^2.8.1, is-core-module@^2.9.0: version "2.9.0" resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.9.0.tgz#e1c34429cd51c6dd9e09e0799e396e27b19a9c69" @@ -5734,7 +5690,7 @@ is-weakref@^1.0.2: dependencies: call-bind "^1.0.2" -is-wsl@^2.1.1, is-wsl@^2.2.0: +is-wsl@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271" integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww== @@ -6195,10 +6151,10 @@ jest-watcher@^29.3.1: jest-util "^29.3.1" string-length "^4.0.1" -jest-webextension-mock@^3.7.22: - version "3.7.22" - resolved "https://registry.yarnpkg.com/jest-webextension-mock/-/jest-webextension-mock-3.7.22.tgz#2f9fee625b06d759bb62decbfccbd00384dfbbb9" - integrity sha512-ai0S49FU9FjUqtXOpkVj26WGc3Lsh6lBPkQABKtKoLUoR60Z42XBBFyNykaZpWRRfIPxprrahLsedPNAVDkJ3w== +jest-webextension-mock@^3.8.6: + version "3.8.6" + resolved "https://registry.yarnpkg.com/jest-webextension-mock/-/jest-webextension-mock-3.8.6.tgz#dc6a62cee42730a6ea271f5a54323ac8439cfb35" + integrity sha512-3AEqeRcUetK0CheiLLPSsQJsf6Z4np3kTibHC7pRaCYxyhlddJbmlqxJriOvpGSCzdo4Y38q/adROEPi5GuDJg== jest-worker@^27.0.2: version "27.0.2" @@ -6353,13 +6309,6 @@ jsonc-parser@^3.2.0: resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.2.0.tgz#31ff3f4c2b9793f89c67212627c51c6394f88e76" integrity sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w== -jsonfile@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb" - integrity sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg== - optionalDependencies: - graceful-fs "^4.1.6" - jsonfile@^6.0.1: version "6.1.0" resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae" @@ -6387,13 +6336,6 @@ kind-of@^6.0.2, kind-of@^6.0.3: resolved "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz" integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw== -klaw-sync@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/klaw-sync/-/klaw-sync-6.0.0.tgz#1fd2cfd56ebb6250181114f0a581167099c2b28c" - integrity sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ== - dependencies: - graceful-fs "^4.1.11" - kleur@^3.0.3: version "3.0.3" resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e" @@ -6970,11 +6912,6 @@ neo-async@^2.6.2: resolved "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz" integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== -nice-try@^1.0.4: - version "1.0.5" - resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" - integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== - no-case@^3.0.4: version "3.0.4" resolved "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz" @@ -7199,14 +7136,6 @@ onetime@^6.0.0: dependencies: mimic-fn "^4.0.0" -open@^7.4.2: - version "7.4.2" - resolved "https://registry.yarnpkg.com/open/-/open-7.4.2.tgz#b8147e26dcf3e426316c730089fd71edd29c2321" - integrity sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q== - dependencies: - is-docker "^2.0.0" - is-wsl "^2.1.1" - open@^8.0.9: version "8.2.1" resolved "https://registry.yarnpkg.com/open/-/open-8.2.1.tgz#82de42da0ccbf429bc12d099dad2e0975e14e8af" @@ -7400,26 +7329,6 @@ pascal-case@^3.1.2: no-case "^3.0.4" tslib "^2.0.3" -patch-package@^6.5.0: - version "6.5.0" - resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-6.5.0.tgz#feb058db56f0005da59cfa316488321de585e88a" - integrity sha512-tC3EqJmo74yKqfsMzELaFwxOAu6FH6t+FzFOsnWAuARm7/n2xB5AOeOueE221eM9gtMuIKMKpF9tBy/X2mNP0Q== - dependencies: - "@yarnpkg/lockfile" "^1.1.0" - chalk "^4.1.2" - cross-spawn "^6.0.5" - find-yarn-workspace-root "^2.0.0" - fs-extra "^7.0.1" - is-ci "^2.0.0" - klaw-sync "^6.0.0" - minimist "^1.2.6" - open "^7.4.2" - rimraf "^2.6.3" - semver "^5.6.0" - slash "^2.0.0" - tmp "^0.0.33" - yaml "^1.10.2" - path-exists@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz" @@ -7440,11 +7349,6 @@ path-is-inside@^1.0.2: resolved "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz" integrity sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM= -path-key@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40" - integrity sha512-fEHGKCSmUSDPv4uoj8AlD+joPlq3peND+HRYyxFz4KPw4z926S/b8rIuFs2FYJg3BwsxJf6A9/3eIdLaYC+9Dw== - path-key@^3.0.0, path-key@^3.1.0: version "3.1.1" resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375" @@ -8675,7 +8579,7 @@ selfsigned@^2.1.1: dependencies: node-forge "^1" -"semver@2 || 3 || 4 || 5", semver@^5.5.0, semver@^5.6.0: +"semver@2 || 3 || 4 || 5": version "5.7.1" resolved "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== @@ -8778,13 +8682,6 @@ shallow-clone@^3.0.0: dependencies: kind-of "^6.0.2" -shebang-command@^1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea" - integrity sha512-EV3L1+UQWGor21OmnvojK36mhg+TyIKDh3iFBKBohr5xeXIhNBcx8oWdgkTEEQ+BEFFYdLRuqMfd5L84N1V5Vg== - dependencies: - shebang-regex "^1.0.0" - shebang-command@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea" @@ -8792,11 +8689,6 @@ shebang-command@^2.0.0: dependencies: shebang-regex "^3.0.0" -shebang-regex@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" - integrity sha512-wpoSFAxys6b2a2wHZ1XpDSgD7N9iVjg29Ph9uV/uaP9Ex/KXlkTZTeddxDPSYQpgvzKLGJke2UU0AzoGCjNIvQ== - shebang-regex@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" @@ -8821,11 +8713,6 @@ sisteransi@^1.0.5: resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed" integrity sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg== -slash@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44" - integrity sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A== - slash@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" @@ -9606,7 +9493,7 @@ unbzip2-stream@1.4.3: buffer "^5.2.1" through "^2.3.8" -universalify@^0.1.0, universalify@^0.1.2: +universalify@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== @@ -10006,13 +9893,6 @@ which-typed-array@^1.1.2: has-tostringtag "^1.0.0" is-typed-array "^1.1.9" -which@^1.2.9: - version "1.3.1" - resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" - integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ== - dependencies: - isexe "^2.0.0" - which@^2.0.1: version "2.0.2" resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" From bc7b862590f3df65e832505987ada3789ed4e532 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Thu, 8 Dec 2022 16:00:09 +0100 Subject: [PATCH 36/47] feat: show prefixed error messages #1051 --- src/app/context/AccountContext.tsx | 3 ++- src/app/context/SettingsContext.tsx | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/context/AccountContext.tsx b/src/app/context/AccountContext.tsx index 2e6db13843..4bb4c7bdb9 100644 --- a/src/app/context/AccountContext.tsx +++ b/src/app/context/AccountContext.tsx @@ -127,7 +127,8 @@ export function AccountProvider({ children }: { children: React.ReactNode }) { } }) .catch((e) => { - toast.error( + toast.error(`An unexpected error occurred (${e.message})`); + console.error( `AccountContext: An unexpected error occurred (${e.message})` ); }) diff --git a/src/app/context/SettingsContext.tsx b/src/app/context/SettingsContext.tsx index f22c8b8178..4df38fd1d0 100644 --- a/src/app/context/SettingsContext.tsx +++ b/src/app/context/SettingsContext.tsx @@ -57,7 +57,8 @@ export const SettingsProvider = ({ setSettings(settings); }) .catch((e) => { - toast.error( + toast.error(`An unexpected error occurred (${e.message})`); + console.error( `SettingsProvider: An unexpected error occurred (${e.message})` ); }) From b9d97f36faab52bd236759a9febe684fbdded385 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Thu, 8 Dec 2022 16:20:10 +0100 Subject: [PATCH 37/47] fix: nostr getPublicKey #1051 --- .../background-script/actions/nostr/getPublicKeyOrPrompt.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extension/background-script/actions/nostr/getPublicKeyOrPrompt.ts b/src/extension/background-script/actions/nostr/getPublicKeyOrPrompt.ts index 9abebc5bb7..07dd116e6a 100644 --- a/src/extension/background-script/actions/nostr/getPublicKeyOrPrompt.ts +++ b/src/extension/background-script/actions/nostr/getPublicKeyOrPrompt.ts @@ -18,7 +18,7 @@ const getPublicKeyOrPrompt = async (message: MessagePublicKeyGet) => { ); if (hasPermission) { - const publicKey = state.getState().getNostr().getPublicKey(); + const publicKey = await state.getState().getNostr().getPublicKey(); return { data: publicKey }; } else { const promptResponse = await utils.openPrompt<{ @@ -39,7 +39,7 @@ const getPublicKeyOrPrompt = async (message: MessagePublicKeyGet) => { if (promptResponse.data.confirm) { // Normally `openPrompt` would throw already, but to make sure we got a confirm from the user we check this here - const publicKey = state.getState().getNostr().getPublicKey(); + const publicKey = await state.getState().getNostr().getPublicKey(); return { data: publicKey }; } else { return { error: "User rejected" }; From 955581f7601fb148a41b1cfe975108b1833232c7 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Tue, 13 Dec 2022 16:37:16 +0100 Subject: [PATCH 38/47] fix(notifications): update imageUrl for manifest v3 #1051 --- src/extension/background-script/events/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension/background-script/events/helpers.ts b/src/extension/background-script/events/helpers.ts index ae099166d9..2bde091636 100644 --- a/src/extension/background-script/events/helpers.ts +++ b/src/extension/background-script/events/helpers.ts @@ -7,7 +7,7 @@ const notify = (options: { title: string; message: string }) => { const notification: browser.Notifications.CreateNotificationOptions = { type: "basic", - iconUrl: "assets/icons/alby_icon_yellow_48x48.png", + iconUrl: "../assets/icons/alby_icon_yellow_48x48.png", ...options, }; From dd91efc14266840d781ee8e63a75e256a21b9854 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Tue, 7 Feb 2023 14:02:04 +0100 Subject: [PATCH 39/47] test: fix nostr tests #1051 --- src/extension/background-script/nostr/__test__/nostr.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extension/background-script/nostr/__test__/nostr.test.ts b/src/extension/background-script/nostr/__test__/nostr.test.ts index 33ec724609..779fd65007 100644 --- a/src/extension/background-script/nostr/__test__/nostr.test.ts +++ b/src/extension/background-script/nostr/__test__/nostr.test.ts @@ -27,7 +27,7 @@ describe("nostr", () => { const bobNostr = new Nostr(bob.privateKey); - const decrypted = bobNostr.decrypt(alice.publicKey, encrypted); + const decrypted = await bobNostr.decrypt(alice.publicKey, encrypted); expect(decrypted).toMatch(message); }); @@ -42,7 +42,7 @@ describe("nostr", () => { let decrypted; try { - decrypted = carolNostr.decrypt(alice.publicKey, encrypted); + decrypted = await carolNostr.decrypt(alice.publicKey, encrypted); } catch (e) { decrypted = "error decrypting message"; } From 18fa751f0430b9c259e769148a4e424735e786b6 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Tue, 7 Feb 2023 14:18:39 +0100 Subject: [PATCH 40/47] test: skip auth test till axios-fetch is fixed #1051 --- .../background-script/actions/lnurl/__tests__/auth.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/extension/background-script/actions/lnurl/__tests__/auth.test.ts b/src/extension/background-script/actions/lnurl/__tests__/auth.test.ts index 3804e8a0c7..6adbdc988f 100644 --- a/src/extension/background-script/actions/lnurl/__tests__/auth.test.ts +++ b/src/extension/background-script/actions/lnurl/__tests__/auth.test.ts @@ -26,7 +26,11 @@ const lnurlDetails: LNURLDetails = { url: "https://lnurl.fiatjaf.com/lnurl-login", }; -describe("auth", () => { +// skip till this is solved: +// https://github.com/axios/axios/pull/5146 +// test works if we do not use: +// https://github.com/getAlby/lightning-browser-extension/blob/refactor/manifest-v3-support/src/extension/background-script/actions/lnurl/auth.ts#L93 +describe.skip("auth", () => { test("returns success response", async () => { state.getState = jest.fn().mockReturnValue(mockState); From 26a9c5f54a0e1ca05642f0bdb974e4875168ad81 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Mon, 13 Feb 2023 15:29:16 +0100 Subject: [PATCH 41/47] fix(lock): close tabs/popup for chrome and firefox #1051 --- src/extension/background-script/state.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/extension/background-script/state.ts b/src/extension/background-script/state.ts index ac618b982e..f90fe3b45d 100644 --- a/src/extension/background-script/state.ts +++ b/src/extension/background-script/state.ts @@ -132,10 +132,18 @@ const state = createState((set, get) => ({ } else { set({ mv2Password: null }); } - const allTabs = browser.extension.getViews({ type: "tab" }); - for (const tab of allTabs) { - tab.close(); - } + + const allTabs = await browser.tabs.query({ title: "Alby" }); + + // https://stackoverflow.com/a/54317362/1667461 + const allTabIds = Array.from(allTabs, (tab) => tab.id).filter( + (i): i is number => { + return typeof i === "number"; + } + ); + + browser.tabs.remove(allTabIds); + const connector = get().connector; if (connector) { await connector.unload(); From 43a4091b6622616493561c4b45e4f20169552599 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Thu, 2 Mar 2023 14:42:40 +0100 Subject: [PATCH 42/47] fix: use further axios adapters #1051 --- src/app/screens/connectors/ConnectGaloy/index.tsx | 5 +++++ src/extension/background-script/connectors/kollider.ts | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/app/screens/connectors/ConnectGaloy/index.tsx b/src/app/screens/connectors/ConnectGaloy/index.tsx index 596e15c2b6..c5c8703fcc 100644 --- a/src/app/screens/connectors/ConnectGaloy/index.tsx +++ b/src/app/screens/connectors/ConnectGaloy/index.tsx @@ -1,6 +1,7 @@ import ConnectorForm from "@components/ConnectorForm"; import Input from "@components/form/Input"; import ConnectionErrorToast from "@components/toasts/ConnectionErrorToast"; +import fetchAdapter from "@vespaiach/axios-fetch-adapter"; import axios from "axios"; import { useState } from "react"; import { Trans, useTranslation } from "react-i18next"; @@ -94,6 +95,7 @@ export default function ConnectGaloy(props: Props) { data: { data, errors }, } = await axios.post(url, query, { headers: defaultHeaders, + adapter: fetchAdapter, }); const errs = errors || data.userRequestAuthCode.errors; if (errs && errs.length) { @@ -157,6 +159,7 @@ export default function ConnectGaloy(props: Props) { try { const { data: authData } = await axios.post(url, authQuery, { headers: defaultHeaders, + adapter: fetchAdapter, }); if (authData.error || authData.errors) { const error = authData.error || authData.errors; @@ -176,6 +179,7 @@ export default function ConnectGaloy(props: Props) { ...defaultHeaders, Authorization: `Bearer ${authToken}`, }, + adapter: fetchAdapter, }); if (meData.error || meData.errors) { const error = meData.error || meData.errors; @@ -225,6 +229,7 @@ export default function ConnectGaloy(props: Props) { ...defaultHeaders, Authorization: `Bearer ${authToken}`, }, + adapter: fetchAdapter, }); if (meData.error || meData.errors) { const error = meData.error || meData.errors; diff --git a/src/extension/background-script/connectors/kollider.ts b/src/extension/background-script/connectors/kollider.ts index 7a1bd6723a..a1f1f258ea 100644 --- a/src/extension/background-script/connectors/kollider.ts +++ b/src/extension/background-script/connectors/kollider.ts @@ -1,3 +1,4 @@ +import fetchAdapter from "@vespaiach/axios-fetch-adapter"; import type { AxiosResponse } from "axios"; import axios, { AxiosRequestConfig, Method } from "axios"; import Hex from "crypto-js/enc-hex"; @@ -305,6 +306,7 @@ export default class Kollider implements Connector { }, { headers: defaultHeaders, + adapter: fetchAdapter, } ); From 05802a9fbdb2f41d0d179df7f854fcc965b398e8 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Mon, 20 Mar 2023 15:55:37 +0100 Subject: [PATCH 43/47] fix(commando): revert lnmessage to v0.0.19 #1051 --- package.json | 2 +- yarn.lock | 39 +++++++-------------------------------- 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index c2a92d68c1..c087caa6d2 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "html5-qrcode": "^2.3.7", "i18next": "^22.4.10", "i18next-browser-languagedetector": "^7.0.1", - "lnmessage": "^0.1.0", + "lnmessage": "0.0.19", "lodash.merge": "^4.6.2", "lodash.pick": "^4.4.0", "lodash.snakecase": "^4.1.1", diff --git a/yarn.lock b/yarn.lock index 133398cf78..20361cc4ef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -982,11 +982,6 @@ strict-event-emitter "^0.2.4" web-encoding "^1.1.5" -"@noble/hashes@^1.2.0": - version "1.2.0" - resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.2.0.tgz#a3150eeb09cc7ab207ebf6d7b9ad311a9bdbed12" - integrity sha512-FZfhjEDbT5GRswV3C6uvLPHMiVD6lQBmpoX5+eSiPaMTXte/IKqI5dykDxzZB/WBeK/CDuQRBWarPdi3FNY2zQ== - "@noble/secp256k1@^1.7.1": version "1.7.1" resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.7.1.tgz#b251c70f824ce3ca7f8dc3df08d58f005cc0507c" @@ -6351,16 +6346,15 @@ listr2@^5.0.7: through "^2.3.8" wrap-ansi "^7.0.0" -lnmessage@^0.1.0: - version "0.1.0" - resolved "https://registry.yarnpkg.com/lnmessage/-/lnmessage-0.1.0.tgz#b5250744aff960a6ec7cdadf61612e81a74f5f2a" - integrity sha512-WyX/cTjLYX0gTBLatcAVMFPsBXwM//SqDx7qwa4KtL0RTiWkwLQ+Z/H8XFUAcd2/d9v1ou+pDUG05LiuRn4P9A== +lnmessage@0.0.19: + version "0.0.19" + resolved "https://registry.yarnpkg.com/lnmessage/-/lnmessage-0.0.19.tgz#269b47b7c806fdc0002953ed133e287ec3395765" + integrity sha512-WnDG82Imis42duRblXVfi6geyjDbdcSDwETDb+ZveKgpe8/kEbdSg8r/wxD2znNUwuCXdbSxdck/aaFrCWc1Rw== dependencies: - "@noble/hashes" "^1.2.0" buffer "^6.0.3" + crypto-js "^4.1.1" rxjs "^7.5.7" - secp256k1 "^5.0.0" - ws "^8.12.1" + secp256k1 "^4.0.3" loader-runner@^4.2.0: version "4.2.0" @@ -6863,11 +6857,6 @@ node-addon-api@^2.0.0: resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-2.0.2.tgz#432cfa82962ce494b132e9d72a15b29f71ff5d32" integrity sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA== -node-addon-api@^5.0.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-5.1.0.tgz#49da1ca055e109a23d537e9de43c09cca21eb762" - integrity sha512-eh0GgfEkpnoWDq+VY8OyvYhFEzBk6jIYbRKdIlyTiAXIVJ8PyBaKb0rp7oDtoddbdoHWhq8wwr+XZ81F1rpNdA== - node-fetch@2.6.7, node-fetch@^2.6.7: version "2.6.7" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" @@ -8451,7 +8440,7 @@ schema-utils@^4.0.0: ajv-formats "^2.1.1" ajv-keywords "^5.0.0" -secp256k1@^4.0.2: +secp256k1@^4.0.2, secp256k1@^4.0.3: version "4.0.3" resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-4.0.3.tgz#c4559ecd1b8d3c1827ed2d1b94190d69ce267303" integrity sha512-NLZVf+ROMxwtEj3Xa562qgv2BK5e2WNmXPiOdVIPLgs6lyTzMvBq0aWTYMI5XCP9jZMVKOcqZLw/Wc4vDkuxhA== @@ -8460,15 +8449,6 @@ secp256k1@^4.0.2: node-addon-api "^2.0.0" node-gyp-build "^4.2.0" -secp256k1@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-5.0.0.tgz#be6f0c8c7722e2481e9773336d351de8cddd12f7" - integrity sha512-TKWX8xvoGHrxVdqbYeZM9w+izTF4b9z3NhSaDkdn81btvuh+ivbIMGT/zQvDtTFWhRlThpoz6LEYTr7n8A5GcA== - dependencies: - elliptic "^6.5.4" - node-addon-api "^5.0.0" - node-gyp-build "^4.2.0" - select-hose@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/select-hose/-/select-hose-2.0.0.tgz" @@ -9912,11 +9892,6 @@ ws@^7.3.1: resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.9.tgz#54fa7db29f4c7cec68b1ddd3a89de099942bb591" integrity sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q== -ws@^8.12.1: - version "8.12.1" - resolved "https://registry.yarnpkg.com/ws/-/ws-8.12.1.tgz#c51e583d79140b5e42e39be48c934131942d4a8f" - integrity sha512-1qo+M9Ba+xNhPB+YTWUlK6M17brTut5EXbcBaMRN5pH5dFrXz7lzz1ChFSUq3bOUl8yEvSenhHmYUNJxFzdJew== - ws@^8.4.2: version "8.5.0" resolved "https://registry.yarnpkg.com/ws/-/ws-8.5.0.tgz#bfb4be96600757fe5382de12c670dab984a1ed4f" From 3ea8086f1be4e8673074ddee1b06f000d82a0580 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Wed, 22 Mar 2023 10:22:15 +0100 Subject: [PATCH 44/47] fix(commando): use lnmessage 0.3.0 beta #1051 --- package.json | 2 +- yarn.lock | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index c087caa6d2..d6344b1ad7 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "html5-qrcode": "^2.3.7", "i18next": "^22.4.10", "i18next-browser-languagedetector": "^7.0.1", - "lnmessage": "0.0.19", + "lnmessage": "0.1.0-0.3.0", "lodash.merge": "^4.6.2", "lodash.pick": "^4.4.0", "lodash.snakecase": "^4.1.1", diff --git a/yarn.lock b/yarn.lock index 20361cc4ef..5d5cb5aef3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -982,6 +982,11 @@ strict-event-emitter "^0.2.4" web-encoding "^1.1.5" +"@noble/hashes@^1.2.0": + version "1.3.0" + resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.0.tgz#085fd70f6d7d9d109671090ccae1d3bec62554a1" + integrity sha512-ilHEACi9DwqJB0pw7kv+Apvh50jiiSyR/cQ3y4W7lOR5mhvn/50FLUfsnfJz0BDZtl/RR16kXvptiv6q1msYZg== + "@noble/secp256k1@^1.7.1": version "1.7.1" resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.7.1.tgz#b251c70f824ce3ca7f8dc3df08d58f005cc0507c" @@ -6346,15 +6351,16 @@ listr2@^5.0.7: through "^2.3.8" wrap-ansi "^7.0.0" -lnmessage@0.0.19: - version "0.0.19" - resolved "https://registry.yarnpkg.com/lnmessage/-/lnmessage-0.0.19.tgz#269b47b7c806fdc0002953ed133e287ec3395765" - integrity sha512-WnDG82Imis42duRblXVfi6geyjDbdcSDwETDb+ZveKgpe8/kEbdSg8r/wxD2znNUwuCXdbSxdck/aaFrCWc1Rw== +lnmessage@0.1.0-0.3.0: + version "0.1.0-0.3.0" + resolved "https://registry.yarnpkg.com/lnmessage/-/lnmessage-0.1.0-0.3.0.tgz#eac5631af87a751f8c1a30ca5f511146616ad01e" + integrity sha512-uYv28zR5xPJrpqnQHNYuDEMCSmAL0aMAVcw5z2UtI+DtDyrRLlzF+MHSJGQPNWTwXtCZMVZaxFizEo2ZhCPbiA== dependencies: + "@noble/hashes" "^1.2.0" + "@noble/secp256k1" "^1.7.1" buffer "^6.0.3" - crypto-js "^4.1.1" rxjs "^7.5.7" - secp256k1 "^4.0.3" + ws "^8.12.1" loader-runner@^4.2.0: version "4.2.0" @@ -8440,7 +8446,7 @@ schema-utils@^4.0.0: ajv-formats "^2.1.1" ajv-keywords "^5.0.0" -secp256k1@^4.0.2, secp256k1@^4.0.3: +secp256k1@^4.0.2: version "4.0.3" resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-4.0.3.tgz#c4559ecd1b8d3c1827ed2d1b94190d69ce267303" integrity sha512-NLZVf+ROMxwtEj3Xa562qgv2BK5e2WNmXPiOdVIPLgs6lyTzMvBq0aWTYMI5XCP9jZMVKOcqZLw/Wc4vDkuxhA== @@ -9892,6 +9898,11 @@ ws@^7.3.1: resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.9.tgz#54fa7db29f4c7cec68b1ddd3a89de099942bb591" integrity sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q== +ws@^8.12.1: + version "8.13.0" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0" + integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA== + ws@^8.4.2: version "8.5.0" resolved "https://registry.yarnpkg.com/ws/-/ws-8.5.0.tgz#bfb4be96600757fe5382de12c670dab984a1ed4f" From b695b58ffcbaa4a1164a60835554d02d67c61d88 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Wed, 22 Mar 2023 10:22:46 +0100 Subject: [PATCH 45/47] fix: window error within SW #1051 --- src/extension/background-script/index.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/extension/background-script/index.ts b/src/extension/background-script/index.ts index e19a591110..e4b8338c5a 100644 --- a/src/extension/background-script/index.ts +++ b/src/extension/background-script/index.ts @@ -2,7 +2,6 @@ import browser, { Runtime, Tabs } from "webextension-polyfill"; import utils from "~/common/lib/utils"; import { ExtensionIcon, setIcon } from "./actions/setup/setIcon"; -import connectors from "./connectors"; import { db, isIndexedDbAvailable } from "./db"; import * as events from "./events"; import migrate from "./migrations"; @@ -147,16 +146,6 @@ async function init() { // Notify the content script that the tab has been updated. browser.tabs.onUpdated.addListener(extractLightningData); - if (debug) { - console.info("Debug mode enabled, use window.debugAlby"); - window.debugAlby = { - state, - db, - connectors, - router, - }; - } - console.info("Loading completed"); } From 573268b8562ac8be802a788ba04db5dcb95b8082 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Wed, 22 Mar 2023 10:52:43 +0100 Subject: [PATCH 46/47] chore: remove unused dep #1051 --- package.json | 1 - yarn.lock | 12 ------------ 2 files changed, 13 deletions(-) diff --git a/package.json b/package.json index d6344b1ad7..593bcc462b 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,6 @@ "@tailwindcss/forms": "^0.5.3", "@tailwindcss/line-clamp": "^0.4.2", "@vespaiach/axios-fetch-adapter": "^0.3.0", - "avvvatars-react": "^0.4.2", "axios": "^0.27.2", "bech32": "^2.0.0", "bolt11": "^1.4.0", diff --git a/yarn.lock b/yarn.lock index 5d5cb5aef3..862b716b72 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2388,13 +2388,6 @@ available-typed-arrays@^1.0.5: resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7" integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw== -avvvatars-react@^0.4.2: - version "0.4.2" - resolved "https://registry.yarnpkg.com/avvvatars-react/-/avvvatars-react-0.4.2.tgz#9569c16ae9a4925f898539ff98c6f734b6a4fe1b" - integrity sha512-D/bnSM+P6pQi71dFeFVqQsqmv+ct5XG7uO2lvJoiksALpXLd6kPgpRR1SUQxFZJkJNrkmg0NPgbhIgJgOsDYRQ== - dependencies: - goober "^2.1.8" - axios@^0.27.2: version "0.27.2" resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972" @@ -4853,11 +4846,6 @@ globby@^6.1.0: pify "^2.0.0" pinkie-promise "^2.0.0" -goober@^2.1.8: - version "2.1.12" - resolved "https://registry.yarnpkg.com/goober/-/goober-2.1.12.tgz#6c1645314ac9a68fe76408e1f502c63df8a39042" - integrity sha512-yXHAvO08FU1JgTXX6Zn6sYCUFfB/OJSX8HHjDSgerZHZmFKAb08cykp5LBw5QnmyMcZyPRMqkdyHUSSzge788Q== - graceful-fs@^4.1.2, graceful-fs@^4.2.4: version "4.2.6" resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz" From 9b53a2920779e6a2aaef0d53632d4ee73f3c24a2 Mon Sep 17 00:00:00 2001 From: escapedcat Date: Wed, 22 Mar 2023 11:03:53 +0100 Subject: [PATCH 47/47] fix: use further axios adapters #1051 --- src/extension/content-script/batteries/Mixcloud.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/extension/content-script/batteries/Mixcloud.ts b/src/extension/content-script/batteries/Mixcloud.ts index 29f7b20c77..fd2f65bf71 100644 --- a/src/extension/content-script/batteries/Mixcloud.ts +++ b/src/extension/content-script/batteries/Mixcloud.ts @@ -1,3 +1,4 @@ +import fetchAdapter from "@vespaiach/axios-fetch-adapter"; import axios from "axios"; import getOriginData from "../originData"; @@ -46,7 +47,9 @@ async function handleShowPage(username: string) { } async function handleProfilePage(username: string) { - const userResponse = await axios.get(`https://api.mixcloud.com/${username}`); + const userResponse = await axios.get(`https://api.mixcloud.com/${username}`, { + adapter: fetchAdapter, + }); if (!userResponse) return; const userInfo = await userResponse.data;