From b4f3a58e70584412230937c22cb58d8a1949a479 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Tue, 20 Feb 2024 15:09:55 +0530 Subject: [PATCH 01/38] feat: initia nostr permission suffix --- src/app/components/SitePreferences/index.tsx | 30 +++++++++++++++++-- .../actions/nostr/signEventOrPrompt.ts | 4 +-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/app/components/SitePreferences/index.tsx b/src/app/components/SitePreferences/index.tsx index ab66dcc575..b0bf366271 100644 --- a/src/app/components/SitePreferences/index.tsx +++ b/src/app/components/SitePreferences/index.tsx @@ -46,6 +46,9 @@ function SitePreferences({ launcherType, allowance, onEdit, onDelete }: Props) { const { t } = useTranslation("components", { keyPrefix: "allowance_menu" }); const { t: tCommon } = useTranslation("common"); const { t: tPermissions } = useTranslation("permissions"); + const { t: tNostr } = useTranslation("translation", { + keyPrefix: "nostr", + }); const hasPermissions = !isLoadingPermissions && !!permissions?.length; @@ -221,12 +224,35 @@ function SitePreferences({ launcherType, allowance, onEdit, onDelete }: Props) { {permissions.map((permission) => ( { } const hasPermission = await hasPermissionFor( - PermissionMethodNostr["NOSTR_SIGNMESSAGE"], + PermissionMethodNostr["NOSTR_SIGNMESSAGE"] + "/" + event.kind, host ); if (!hasPermission) { @@ -41,7 +41,7 @@ const signEventOrPrompt = async (message: MessageSignEvent, sender: Sender) => { // add permission to db only if user decided to always allow this request if (promptResponse.data.enabled) { await addPermissionFor( - PermissionMethodNostr["NOSTR_SIGNMESSAGE"], + PermissionMethodNostr["NOSTR_SIGNMESSAGE"] + "/" + event.kind, host ); } From 594778ceb52241104969267fb3e6f676fe186348 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Wed, 21 Feb 2024 15:41:58 +0530 Subject: [PATCH 02/38] feat: implement multiple permission options --- src/app/components/SitePreferences/index.tsx | 11 +++---- src/app/screens/Nostr/ConfirmSignMessage.tsx | 30 +++++++++---------- .../actions/nostr/signEventOrPrompt.ts | 24 +++++++++++---- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/app/components/SitePreferences/index.tsx b/src/app/components/SitePreferences/index.tsx index b0bf366271..b4a1eacdaa 100644 --- a/src/app/components/SitePreferences/index.tsx +++ b/src/app/components/SitePreferences/index.tsx @@ -237,13 +237,10 @@ function SitePreferences({ launcherType, allowance, onEdit, onDelete }: Props) { .slice(-1) .toString()}`, { - defaultValue: tNostr("kinds.unknown", { - kind: permission.method - .toLowerCase() - .split("/") - .slice(-1) - .toString(), - }), + defaultValue: permission.method + .split("/") + .slice(-1) + .toString(), } ) : permission.method.split("/").slice(0, 2).join("/") diff --git a/src/app/screens/Nostr/ConfirmSignMessage.tsx b/src/app/screens/Nostr/ConfirmSignMessage.tsx index 8607bcfca5..ae8e6a5a8a 100644 --- a/src/app/screens/Nostr/ConfirmSignMessage.tsx +++ b/src/app/screens/Nostr/ConfirmSignMessage.tsx @@ -3,7 +3,6 @@ import Container from "@components/Container"; import ContentMessage from "@components/ContentMessage"; import PublisherCard from "@components/PublisherCard"; import SuccessMessage from "@components/SuccessMessage"; -import Checkbox from "@components/form/Checkbox"; import { useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; @@ -28,7 +27,7 @@ function ConfirmSignMessage() { const origin = navState.origin as OriginData; const [loading, setLoading] = useState(false); const [successMessage, setSuccessMessage] = useState(""); - const [rememberPermission, setRememberPermission] = useState(false); + const [permissionOption, setPermissionOption] = useState("ask_every_time"); const [showJSON, setShowJSON] = useState(false); // TODO: refactor: the success message and loading will not be displayed because after the reply the prompt is closed. @@ -37,7 +36,7 @@ function ConfirmSignMessage() { setLoading(true); msg.reply({ blocked: false, - enabled: rememberPermission, + permissionOption: permissionOption, }); setSuccessMessage(tCommon("success")); } catch (e) { @@ -115,20 +114,19 @@ function ConfirmSignMessage() {
- { - setRememberPermission(event.target.checked); - }} - /> - + + + +
{ }; } - const hasPermission = await hasPermissionFor( - PermissionMethodNostr["NOSTR_SIGNMESSAGE"] + "/" + event.kind, - host - ); + const hasPermission = + (await hasPermissionFor( + PermissionMethodNostr["NOSTR_SIGNMESSAGE"], + host + )) || + (await hasPermissionFor( + PermissionMethodNostr["NOSTR_SIGNMESSAGE"] + "/" + event.kind, + host + )); if (!hasPermission) { const promptResponse = await utils.openPrompt<{ - enabled: boolean; blocked: boolean; + permissionOption: string; }>({ ...message, action: "public/nostr/confirmSignMessage", }); // add permission to db only if user decided to always allow this request - if (promptResponse.data.enabled) { + if (promptResponse.data.permissionOption == "dont_ask_again_current") { await addPermissionFor( PermissionMethodNostr["NOSTR_SIGNMESSAGE"] + "/" + event.kind, host ); } + + if (promptResponse.data.permissionOption == "dont_ask_again_all") { + await addPermissionFor( + PermissionMethodNostr["NOSTR_SIGNMESSAGE"], + host + ); + } } if (!event.pubkey) event.pubkey = nostr.getPublicKey(); From 86912accc51aa6e749771477c51490c7dbe565dd Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Fri, 1 Mar 2024 16:18:20 +0530 Subject: [PATCH 03/38] feat: permission popup model --- src/app/components/PermissionModal/index.tsx | 114 +++++++++++++++++++ src/app/screens/Nostr/ConfirmSignMessage.tsx | 46 +++++--- 2 files changed, 144 insertions(+), 16 deletions(-) create mode 100644 src/app/components/PermissionModal/index.tsx diff --git a/src/app/components/PermissionModal/index.tsx b/src/app/components/PermissionModal/index.tsx new file mode 100644 index 0000000000..241e45ad26 --- /dev/null +++ b/src/app/components/PermissionModal/index.tsx @@ -0,0 +1,114 @@ +import { useState } from "react"; +import { useTranslation } from "react-i18next"; +import Button from "~/app/components/Button"; +import Modal from "~/app/components/Modal"; +import PublisherCard from "~/app/components/PublisherCard"; +import { useNavigationState } from "~/app/hooks/useNavigationState"; +import { OriginData } from "~/types"; + +type Props = { + onClose: () => void; + isOpen: boolean; + PermssionCallback: (permission: string) => void; + permission: string; +}; + +export default function PermissionModal({ + isOpen, + onClose, + PermssionCallback, + permission, +}: Props) { + const { t: tCommon } = useTranslation("common"); + + const navState = useNavigationState(); + const [permissionOption, setPermissionOption] = useState("ask_every_time"); + const origin = navState.origin as OriginData; + + return ( + { + onClose(); + }} + contentLabel={"Transactions"} + position="top" + > +
+ +
    +
  • + { + setPermissionOption("ask_every_time"); + }} + /> + +
  • + +
  • + { + setPermissionOption("dont_ask_again_current"); + }} + /> + +
  • +
  • + { + setPermissionOption("dont_ask_again_all"); + }} + /> + +
  • +
+ +
+
+
+
+ ); +} diff --git a/src/app/screens/Nostr/ConfirmSignMessage.tsx b/src/app/screens/Nostr/ConfirmSignMessage.tsx index ae8e6a5a8a..f62465beba 100644 --- a/src/app/screens/Nostr/ConfirmSignMessage.tsx +++ b/src/app/screens/Nostr/ConfirmSignMessage.tsx @@ -3,10 +3,12 @@ import Container from "@components/Container"; import ContentMessage from "@components/ContentMessage"; import PublisherCard from "@components/PublisherCard"; import SuccessMessage from "@components/SuccessMessage"; +import { PopiconsShieldCheckLine } from "@popicons/react"; import { useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; import Hyperlink from "~/app/components/Hyperlink"; +import PermissionModal from "~/app/components/PermissionModal"; import ScreenHeader from "~/app/components/ScreenHeader"; import toast from "~/app/components/Toast"; import { useNavigationState } from "~/app/hooks/useNavigationState"; @@ -27,8 +29,10 @@ function ConfirmSignMessage() { const origin = navState.origin as OriginData; const [loading, setLoading] = useState(false); const [successMessage, setSuccessMessage] = useState(""); - const [permissionOption, setPermissionOption] = useState("ask_every_time"); + const [showJSON, setShowJSON] = useState(false); + const [modalOpen, setModalOpen] = useState(false); + const [permissionOption, setPermissionOption] = useState("ask_every_time"); // TODO: refactor: the success message and loading will not be displayed because after the reply the prompt is closed. async function confirm() { @@ -113,26 +117,36 @@ function ConfirmSignMessage() { )}
-
- -
+
+ { + setModalOpen(false); + }} + PermssionCallback={(permission) => { + setPermissionOption(permission); + setModalOpen(false); + }} + permission={t(`kinds.${event.kind}`, { + defaultValue: t("kinds.unknown", { + kind: event.kind, + }), + })} + /> + +
+
+ +
+ +
From 3c0372cbc467c77d22708ed805f8562f1d3d9230 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Wed, 6 Mar 2024 18:23:41 +0530 Subject: [PATCH 04/38] refactor: permissiom modal --- src/app/components/PermissionModal/index.tsx | 105 +++++++++---------- src/i18n/locales/en/translation.json | 6 ++ 2 files changed, 53 insertions(+), 58 deletions(-) diff --git a/src/app/components/PermissionModal/index.tsx b/src/app/components/PermissionModal/index.tsx index 241e45ad26..5a0588dcfb 100644 --- a/src/app/components/PermissionModal/index.tsx +++ b/src/app/components/PermissionModal/index.tsx @@ -1,5 +1,5 @@ import { useState } from "react"; -import { useTranslation } from "react-i18next"; +import { Trans, useTranslation } from "react-i18next"; import Button from "~/app/components/Button"; import Modal from "~/app/components/Modal"; import PublisherCard from "~/app/components/PublisherCard"; @@ -21,8 +21,12 @@ export default function PermissionModal({ }: Props) { const { t: tCommon } = useTranslation("common"); + const { t } = useTranslation("components", { + keyPrefix: "permissions_modal", + }); + const navState = useNavigationState(); - const [permissionOption, setPermissionOption] = useState("ask_every_time"); + const [permissionOption, setPermissionOption] = useState("ask_everytime"); const origin = navState.origin as OriginData; return ( @@ -42,63 +46,13 @@ export default function PermissionModal({ isSmall={false} isCard={false} /> -
    -
  • - { - setPermissionOption("ask_every_time"); - }} - /> - -
  • +
    +

    {t("set_permissions")}

    -
  • - { - setPermissionOption("dont_ask_again_current"); - }} - /> - -
  • -
  • - { - setPermissionOption("dont_ask_again_all"); - }} - /> - -
  • -
+ + + +
@@ -72,7 +73,7 @@ export default function PermissionModal({ function ListItem({ checkedValue }: ListItemProps) { return ( -
+
-
-
+
{ @@ -139,12 +144,23 @@ function ConfirmSignMessage() { onCancel={reject} /> -
+
From 05258655ff1283449ab2bfd496e6a7d0bcb17aac Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Wed, 13 Mar 2024 15:24:51 +0530 Subject: [PATCH 07/38] feat: deletable badge permissions --- src/app/components/Badge/index.tsx | 28 ++++++++++--- src/app/components/SitePreferences/index.tsx | 43 +++++++------------- src/i18n/locales/en/translation.json | 1 - 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/app/components/Badge/index.tsx b/src/app/components/Badge/index.tsx index 2fe880828a..ff9fe5908f 100644 --- a/src/app/components/Badge/index.tsx +++ b/src/app/components/Badge/index.tsx @@ -1,24 +1,40 @@ +import { CrossIcon } from "@bitcoin-design/bitcoin-icons-react/outline"; import { useTranslation } from "react-i18next"; import { classNames } from "~/app/utils"; type Props = { - label: "budget" | "auth" | "imported"; + label?: "budget" | "auth" | "imported"; + sitePermission?: string; className: string; + delete?: () => void; }; -export default function Badge({ label, className }: Props) { +export default function Badge({ + label, + className, + sitePermission, + delete: deletePermission, +}: Props) { const { t: tComponents } = useTranslation("components", { keyPrefix: "badge", }); return ( - - {tComponents(`label.${label}`)} - + {label ? tComponents(`label.${label}`) : sitePermission} + {deletePermission && ( + + )} +
); } diff --git a/src/app/components/SitePreferences/index.tsx b/src/app/components/SitePreferences/index.tsx index b4a1eacdaa..2a8c955f8c 100644 --- a/src/app/components/SitePreferences/index.tsx +++ b/src/app/components/SitePreferences/index.tsx @@ -12,6 +12,7 @@ import { PreferencesIcon } from "~/app/icons"; import msg from "~/common/lib/msg"; import type { Allowance, Permission } from "~/types"; +import Badge from "~/app/components/Badge"; import Modal from "~/app/components/Modal"; import DualCurrencyField from "../form/DualCurrencyField/index"; @@ -45,7 +46,6 @@ function SitePreferences({ launcherType, allowance, onEdit, onDelete }: Props) { const { t } = useTranslation("components", { keyPrefix: "allowance_menu" }); const { t: tCommon } = useTranslation("common"); - const { t: tPermissions } = useTranslation("permissions"); const { t: tNostr } = useTranslation("translation", { keyPrefix: "nostr", }); @@ -223,8 +223,9 @@ function SitePreferences({ launcherType, allowance, onEdit, onDelete }: Props) {
{permissions.map((permission) => ( - lnd.getinfo - nostr/nip04decrypt --> nostr.nip04decrypt */ - > - { - setPermissions( - permissions.map((prm) => - prm.id === permission.id - ? { ...prm, enabled: !prm.enabled } - : prm - ) - ); - }} - /> - + delete={() => { + setPermissions( + permissions.map((prm) => + prm.id === permission.id + ? { ...prm, enabled: !prm.enabled } + : prm + ) + ); + }} + className="bg-green-100 dark:bg-emerald-950 border border-green-100 dark:border-emerald-950 text-gray-800 dark:text-neutral-200 gap-1" + /> ))}
diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json index 8991da7e7d..8a805e1004 100644 --- a/src/i18n/locales/en/translation.json +++ b/src/i18n/locales/en/translation.json @@ -1193,7 +1193,6 @@ }, "nostr": { "getpublickey": "Read your public key", - "signmessage": "Sign message with your key", "nip04decrypt": "Decrypt data" }, "bitcoin": { From d1d64315fb2008745867983a26d1d01aaa7aefa6 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Thu, 14 Mar 2024 11:21:22 +0530 Subject: [PATCH 08/38] feat: prevent default form submission --- src/app/components/Badge/index.tsx | 39 +++++++++++++------- src/app/components/SitePreferences/index.tsx | 8 +++- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/app/components/Badge/index.tsx b/src/app/components/Badge/index.tsx index ff9fe5908f..01bbddeff6 100644 --- a/src/app/components/Badge/index.tsx +++ b/src/app/components/Badge/index.tsx @@ -1,4 +1,5 @@ import { CrossIcon } from "@bitcoin-design/bitcoin-icons-react/outline"; +import { useState } from "react"; import { useTranslation } from "react-i18next"; import { classNames } from "~/app/utils"; @@ -19,22 +20,32 @@ export default function Badge({ keyPrefix: "badge", }); + const [showBadge, setShowBadge] = useState(true); + return ( -
- {label ? tComponents(`label.${label}`) : sitePermission} - {deletePermission && ( - + {label ? tComponents(`label.${label}`) : sitePermission} + {deletePermission && ( + + )} +
)} -
+ ); } diff --git a/src/app/components/SitePreferences/index.tsx b/src/app/components/SitePreferences/index.tsx index 2a8c955f8c..5656a1a687 100644 --- a/src/app/components/SitePreferences/index.tsx +++ b/src/app/components/SitePreferences/index.tsx @@ -243,8 +243,12 @@ function SitePreferences({ launcherType, allowance, onEdit, onDelete }: Props) { .slice(-1) .toString(), } - ) - : permission.method.split("/").slice(0, 2).join("/") + ).toUpperCase() + : permission.method + .split("/") + .slice(0, 2) + .join("/") + .toUpperCase() } delete={() => { setPermissions( From 00724525f4a496eeadf35edca99a7409a1b63178 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Thu, 14 Mar 2024 12:28:56 +0530 Subject: [PATCH 09/38] fix: radio button styles --- src/app/components/PermissionModal/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/components/PermissionModal/index.tsx b/src/app/components/PermissionModal/index.tsx index 307af9ced6..c5993c39b6 100644 --- a/src/app/components/PermissionModal/index.tsx +++ b/src/app/components/PermissionModal/index.tsx @@ -87,6 +87,7 @@ export default function PermissionModal({ onChange={() => { setPermissionOption(checkedValue); }} + className="bg-white dark:bg-surface-01dp border border-gray-200 dark:border-neutral-700 cursor-pointer text-primary focus:ring-0 focus:ring-offset-0" />
diff --git a/src/app/screens/Nostr/ConfirmDecrypt.tsx b/src/app/screens/Nostr/ConfirmDecrypt.tsx index 40c947e7a6..7bc7cff766 100644 --- a/src/app/screens/Nostr/ConfirmDecrypt.tsx +++ b/src/app/screens/Nostr/ConfirmDecrypt.tsx @@ -68,7 +68,7 @@ function NostrConfirmDecrypt() {

{t("allow", { host: origin.host })}

- {tPermissions("nostr.nip04decrypt")} + {tPermissions("nostr.decrypt.description")}

diff --git a/src/app/screens/Nostr/ConfirmGetPublicKey.tsx b/src/app/screens/Nostr/ConfirmGetPublicKey.tsx index 5f7abf1234..785abe368c 100644 --- a/src/app/screens/Nostr/ConfirmGetPublicKey.tsx +++ b/src/app/screens/Nostr/ConfirmGetPublicKey.tsx @@ -68,7 +68,7 @@ function NostrConfirmGetPublicKey() {

- {tPermissions("nostr.getpublickey")} + {tPermissions("nostr.getpublickey.description")}

diff --git a/src/app/screens/Nostr/ConfirmSignMessage.tsx b/src/app/screens/Nostr/ConfirmSignMessage.tsx index de54e70d73..de282ce72f 100644 --- a/src/app/screens/Nostr/ConfirmSignMessage.tsx +++ b/src/app/screens/Nostr/ConfirmSignMessage.tsx @@ -100,7 +100,7 @@ function ConfirmSignMessage() { values={{ host: origin.host, kind: t(`kinds.${event.kind}`, { - defaultValue: t("kinds.unknown", { + defaultValue: t("kinds.unknown.title", { kind: event.kind, }), }), @@ -133,7 +133,7 @@ function ConfirmSignMessage() { setModalOpen(false); }} permission={t(`kinds.${event.kind}`, { - defaultValue: t("kinds.unknown", { + defaultValue: t("kinds.unknown.title", { kind: event.kind, }), })} @@ -154,7 +154,7 @@ function ConfirmSignMessage() { t={tPermissions} values={{ permission: t(`kinds.${event.kind}`, { - defaultValue: t("kinds.unknown", { + defaultValue: t("kinds.unknown.title", { kind: event.kind, }), }), diff --git a/src/extension/background-script/actions/webln/getBalanceOrPrompt.ts b/src/extension/background-script/actions/webln/getBalanceOrPrompt.ts index cd7987cbef..bc9c67d8ea 100644 --- a/src/extension/background-script/actions/webln/getBalanceOrPrompt.ts +++ b/src/extension/background-script/actions/webln/getBalanceOrPrompt.ts @@ -43,7 +43,7 @@ const getBalanceOrPrompt = async (message: MessageDefault) => { args: { requestPermission: { method: "getBalance", - description: `webln.getbalance`, + description: `webln.getbalance.description`, }, }, origin: message.origin, diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json index 5b119be993..afbff95dad 100644 --- a/src/i18n/locales/en/translation.json +++ b/src/i18n/locales/en/translation.json @@ -917,30 +917,96 @@ "block_added": "Added {{host}} to the blocklist, please reload the website.", "recipient": "Recipient", "kinds": { - "unknown": "kind {{kind}}", - "0": "metadata", - "1": "short text note", - "2": "recommend relay", - "3": "contacts", - "4": "encrypted direct messages", - "5": "event deletion", - "7": "reaction", - "8": "badge award", - "40": "channel creation", - "41": "channel metadata", - "42": "channel message", - "43": "channel hide message", - "44": "channel mute user", - "1984": "reporting", - "9734": "zap request", - "9735": "zap", - "10002": "relay list metadata", - "22242": "client authentication", - "24133": "nostr connect", - "30008": "profile badges", - "30009": "badge definition", - "30023": "long-form content", - "30078": "application-specific data" + "unknown": { "title": "kind {{kind}}", "description": "Unknown Kind" }, + "0": { + "title": "Profile", + "description": "Share your name, description, profile picture, Nostr address and additional profile metadata." + }, + "1": { "title": "Short note", "description": "Sign a short text note" }, + "2": { + "title": "Recommend relay", + "description": "Share a recommended relay" + }, + "3": { + "title": "Follow list", + "description": "Share a list of accounts you follow" + }, + "4": { + "title": "Direct message", + "description": "Send an encrypted direct message" + }, + "5": { + "title": "Event deletion", + "description": "Request relays to delete an event" + }, + "7": { + "title": "Reactions", + "description": "Sign a reaction to a note" + }, + "8": { + "title": "Badge award", + "description": "Award a badge to a Nostr profile" + }, + "40": { + "title": "Channel creation", + "description": "Create a public channel chat" + }, + "41": { + "title": "Update channel", + "description": "Update channel's name, description, picture and additional metadata" + }, + "42": { + "title": "Channel message", + "description": "Send a text message to a channel" + }, + "43": { + "title": "Channel hide message", + "description": "Hide a text message in a channel" + }, + "44": { + "title": "Channel mute user", + "description": "Hide all messages from a Nostr profile" + }, + "1984": { + "title": "Report note", + "description": "Report a note for spam, illegal or explicit content " + }, + "9734": { + "title": "Zap request", + "description": "Request a lightning payment" + }, + "9735": { + "title": "Zap recipt", + "description": "Display a confirmation of a paid lightning invoice" + }, + "10002": { + "title": "Relay list", + "description": "Share preferred relays for discovering your notes and receiving others' notes" + }, + "22242": { + "title": "Authenticate", + "description": "Authenticate to a relay" + }, + "24133": { + "title": "Remote signing", + "description": "Request and sign events remotely" + }, + "30008": { + "title": "Profile badges", + "description": "Accept, reject and change display order of awarded badges" + }, + "30009": { + "title": "Create badge", + "description": "Create a new badge" + }, + "30023": { + "title": "Long note", + "description": "Sign a long-form notes like articles or blog posts" + }, + "30078": { + "title": "App data", + "description": "Sign an application-specific data" + } } }, "transactions": { @@ -1170,21 +1236,36 @@ }, "permissions": { "webln": { - "getbalance": "Read the balance of your account" + "getbalance": { + "title": "Get Balance", + "description": "Read the balance of your account" + } }, "bitcoin": { - "getaddress": "Read your Bitcoin receive address" + "getaddress": { + "title": "Get Address", + "description": "Read your Bitcoin receive address" + } }, "liquid": { - "getaddress": "Read your Liquid receive address", - "signschnorr": "Sign message with your key" + "getaddress": { + "title": "Get Address", + "description": "Read your Liquid receive address" + }, + "signschnorr": { + "title": "Sign Schnorr", + "description": "Sign message with your key" + } }, "nostr": { - "getpublickey": "Read your public key", - "nip04encrypt": "Encrypt data", - "nip04decrypt": "Decrypt data", - "nip44encrypt": "Encrypt data", - "nip44decrypt": "Decrypt data" + "getpublickey": { + "title": "Read Public Key", + "description": "Read your public key" + }, + "decrypt": { + "title": "Decrypt Data", + "description": "Allow NIP04 Data Decryption" + } }, "commando": { "bkpr-listbalances": "List of all current and historical account balances", From 7859d86b536b92a1f07d89ddbc9739b01973e69c Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Fri, 15 Mar 2024 13:03:05 +0530 Subject: [PATCH 11/38] fix: tests, badge icon, translation keys --- src/app/components/Badge/index.tsx | 4 ++-- src/app/screens/Nostr/ConfirmSignMessage.tsx | 6 +++--- .../actions/ln/__tests__/getBalance.test.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app/components/Badge/index.tsx b/src/app/components/Badge/index.tsx index f8a891bdeb..b1fab4a83c 100644 --- a/src/app/components/Badge/index.tsx +++ b/src/app/components/Badge/index.tsx @@ -1,4 +1,4 @@ -import { CrossIcon } from "@bitcoin-design/bitcoin-icons-react/outline"; +import { PopiconsXLine } from "@popicons/react"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { classNames } from "~/app/utils"; @@ -44,7 +44,7 @@ export default function Badge({ }} className="text-gray-400 dark:text-neutral-600 hover:text-gray-600 dark:hover:text-neutral-400" > - + )} diff --git a/src/app/screens/Nostr/ConfirmSignMessage.tsx b/src/app/screens/Nostr/ConfirmSignMessage.tsx index de282ce72f..0f149b3f61 100644 --- a/src/app/screens/Nostr/ConfirmSignMessage.tsx +++ b/src/app/screens/Nostr/ConfirmSignMessage.tsx @@ -99,7 +99,7 @@ function ConfirmSignMessage() { t={t} values={{ host: origin.host, - kind: t(`kinds.${event.kind}`, { + kind: t(`kinds.${event.kind}.title`, { defaultValue: t("kinds.unknown.title", { kind: event.kind, }), @@ -132,7 +132,7 @@ function ConfirmSignMessage() { setPermissionOption(permission); setModalOpen(false); }} - permission={t(`kinds.${event.kind}`, { + permission={t(`kinds.${event.kind}.title`, { defaultValue: t("kinds.unknown.title", { kind: event.kind, }), @@ -153,7 +153,7 @@ function ConfirmSignMessage() { i18nKey={permissionOption} t={tPermissions} values={{ - permission: t(`kinds.${event.kind}`, { + permission: t(`kinds.${event.kind}.title`, { defaultValue: t("kinds.unknown.title", { kind: event.kind, }), diff --git a/src/extension/background-script/actions/ln/__tests__/getBalance.test.ts b/src/extension/background-script/actions/ln/__tests__/getBalance.test.ts index 9f9b37a1d3..a69d997bba 100644 --- a/src/extension/background-script/actions/ln/__tests__/getBalance.test.ts +++ b/src/extension/background-script/actions/ln/__tests__/getBalance.test.ts @@ -123,7 +123,7 @@ describe("prompts the user first and then calls getBalance", () => { args: { requestPermission: { method: "getBalance", - description: "webln.getbalance", + description: "webln.getbalance.description", }, }, origin: message.origin, @@ -147,7 +147,7 @@ describe("prompts the user first and then calls getBalance", () => { args: { requestPermission: { method: "getBalance", - description: "webln.getbalance", + description: "webln.getbalance.description", }, }, origin: message.origin, From 6821bc2eae544c40bcd869875f73355a1cde36b3 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Fri, 15 Mar 2024 14:37:08 +0530 Subject: [PATCH 12/38] feat: designs for site preferences --- src/app/components/Badge/index.tsx | 2 +- src/app/components/Modal/index.tsx | 2 +- src/app/components/SitePreferences/index.tsx | 181 ++++++++++--------- src/i18n/locales/en/translation.json | 4 +- 4 files changed, 100 insertions(+), 89 deletions(-) diff --git a/src/app/components/Badge/index.tsx b/src/app/components/Badge/index.tsx index b1fab4a83c..1fe75adcbb 100644 --- a/src/app/components/Badge/index.tsx +++ b/src/app/components/Badge/index.tsx @@ -29,7 +29,7 @@ export default function Badge({ {showBadge && (
{title && ( -

{title}

+

{title}

)}
diff --git a/src/app/screens/Nostr/ConfirmSignMessage.tsx b/src/app/screens/Nostr/ConfirmSignMessage.tsx index b719394869..673db1ff45 100644 --- a/src/app/screens/Nostr/ConfirmSignMessage.tsx +++ b/src/app/screens/Nostr/ConfirmSignMessage.tsx @@ -12,20 +12,10 @@ import PermissionModal from "~/app/components/PermissionModal"; import ScreenHeader from "~/app/components/ScreenHeader"; import toast from "~/app/components/Toast"; import { useNavigationState } from "~/app/hooks/useNavigationState"; -import { - ASK_EVERYTIME, - DONT_ASK_ANY, - DONT_ASK_CURRENT, - USER_REJECTED_ERROR, -} from "~/common/constants"; +import { USER_REJECTED_ERROR } from "~/common/constants"; import msg from "~/common/lib/msg"; import { Event } from "~/extension/providers/nostr/types"; -import type { OriginData } from "~/types"; - -type PermissionOption = - | typeof ASK_EVERYTIME - | typeof DONT_ASK_CURRENT - | typeof DONT_ASK_ANY; +import { OriginData, PermissionOption } from "~/types"; function ConfirmSignMessage() { const navState = useNavigationState(); @@ -45,8 +35,9 @@ function ConfirmSignMessage() { const [showJSON, setShowJSON] = useState(false); const [modalOpen, setModalOpen] = useState(false); - const [permissionOption, setPermissionOption] = - useState("ask_everytime"); + const [permissionOption, setPermissionOption] = useState( + PermissionOption.ASK_EVERYTIME + ); // TODO: refactor: the success message and loading will not be displayed because after the reply the prompt is closed. async function confirm() { @@ -136,7 +127,7 @@ function ConfirmSignMessage() { onClose={() => { setModalOpen(false); }} - permssionCallback={(permission) => { + permissionCallback={(permission) => { setPermissionOption(permission); setModalOpen(false); }} diff --git a/src/types.ts b/src/types.ts index 8e2737ebe5..dceae6c02b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -779,6 +779,12 @@ export interface Payment extends Omit { id: number; } +export enum PermissionOption { + ASK_EVERYTIME = "ask_everytime", + DONT_ASK_CURRENT = "dont_ask_current", + DONT_ASK_ANY = "dont_ask_any", +} + export enum PermissionMethodBitcoin { BITCOIN_GETADDRESS = "bitcoin/getAddress", } From 06424ae07ca8d5714a65fd324bb30c3b40d4eca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Wed, 20 Mar 2024 15:53:17 +0100 Subject: [PATCH 27/38] fix: remove badge hiding --- src/app/components/Badge/index.tsx | 44 +++--- src/app/components/SitePreferences/index.tsx | 137 ++++++++++--------- 2 files changed, 89 insertions(+), 92 deletions(-) diff --git a/src/app/components/Badge/index.tsx b/src/app/components/Badge/index.tsx index eb3d280ae5..277eb143b4 100644 --- a/src/app/components/Badge/index.tsx +++ b/src/app/components/Badge/index.tsx @@ -1,5 +1,4 @@ import { PopiconsXLine } from "@popicons/react"; -import { useState } from "react"; import { classNames } from "~/app/utils"; type Props = { @@ -15,33 +14,26 @@ export default function Badge({ onDelete, description, }: Props) { - const [showBadge, setShowBadge] = useState(true); - return ( - <> - {showBadge && ( -
+ {label.toUpperCase()} + {onDelete && ( + - )} -
+ + )} - + ); } diff --git a/src/app/components/SitePreferences/index.tsx b/src/app/components/SitePreferences/index.tsx index de05a42357..49a71ba19e 100644 --- a/src/app/components/SitePreferences/index.tsx +++ b/src/app/components/SitePreferences/index.tsx @@ -247,74 +247,79 @@ function SitePreferences({ launcherType, allowance, onEdit, onDelete }: Props) { {t("edit_allowance.always_allow")}

- {permissions.map((permission) => ( - - x.enabled) + .map((permission) => ( + + { + setPermissions( + permissions.map((prm) => + prm.id === permission.id + ? { ...prm, enabled: !prm.enabled } + : prm ) - } - onDelete={() => { - setPermissions( - permissions.map((prm) => - prm.id === permission.id - ? { ...prm, enabled: !prm.enabled } - : prm - ) - ); - }} - className="bg-green-100 dark:bg-emerald-950 border border-green-100 dark:border-emerald-950 text-gray-800 dark:text-neutral-200 gap-1" - /> - - ))} + ); + }} + className="bg-green-100 dark:bg-emerald-950 border border-green-100 dark:border-emerald-950 text-gray-800 dark:text-neutral-200 gap-1" + /> + + ))}
From d04f63e13c45b41a3e4a4205530f139adc8cde60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Wed, 20 Mar 2024 16:10:59 +0100 Subject: [PATCH 28/38] fix: simplify lang key construction --- src/app/components/SitePreferences/index.tsx | 125 +++++++++---------- 1 file changed, 57 insertions(+), 68 deletions(-) diff --git a/src/app/components/SitePreferences/index.tsx b/src/app/components/SitePreferences/index.tsx index 49a71ba19e..b1abcd5bb3 100644 --- a/src/app/components/SitePreferences/index.tsx +++ b/src/app/components/SitePreferences/index.tsx @@ -3,7 +3,7 @@ import Hyperlink from "@components/Hyperlink"; import Setting from "@components/Setting"; import Toggle from "@components/form/Toggle"; import type { FormEvent } from "react"; -import { Fragment, useEffect, useState } from "react"; +import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import toast from "~/app/components/Toast"; import { useAccount } from "~/app/context/AccountContext"; @@ -250,75 +250,64 @@ function SitePreferences({ launcherType, allowance, onEdit, onDelete }: Props) { {permissions .filter((x) => x.enabled) .map((permission) => ( - - { - setPermissions( - permissions.map((prm) => - prm.id === permission.id - ? { ...prm, enabled: !prm.enabled } - : prm + } + ) + : tPermissions( + getPermissionKey(permission).concat( + ".description" + ), + { + defaultValue: getPermissionKind(permission), + } ) - ); - }} - className="bg-green-100 dark:bg-emerald-950 border border-green-100 dark:border-emerald-950 text-gray-800 dark:text-neutral-200 gap-1" - /> - + } + onDelete={() => { + setPermissions( + permissions.map((prm) => + prm.id === permission.id + ? { ...prm, enabled: !prm.enabled } + : prm + ) + ); + }} + className="bg-green-100 dark:bg-emerald-950 border border-green-100 dark:border-emerald-950 text-gray-800 dark:text-neutral-200 gap-1" + /> ))} From c5e1cf051699b1fc0dc48d801c091285b96acd60 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Thu, 21 Mar 2024 11:43:34 +0530 Subject: [PATCH 29/38] fix: encrypt decrypt translations --- src/app/screens/Nostr/ConfirmDecrypt.tsx | 2 +- src/i18n/locales/en/translation.json | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/app/screens/Nostr/ConfirmDecrypt.tsx b/src/app/screens/Nostr/ConfirmDecrypt.tsx index 2fb44c3556..4567ddd6be 100644 --- a/src/app/screens/Nostr/ConfirmDecrypt.tsx +++ b/src/app/screens/Nostr/ConfirmDecrypt.tsx @@ -69,7 +69,7 @@ function NostrConfirmDecrypt() {

{t("allow", { host: origin.host })}

- {tPermissions("nostr.decrypt.description")} + {tPermissions("nostr.decrypt")}

diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json index 2b7fcdeb14..941af36cb8 100644 --- a/src/i18n/locales/en/translation.json +++ b/src/i18n/locales/en/translation.json @@ -1274,9 +1274,22 @@ "title": "read public key", "description": "Read your public key" }, - "decrypt": { - "title": "decrypt data", + "decrypt": "Decrypt data", + "nip04decrypt": { + "title": "nip04 decrypt", "description": "Decrypt data" + }, + "nip04encrypt": { + "title": "nip04 encrypt", + "description": "Encrypt Data" + }, + "nip44decrypt": { + "title": "nip44 decrypt", + "description": "Decrypt Data" + }, + "nip44encrypt": { + "title": "nip44 encrypt", + "description": "encrypt data" } }, "commando": { From 187d9975c8d75b4ca3ec89186b97bbba56ddee6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Thu, 21 Mar 2024 08:33:09 +0100 Subject: [PATCH 30/38] fix: simplify translation keys --- src/app/components/SitePreferences/index.tsx | 122 ++++++++++--------- 1 file changed, 65 insertions(+), 57 deletions(-) diff --git a/src/app/components/SitePreferences/index.tsx b/src/app/components/SitePreferences/index.tsx index b1abcd5bb3..3557ece761 100644 --- a/src/app/components/SitePreferences/index.tsx +++ b/src/app/components/SitePreferences/index.tsx @@ -122,7 +122,7 @@ function SitePreferences({ launcherType, allowance, onEdit, onDelete }: Props) { // returns actual permission kind (permission name) function getPermissionKind(permission: Permission): string { - return permission.method.split(/[./]/).slice(-1).toString(); + return permission.method.split("/").slice(-1).toString(); } //constructs i18n key for the permission translations @@ -250,64 +250,72 @@ function SitePreferences({ launcherType, allowance, onEdit, onDelete }: Props) { {permissions .filter((x) => x.enabled) .map((permission) => ( - + `${getPermissionKey(permission)}.title` + { + setPermissions( + permissions.map((prm) => + prm.id === permission.id + ? { ...prm, enabled: !prm.enabled } + : prm ) - } - onDelete={() => { - setPermissions( - permissions.map((prm) => - prm.id === permission.id - ? { ...prm, enabled: !prm.enabled } - : prm - ) - ); - }} - className="bg-green-100 dark:bg-emerald-950 border border-green-100 dark:border-emerald-950 text-gray-800 dark:text-neutral-200 gap-1" - /> + ); + }} + className="bg-green-100 dark:bg-emerald-950 border border-green-100 dark:border-emerald-950 text-gray-800 dark:text-neutral-200 gap-1" + /> + ))} From acb7fdcd2443eca720a100c6b794ecc605465ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Thu, 21 Mar 2024 09:08:46 +0100 Subject: [PATCH 31/38] fix: translations --- src/i18n/locales/en/translation.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json index 941af36cb8..59a2b580c8 100644 --- a/src/i18n/locales/en/translation.json +++ b/src/i18n/locales/en/translation.json @@ -927,8 +927,8 @@ "description": "Unidentified action" }, "0": { - "title": "share profile", - "description": "Share your name, description, profile picture, Nostr address and additional profile metadata." + "title": "update profile", + "description": "Update your name, description, profile picture, Nostr address and additional profile metadata." }, "1": { "title": "short note", @@ -939,8 +939,8 @@ "description": "Share a recommended relay" }, "3": { - "title": "share follow list", - "description": "Share a list of accounts you follow" + "title": "update follow list", + "description": "Update the list of accounts you follow" }, "4": { "title": "direct message", @@ -987,12 +987,12 @@ "description": "Request a lightning payment" }, "9735": { - "title": "share zap receipt", + "title": "zap receipt", "description": "Display a confirmation of a paid lightning invoice" }, "10002": { - "title": "share relay list", - "description": "Share preferred relays for discovering your notes and receiving others' notes" + "title": "relay list", + "description": "Update preferred relays for discovering your notes and receiving others' notes" }, "22242": { "title": "authenticate", From c611501aede82deb8fb0f297ff98039b2c441ded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Thu, 21 Mar 2024 09:10:40 +0100 Subject: [PATCH 32/38] fix: remove debugging --- src/app/components/SitePreferences/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/components/SitePreferences/index.tsx b/src/app/components/SitePreferences/index.tsx index 3557ece761..5a9bdd1505 100644 --- a/src/app/components/SitePreferences/index.tsx +++ b/src/app/components/SitePreferences/index.tsx @@ -251,7 +251,6 @@ function SitePreferences({ launcherType, allowance, onEdit, onDelete }: Props) { .filter((x) => x.enabled) .map((permission) => ( <> - `${getPermissionKey(permission)}.title` Date: Thu, 21 Mar 2024 09:13:26 +0100 Subject: [PATCH 33/38] fix: translations --- src/i18n/locales/en/translation.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json index 59a2b580c8..781df84807 100644 --- a/src/i18n/locales/en/translation.json +++ b/src/i18n/locales/en/translation.json @@ -1289,7 +1289,7 @@ }, "nip44encrypt": { "title": "nip44 encrypt", - "description": "encrypt data" + "description": "Encrypt data" } }, "commando": { From bc66f48e68139a92728fb5c3b5858ac0daa882ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Thu, 21 Mar 2024 09:13:56 +0100 Subject: [PATCH 34/38] fix: revert splitting --- src/app/components/SitePreferences/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/SitePreferences/index.tsx b/src/app/components/SitePreferences/index.tsx index 5a9bdd1505..fe8c260242 100644 --- a/src/app/components/SitePreferences/index.tsx +++ b/src/app/components/SitePreferences/index.tsx @@ -122,7 +122,7 @@ function SitePreferences({ launcherType, allowance, onEdit, onDelete }: Props) { // returns actual permission kind (permission name) function getPermissionKind(permission: Permission): string { - return permission.method.split("/").slice(-1).toString(); + return permission.method.split(/[./]/).slice(-1).toString(); } //constructs i18n key for the permission translations From fedf461297f7b3b67cf1b8456e2644829992e248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Thu, 21 Mar 2024 10:12:07 +0100 Subject: [PATCH 35/38] fix: add margin --- src/app/components/PermissionModal/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/PermissionModal/index.tsx b/src/app/components/PermissionModal/index.tsx index 207a515fc4..792fc0878d 100644 --- a/src/app/components/PermissionModal/index.tsx +++ b/src/app/components/PermissionModal/index.tsx @@ -58,7 +58,7 @@ export default function PermissionModal({ -
+