From b2de201214a6577c0105efea4d37b91b8f659cd0 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Wed, 13 Dec 2023 14:57:30 +0530 Subject: [PATCH 01/11] feat: secure allowance creationby including protocol information --- src/app/components/Enable/WeblnEnable.tsx | 11 +++++++ src/common/utils/helpers.ts | 4 +-- .../background-script/migrations/index.ts | 31 ++++++++++++------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/app/components/Enable/WeblnEnable.tsx b/src/app/components/Enable/WeblnEnable.tsx index d857ebaaa4..f6039fa09d 100644 --- a/src/app/components/Enable/WeblnEnable.tsx +++ b/src/app/components/Enable/WeblnEnable.tsx @@ -4,6 +4,7 @@ import Container from "@components/Container"; import PublisherCard from "@components/PublisherCard"; import { useState } from "react"; import { useTranslation } from "react-i18next"; +import Alert from "~/app/components/Alert"; import ScreenHeader from "~/app/components/ScreenHeader"; import toast from "~/app/components/Toast"; import { USER_REJECTED_ERROR } from "~/common/constants"; @@ -15,6 +16,7 @@ type Props = { }; function WeblnEnableComponent(props: Props) { const [loading, setLoading] = useState(false); + const hasHttp = props.origin.domain.startsWith("http://"); const { t } = useTranslation("translation", { keyPrefix: "webln_enable", }); @@ -62,6 +64,14 @@ function WeblnEnableComponent(props: Props) { isSmall={false} /> +
+ {hasHttp && ( + + ⚠️ you are connecting to a unsecure domain + + )} +
+

{tCommon("enable.allow")}

@@ -75,6 +85,7 @@ function WeblnEnableComponent(props: Props) {
+
=> { return state.getState().saveToStorage(); }; -*/ - -const migrations = {}; +const migrations = { + migrateAllowanceDomainProtocol: async () => { + const allowances = await db.allowances.toArray(); + + allowances.forEach(async (allowances) => { + allowances.id && + (await db.allowances.update(allowances.id, { + host: `https://${allowances.host}`, + })); + }); + }, +}; const migrate = async () => { // going forward we can iterate through the the migrations object above and DRY this up: // Object.keys(migrations).forEach((name: string) => { // example: - //if (shouldMigrate("migratePermissionsWithoutAccountId")) { - // console.info("Running migration for: migratePermissionsWithoutAccountId"); - // await migrations["migratePermissionsWithoutAccountId"](); - // await setMigrated("migratePermissionsWithoutAccountId"); - //} + if (shouldMigrate("migrateAllowanceDomainProtocol")) { + console.info("Running migration for: migrateAllowanceDomainProtocol"); + await migrations["migrateAllowanceDomainProtocol"](); + await setMigrated("migrateAllowanceDomainProtocol"); + } }; export default migrate; From 8fd7f02fff0345d76e6226a10102d38131b26f97 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Mon, 18 Dec 2023 16:00:05 +0530 Subject: [PATCH 02/11] feat: extend insecure allowance warning to other enable screens --- src/app/components/Enable/AlbyEnable.tsx | 10 ++++++++++ src/app/components/Enable/LiquidEnable.tsx | 10 ++++++++++ src/app/components/Enable/NostrEnable.tsx | 10 ++++++++++ src/app/components/Enable/WebbtcEnable.tsx | 10 ++++++++++ src/app/components/Enable/WeblnEnable.tsx | 2 +- src/i18n/locales/en/translation.json | 3 ++- 6 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/app/components/Enable/AlbyEnable.tsx b/src/app/components/Enable/AlbyEnable.tsx index f0d77ad086..8db3fa7184 100644 --- a/src/app/components/Enable/AlbyEnable.tsx +++ b/src/app/components/Enable/AlbyEnable.tsx @@ -4,6 +4,7 @@ import Container from "@components/Container"; import PublisherCard from "@components/PublisherCard"; import { useState } from "react"; import { useTranslation } from "react-i18next"; +import Alert from "~/app/components/Alert"; import ScreenHeader from "~/app/components/ScreenHeader"; import toast from "~/app/components/Toast"; import { USER_REJECTED_ERROR } from "~/common/constants"; @@ -15,6 +16,7 @@ type Props = { }; function AlbyEnableComponent(props: Props) { const [loading, setLoading] = useState(false); + const hasHttp = props.origin.domain.startsWith("http://"); const { t } = useTranslation("translation", { keyPrefix: "alby_enable", }); @@ -62,6 +64,14 @@ function AlbyEnableComponent(props: Props) { isSmall={false} /> +
+ {hasHttp && ( + + {tCommon("enable.insecure_domain_warn")} + + )} +
+

{tCommon("enable.allow")}

diff --git a/src/app/components/Enable/LiquidEnable.tsx b/src/app/components/Enable/LiquidEnable.tsx index 3b34f56655..7e63089526 100644 --- a/src/app/components/Enable/LiquidEnable.tsx +++ b/src/app/components/Enable/LiquidEnable.tsx @@ -4,6 +4,7 @@ import Container from "@components/Container"; import PublisherCard from "@components/PublisherCard"; import { useState } from "react"; import { useTranslation } from "react-i18next"; +import Alert from "~/app/components/Alert"; import ScreenHeader from "~/app/components/ScreenHeader"; import toast from "~/app/components/Toast"; import { USER_REJECTED_ERROR } from "~/common/constants"; @@ -15,6 +16,7 @@ type Props = { }; function LiquidEnableComponent(props: Props) { const [loading, setLoading] = useState(false); + const hasHttp = props.origin.domain.startsWith("http://"); const { t } = useTranslation("translation", { keyPrefix: "liquid_enable", }); @@ -62,6 +64,14 @@ function LiquidEnableComponent(props: Props) { isSmall={false} /> +
+ {hasHttp && ( + + {tCommon("enable.insecure_domain_warn")} + + )} +
+

{tCommon("enable.allow")}

diff --git a/src/app/components/Enable/NostrEnable.tsx b/src/app/components/Enable/NostrEnable.tsx index 8b7d0d0245..bfbbbba40e 100644 --- a/src/app/components/Enable/NostrEnable.tsx +++ b/src/app/components/Enable/NostrEnable.tsx @@ -4,6 +4,7 @@ import Container from "@components/Container"; import PublisherCard from "@components/PublisherCard"; import { useState } from "react"; import { useTranslation } from "react-i18next"; +import Alert from "~/app/components/Alert"; import ScreenHeader from "~/app/components/ScreenHeader"; import toast from "~/app/components/Toast"; import { USER_REJECTED_ERROR } from "~/common/constants"; @@ -15,6 +16,7 @@ type Props = { }; function NostrEnableComponent(props: Props) { const [loading, setLoading] = useState(false); + const hasHttp = props.origin.domain.startsWith("http://"); const { t } = useTranslation("translation", { keyPrefix: "nostr_enable", }); @@ -62,6 +64,14 @@ function NostrEnableComponent(props: Props) { isSmall={false} /> +
+ {hasHttp && ( + + {tCommon("enable.insecure_domain_warn")} + + )} +
+

{tCommon("enable.allow")}

diff --git a/src/app/components/Enable/WebbtcEnable.tsx b/src/app/components/Enable/WebbtcEnable.tsx index 61c8179b8d..101ef891fa 100644 --- a/src/app/components/Enable/WebbtcEnable.tsx +++ b/src/app/components/Enable/WebbtcEnable.tsx @@ -4,6 +4,7 @@ import Container from "@components/Container"; import PublisherCard from "@components/PublisherCard"; import { useState } from "react"; import { useTranslation } from "react-i18next"; +import Alert from "~/app/components/Alert"; import ScreenHeader from "~/app/components/ScreenHeader"; import toast from "~/app/components/Toast"; import { USER_REJECTED_ERROR } from "~/common/constants"; @@ -15,6 +16,7 @@ type Props = { }; function WebbtcEnableComponent(props: Props) { const [loading, setLoading] = useState(false); + const hasHttp = props.origin.domain.startsWith("http://"); const { t } = useTranslation("translation", { keyPrefix: "webbtc_enable", }); @@ -62,6 +64,14 @@ function WebbtcEnableComponent(props: Props) { isSmall={false} /> +
+ {hasHttp && ( + + {tCommon("enable.insecure_domain_warn")} + + )} +
+

{tCommon("enable.allow")}

diff --git a/src/app/components/Enable/WeblnEnable.tsx b/src/app/components/Enable/WeblnEnable.tsx index f6039fa09d..f52beda4d2 100644 --- a/src/app/components/Enable/WeblnEnable.tsx +++ b/src/app/components/Enable/WeblnEnable.tsx @@ -67,7 +67,7 @@ function WeblnEnableComponent(props: Props) {
{hasHttp && ( - ⚠️ you are connecting to a unsecure domain + {tCommon("enable.insecure_domain_warn")} )}
diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json index af95bbea97..39d812d822 100644 --- a/src/i18n/locales/en/translation.json +++ b/src/i18n/locales/en/translation.json @@ -1031,7 +1031,8 @@ "allow": "Allow this website to:", "block_added": "Added {{host}} to the blocklist, please reload the website.", "request1": "Request approval for transactions", - "block_and_ignore": "Block and ignore {{host}}" + "block_and_ignore": "Block and ignore {{host}}", + "insecure_domain_warn": "⚠️ You are connecting to an insecure domain." } }, "components": { From f6f5dfa892cdc575310421a7db50cc2e5520bb46 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Mon, 18 Dec 2023 17:37:36 +0530 Subject: [PATCH 03/11] feat: fix tests --- .../actions/allowances/__tests__/delete.test.ts | 2 +- .../actions/allowances/__tests__/enable.test.ts | 4 ++-- .../actions/allowances/__tests__/get.test.ts | 2 +- .../actions/nostr/__tests__/signSchnorr.test.ts | 4 ++-- .../actions/payments/__tests__/all.test.ts | 4 ++-- .../events/__test__/persistPayments.test.ts | 4 ++-- .../events/__test__/updateAllowances.test.ts | 4 ++-- src/fixtures/allowances.ts | 4 ++-- src/fixtures/payment.ts | 4 ++-- src/fixtures/permissions.ts | 6 +++--- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/extension/background-script/actions/allowances/__tests__/delete.test.ts b/src/extension/background-script/actions/allowances/__tests__/delete.test.ts index 4ff5b4b68d..b046942743 100644 --- a/src/extension/background-script/actions/allowances/__tests__/delete.test.ts +++ b/src/extension/background-script/actions/allowances/__tests__/delete.test.ts @@ -74,7 +74,7 @@ describe("delete allowance", () => { expect(dbAllowances).toEqual([ { enabled: true, - host: "getalby.com", + host: "https://getalby.com", id: 1, imageURL: "https://getalby.com/favicon.ico", lastPaymentAt: 0, diff --git a/src/extension/background-script/actions/allowances/__tests__/enable.test.ts b/src/extension/background-script/actions/allowances/__tests__/enable.test.ts index c4888b1cf5..77b977bd92 100644 --- a/src/extension/background-script/actions/allowances/__tests__/enable.test.ts +++ b/src/extension/background-script/actions/allowances/__tests__/enable.test.ts @@ -45,7 +45,7 @@ describe("enable allowance", () => { external: true, }, args: { - host: "lnmarkets.com", + host: "https://lnmarkets.com", }, }; @@ -87,7 +87,7 @@ describe("enable allowance", () => { external: true, }, args: { - host: "getalby.com", + host: `https://getalby.com`, }, }; const sender: Sender = { diff --git a/src/extension/background-script/actions/allowances/__tests__/get.test.ts b/src/extension/background-script/actions/allowances/__tests__/get.test.ts index cba11f1235..12ab18dfe3 100644 --- a/src/extension/background-script/actions/allowances/__tests__/get.test.ts +++ b/src/extension/background-script/actions/allowances/__tests__/get.test.ts @@ -23,7 +23,7 @@ describe("get allowance", () => { internal: true, }, args: { - host: "getalby.com", + host: "https://getalby.com", }, }; diff --git a/src/extension/background-script/actions/nostr/__tests__/signSchnorr.test.ts b/src/extension/background-script/actions/nostr/__tests__/signSchnorr.test.ts index 7d76f96eac..750c6d1a25 100644 --- a/src/extension/background-script/actions/nostr/__tests__/signSchnorr.test.ts +++ b/src/extension/background-script/actions/nostr/__tests__/signSchnorr.test.ts @@ -45,8 +45,8 @@ const sender: Sender = { documentId: "ALBY123", documentLifecycle: "active", id: "alby", - origin: `https://${allowanceInDB.host}`, - url: `https://${allowanceInDB.host}/test`, + origin: `${allowanceInDB.host}`, + url: `${allowanceInDB.host}/test`, }; const requestResponse = { data: "" }; diff --git a/src/extension/background-script/actions/payments/__tests__/all.test.ts b/src/extension/background-script/actions/payments/__tests__/all.test.ts index f7f34c8769..83e2e77b4c 100644 --- a/src/extension/background-script/actions/payments/__tests__/all.test.ts +++ b/src/extension/background-script/actions/payments/__tests__/all.test.ts @@ -10,7 +10,7 @@ const mockPayments: DbPayment[] = [ createdAt: "123456", description: "A blue bird?!", destination: "Space", - host: "getalby.com", + host: "https://getalby.com", id: 4, location: "https://www.getalby.com", name: "Alby", @@ -26,7 +26,7 @@ const mockPayments: DbPayment[] = [ createdAt: "123456", description: "A yellow bird?!", destination: "Space", - host: "getalby.com", + host: "https://getalby.com", id: 5, location: "https://www.getalby.com", name: "Alby", diff --git a/src/extension/background-script/events/__test__/persistPayments.test.ts b/src/extension/background-script/events/__test__/persistPayments.test.ts index da047eea94..f20cdc1722 100644 --- a/src/extension/background-script/events/__test__/persistPayments.test.ts +++ b/src/extension/background-script/events/__test__/persistPayments.test.ts @@ -24,7 +24,7 @@ const updatedPayments: DbPayment[] = [ createdAt: "1487076708000", description: "A red bird?!", destination: "Space", - host: "getalby.com", + host: "https://getalby.com", id: 6, location: "test", name: "Alby", @@ -73,7 +73,7 @@ const data: PaymentNotificationData = { origin: { location: "test", domain: "", - host: "getalby.com", + host: "https://getalby.com", pathname: "test", name: "Alby", description: "test", diff --git a/src/extension/background-script/events/__test__/updateAllowances.test.ts b/src/extension/background-script/events/__test__/updateAllowances.test.ts index de645ce18d..76961504f7 100644 --- a/src/extension/background-script/events/__test__/updateAllowances.test.ts +++ b/src/extension/background-script/events/__test__/updateAllowances.test.ts @@ -32,7 +32,7 @@ const data: PaymentNotificationData = { origin: { location: "test", domain: "", - host: "getalby.com", + host: "https://getalby.com", pathname: "test", name: "Alby", description: "test", @@ -56,7 +56,7 @@ describe("Update Allowances", () => { internal: true, }, args: { - host: "getalby.com", + host: "https://getalby.com", }, }; diff --git a/src/fixtures/allowances.ts b/src/fixtures/allowances.ts index 3c5e6bb714..a656e519ee 100644 --- a/src/fixtures/allowances.ts +++ b/src/fixtures/allowances.ts @@ -3,7 +3,7 @@ import type { DbAllowance } from "~/types"; export const allowanceFixture: DbAllowance[] = [ { enabled: true, - host: "getalby.com", + host: "https://getalby.com", id: 1, imageURL: "https://getalby.com/favicon.ico", lastPaymentAt: 0, @@ -17,7 +17,7 @@ export const allowanceFixture: DbAllowance[] = [ }, { enabled: false, - host: "lnmarkets.com", + host: "https://lnmarkets.com", id: 2, imageURL: "https://lnmarkets.com/apple-touch-icon.png", lastPaymentAt: 0, diff --git a/src/fixtures/payment.ts b/src/fixtures/payment.ts index cd970f1c57..38b5a8aedc 100644 --- a/src/fixtures/payment.ts +++ b/src/fixtures/payment.ts @@ -7,7 +7,7 @@ export const paymentsFixture: DbPayment[] = [ createdAt: "123456", description: "A blue bird?!", destination: "Space", - host: "getalby.com", + host: "https://getalby.com", id: 4, location: "https://www.getalby.com", name: "Alby", @@ -23,7 +23,7 @@ export const paymentsFixture: DbPayment[] = [ createdAt: "123456", description: "A yellow bird?!", destination: "Space", - host: "getalby.com", + host: "https://getalby.com", id: 5, location: "https://www.getalby.com", name: "Alby", diff --git a/src/fixtures/permissions.ts b/src/fixtures/permissions.ts index e2d8871f8e..12ef3e607c 100644 --- a/src/fixtures/permissions.ts +++ b/src/fixtures/permissions.ts @@ -6,7 +6,7 @@ export const permissionsFixture: DbPermission[] = [ accountId: "8b7f1dc6-ab87-4c6c-bca5-19fa8632731e", allowanceId: 1, createdAt: "1487076708000", - host: "getalby.com", + host: "https://getalby.com", method: "the-request-method-1", blocked: false, enabled: true, @@ -16,7 +16,7 @@ export const permissionsFixture: DbPermission[] = [ accountId: "8b7f1dc6-ab87-4c6c-bca5-19fa8632731e", allowanceId: 1, createdAt: "1487076708000", - host: "getalby.com", + host: "https://getalby.com", method: "the-request-method-2", blocked: false, enabled: true, @@ -26,7 +26,7 @@ export const permissionsFixture: DbPermission[] = [ accountId: "8b7f1dc6-ab87-4c6c-bca5-19fa8632731e", allowanceId: 2, createdAt: "1487076708000", - host: "lnmarkets.com", + host: "https://lnmarkets.com", method: "the-request-method-3", blocked: false, enabled: true, From ee00ddf84ee6b94c5acb2071598318ca88cd3d63 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Mon, 18 Dec 2023 18:19:03 +0530 Subject: [PATCH 04/11] feat: add protocol info while adding new allowances --- src/app/screens/ConfirmKeysend/index.tsx | 2 +- src/app/screens/ConfirmPayment/index.tsx | 2 +- .../actions/allowances/__tests__/add.test.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/screens/ConfirmKeysend/index.tsx b/src/app/screens/ConfirmKeysend/index.tsx index 34c3de533d..efd3008b96 100644 --- a/src/app/screens/ConfirmKeysend/index.tsx +++ b/src/app/screens/ConfirmKeysend/index.tsx @@ -116,7 +116,7 @@ function ConfirmKeysend() { if (!budget) return; return msg.request("addAllowance", { totalBudget: parseInt(budget), - host: origin.host, + host: origin.domain, name: origin.name, imageURL: origin.icon, }); diff --git a/src/app/screens/ConfirmPayment/index.tsx b/src/app/screens/ConfirmPayment/index.tsx index de55ee54cb..118410ad0c 100644 --- a/src/app/screens/ConfirmPayment/index.tsx +++ b/src/app/screens/ConfirmPayment/index.tsx @@ -122,7 +122,7 @@ function ConfirmPayment() { if (!budget || !navState.origin) return; return msg.request("addAllowance", { totalBudget: parseInt(budget), - host: navState.origin.host, + host: navState.origin.domain, name: navState.origin.name, imageURL: navState.origin.icon, }); diff --git a/src/extension/background-script/actions/allowances/__tests__/add.test.ts b/src/extension/background-script/actions/allowances/__tests__/add.test.ts index 03d903899a..c150b8710e 100644 --- a/src/extension/background-script/actions/allowances/__tests__/add.test.ts +++ b/src/extension/background-script/actions/allowances/__tests__/add.test.ts @@ -22,7 +22,7 @@ describe("add allowance", () => { internal: true, }, args: { - host: "lnmarkets.com", + host: "https://lnmarkets.com", name: "LN Markets", imageURL: "https://lnmarkets.com/apple-touch-icon.png", totalBudget: 200, @@ -41,7 +41,7 @@ describe("add allowance", () => { expect(dbAllowances).toContainEqual({ createdAt: "1487076708000", enabled: true, - host: "lnmarkets.com", + host: "https://lnmarkets.com", imageURL: "https://lnmarkets.com/apple-touch-icon.png", lastPaymentAt: 0, lnurlAuth: false, From 6a9f4f55efecf1911b8b65a80e71125b25d04828 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Tue, 19 Dec 2023 11:28:29 +0530 Subject: [PATCH 05/11] fix: resolve broken links in connected sites --- src/app/components/PublisherPanel/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/PublisherPanel/index.tsx b/src/app/components/PublisherPanel/index.tsx index d67cb575a2..9a26fbcf3f 100644 --- a/src/app/components/PublisherPanel/index.tsx +++ b/src/app/components/PublisherPanel/index.tsx @@ -70,7 +70,7 @@ export default function PublisherPanel({ {url && ( Date: Tue, 19 Dec 2023 14:17:59 +0530 Subject: [PATCH 06/11] feat: include host with protocol in persistPayment migrate existing host in payments table --- .../background-script/events/persistPayments.ts | 2 +- .../background-script/migrations/index.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/extension/background-script/events/persistPayments.ts b/src/extension/background-script/events/persistPayments.ts index 1574b429eb..5f3a9cb39d 100644 --- a/src/extension/background-script/events/persistPayments.ts +++ b/src/extension/background-script/events/persistPayments.ts @@ -7,7 +7,7 @@ const persistSuccessfulPayment = async ( data: PaymentNotificationData ) => { const name = data?.origin?.name; - const host = data?.origin?.host || ""; + const host = data?.origin?.domain || ""; const location = data?.origin?.location; const accountId = data.accountId; const paymentResponse = data.response; diff --git a/src/extension/background-script/migrations/index.ts b/src/extension/background-script/migrations/index.ts index bc81a2759c..2352b97b79 100644 --- a/src/extension/background-script/migrations/index.ts +++ b/src/extension/background-script/migrations/index.ts @@ -39,6 +39,17 @@ const migrations = { })); }); }, + + migrateHostInPayments: async () => { + const payments = await db.payments.toArray(); + + payments.forEach(async (payments) => { + payments.id && + (await db.payments.update(payments.id, { + host: `https://${payments.host}`, + })); + }); + }, }; const migrate = async () => { @@ -50,6 +61,12 @@ const migrate = async () => { await migrations["migrateAllowanceDomainProtocol"](); await setMigrated("migrateAllowanceDomainProtocol"); } + + if (shouldMigrate("migrateHostInPayments")) { + console.info("Running migration for: migrateHostInPayments"); + await migrations["migrateHostInPayments"](); + await setMigrated("migrateHostInPayments"); + } }; export default migrate; From 4dd37b4017ab6091f608f8225d0556384ae1d0d1 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Fri, 29 Dec 2023 15:01:18 +0530 Subject: [PATCH 07/11] feat: fix getAllowance call --- src/app/components/LNURLAuth/index.tsx | 4 ++-- src/app/screens/Home/index.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/components/LNURLAuth/index.tsx b/src/app/components/LNURLAuth/index.tsx index cb11ef5eca..f8e78105eb 100644 --- a/src/app/components/LNURLAuth/index.tsx +++ b/src/app/components/LNURLAuth/index.tsx @@ -36,8 +36,8 @@ function LNURLAuthComponent() { lnurlDetails: details, }); - if (navState.isPrompt && origin?.host) { - const allowance = await api.getAllowance(origin.host); + if (navState.isPrompt && origin?.domain) { + const allowance = await api.getAllowance(origin.domain); if (allowance.lnurlAuth === false) { await msg.request("updateAllowance", { diff --git a/src/app/screens/Home/index.tsx b/src/app/screens/Home/index.tsx index 181175f19a..d922c21374 100644 --- a/src/app/screens/Home/index.tsx +++ b/src/app/screens/Home/index.tsx @@ -20,7 +20,7 @@ const Home: FC = () => { // typeguard, currentUrl should exist at this point if (!currentUrl) throw new Error("No established browser connection"); - const result = await api.getAllowance(currentUrl.host); + const result = await api.getAllowance(currentUrl.origin); if (result.enabled) { setAllowance(result); From 656d496f5e920c476e01391192b9a6f7c37bd62c Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Fri, 29 Dec 2023 15:15:27 +0530 Subject: [PATCH 08/11] feat: migrate blocklist host --- .../background-script/migrations/index.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/extension/background-script/migrations/index.ts b/src/extension/background-script/migrations/index.ts index 2352b97b79..9083bb6410 100644 --- a/src/extension/background-script/migrations/index.ts +++ b/src/extension/background-script/migrations/index.ts @@ -50,6 +50,17 @@ const migrations = { })); }); }, + + migrateHostInBlocklist: async () => { + const blocklist = await db.blocklist.toArray(); + + blocklist.forEach(async (blocklist) => { + blocklist.id && + (await db.blocklist.update(blocklist.id, { + host: `https://${blocklist.host}`, + })); + }); + }, }; const migrate = async () => { @@ -67,6 +78,12 @@ const migrate = async () => { await migrations["migrateHostInPayments"](); await setMigrated("migrateHostInPayments"); } + + if (shouldMigrate("migrateHostInBlocklist")) { + console.info("Running migration for: migrateHostInBlocklist"); + await migrations["migrateHostInBlocklist"](); + await setMigrated("migrateHostInBlocklist"); + } }; export default migrate; From a95d0070fc515e37ab796bf8ea5c9dface2d1605 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Fri, 29 Dec 2023 15:24:29 +0530 Subject: [PATCH 09/11] feat: migrate host in blocklist and permissions --- .../background-script/migrations/index.ts | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/extension/background-script/migrations/index.ts b/src/extension/background-script/migrations/index.ts index 9083bb6410..efc411b354 100644 --- a/src/extension/background-script/migrations/index.ts +++ b/src/extension/background-script/migrations/index.ts @@ -29,7 +29,7 @@ const setMigrated = (name: Migration): Promise => { }; const migrations = { - migrateAllowanceDomainProtocol: async () => { + migrateHostInAllowances: async () => { const allowances = await db.allowances.toArray(); allowances.forEach(async (allowances) => { @@ -52,12 +52,23 @@ const migrations = { }, migrateHostInBlocklist: async () => { - const blocklist = await db.blocklist.toArray(); + const blocklists = await db.blocklist.toArray(); - blocklist.forEach(async (blocklist) => { - blocklist.id && - (await db.blocklist.update(blocklist.id, { - host: `https://${blocklist.host}`, + blocklists.forEach(async (blocklists) => { + blocklists.id && + (await db.blocklist.update(blocklists.id, { + host: `https://${blocklists.host}`, + })); + }); + }, + + migrateHostInPermissions: async () => { + const permissions = await db.permissions.toArray(); + + permissions.forEach(async (permissions) => { + permissions.id && + (await db.permissions.update(permissions.id, { + host: `https://${permissions.host}`, })); }); }, @@ -67,10 +78,10 @@ const migrate = async () => { // going forward we can iterate through the the migrations object above and DRY this up: // Object.keys(migrations).forEach((name: string) => { // example: - if (shouldMigrate("migrateAllowanceDomainProtocol")) { - console.info("Running migration for: migrateAllowanceDomainProtocol"); - await migrations["migrateAllowanceDomainProtocol"](); - await setMigrated("migrateAllowanceDomainProtocol"); + if (shouldMigrate("migrateHostInAllowances")) { + console.info("Running migration for: migrateHostInAllowances"); + await migrations["migrateHostInAllowances"](); + await setMigrated("migrateHostInAllowances"); } if (shouldMigrate("migrateHostInPayments")) { @@ -84,6 +95,11 @@ const migrate = async () => { await migrations["migrateHostInBlocklist"](); await setMigrated("migrateHostInBlocklist"); } + if (shouldMigrate("migrateHostInPermissions")) { + console.info("Running migration for: migrateHostInPermissions"); + await migrations["migrateHostInPermissions"](); + await setMigrated("migrateHostInPermissions"); + } }; export default migrate; From 21af3999a696cb2da70e40a62bfd8f5e446991da Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Fri, 29 Dec 2023 15:59:32 +0530 Subject: [PATCH 10/11] fix: tests in persist-payments --- .../background-script/events/__test__/persistPayments.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension/background-script/events/__test__/persistPayments.test.ts b/src/extension/background-script/events/__test__/persistPayments.test.ts index f20cdc1722..bb9b0d2af9 100644 --- a/src/extension/background-script/events/__test__/persistPayments.test.ts +++ b/src/extension/background-script/events/__test__/persistPayments.test.ts @@ -72,7 +72,7 @@ const data: PaymentNotificationData = { }, origin: { location: "test", - domain: "", + domain: "https://getalby.com", host: "https://getalby.com", pathname: "test", name: "Alby", From d8936c52f4fb33261672a95bc5665397a681ba0e Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Fri, 29 Dec 2023 16:38:48 +0530 Subject: [PATCH 11/11] fix: revert blocklist and permissions migrations --- .../background-script/migrations/index.ts | 33 ------------------- 1 file changed, 33 deletions(-) diff --git a/src/extension/background-script/migrations/index.ts b/src/extension/background-script/migrations/index.ts index efc411b354..1fdf286858 100644 --- a/src/extension/background-script/migrations/index.ts +++ b/src/extension/background-script/migrations/index.ts @@ -50,28 +50,6 @@ const migrations = { })); }); }, - - migrateHostInBlocklist: async () => { - const blocklists = await db.blocklist.toArray(); - - blocklists.forEach(async (blocklists) => { - blocklists.id && - (await db.blocklist.update(blocklists.id, { - host: `https://${blocklists.host}`, - })); - }); - }, - - migrateHostInPermissions: async () => { - const permissions = await db.permissions.toArray(); - - permissions.forEach(async (permissions) => { - permissions.id && - (await db.permissions.update(permissions.id, { - host: `https://${permissions.host}`, - })); - }); - }, }; const migrate = async () => { @@ -89,17 +67,6 @@ const migrate = async () => { await migrations["migrateHostInPayments"](); await setMigrated("migrateHostInPayments"); } - - if (shouldMigrate("migrateHostInBlocklist")) { - console.info("Running migration for: migrateHostInBlocklist"); - await migrations["migrateHostInBlocklist"](); - await setMigrated("migrateHostInBlocklist"); - } - if (shouldMigrate("migrateHostInPermissions")) { - console.info("Running migration for: migrateHostInPermissions"); - await migrations["migrateHostInPermissions"](); - await setMigrated("migrateHostInPermissions"); - } }; export default migrate;