Skip to content

Commit 608ec8b

Browse files
feat: refactor nip-04 screens (#2897)
* feat: refactor nip-04 screens * feat: change encrypt and decrypt screens correct namings translations signed-off-by: pavan joshi <[email protected]> * fix: ui * fix: add new translation * feat: refactor nostr confirm to nostrEncryptOrDecrypt * fix: hosts are already part of the screen, make message more generic * fix: remove defaultValue * fix: translation keys & more * fix: cleanup * fix: openPrompt args * fix: allow_sign_event translation * fix: translation for unknown kinds * fix: remove outdated translations * fix: remove no_content message --------- Co-authored-by: René Aaron <[email protected]> Co-authored-by: René Aaron <[email protected]>
1 parent 46f0a32 commit 608ec8b

18 files changed

+81
-70
lines changed

src/app/router/Prompt/Prompt.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import LNURLWithdraw from "@screens/LNURLWithdraw";
1111
import LiquidConfirmGetAddress from "@screens/Liquid/ConfirmGetAddress";
1212
import ConfirmSignPset from "@screens/Liquid/ConfirmSignPset";
1313
import MakeInvoice from "@screens/MakeInvoice";
14-
import NostrConfirm from "@screens/Nostr/Confirm";
1514
import NostrConfirmGetPublicKey from "@screens/Nostr/ConfirmGetPublicKey";
1615
import NostrConfirmSignMessage from "@screens/Nostr/ConfirmSignMessage";
1716
import NostrConfirmSignSchnorr from "@screens/Nostr/ConfirmSignSchnorr";
@@ -29,6 +28,7 @@ import LiquidEnable from "~/app/screens/Enable/LiquidEnable";
2928
import NostrEnable from "~/app/screens/Enable/NostrEnable";
3029
import WebbtcEnable from "~/app/screens/Enable/WebbtcEnable";
3130
import WeblnEnable from "~/app/screens/Enable/WeblnEnable";
31+
import NostrConfirmEncryptOrDecrypt from "~/app/screens/Nostr/ConfirmEncryptOrDecrypt";
3232
import type { NavigationState, OriginData } from "~/types";
3333

3434
// Parse out the parameters from the querystring.
@@ -123,7 +123,10 @@ function Prompt() {
123123
path="public/liquid/confirmSignPset"
124124
element={<ConfirmSignPset />}
125125
/>
126-
<Route path="public/nostr/confirm" element={<NostrConfirm />} />
126+
<Route
127+
path="public/nostr/confirmEncryptOrDecrypt"
128+
element={<NostrConfirmEncryptOrDecrypt />}
129+
/>
127130
<Route
128131
path="public/nostr/confirmGetPublicKey"
129132
element={<NostrConfirmGetPublicKey />}

src/app/screens/Nostr/Confirm.tsx renamed to src/app/screens/Nostr/ConfirmEncryptOrDecrypt.tsx

+34-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
1-
import { CheckIcon } from "@bitcoin-design/bitcoin-icons-react/filled";
21
import ConfirmOrCancel from "@components/ConfirmOrCancel";
32
import Container from "@components/Container";
43
import PublisherCard from "@components/PublisherCard";
54
import { useState } from "react";
65
import { useTranslation } from "react-i18next";
6+
import ContentMessage from "~/app/components/ContentMessage";
7+
import Hyperlink from "~/app/components/Hyperlink";
78
import ScreenHeader from "~/app/components/ScreenHeader";
89
import Checkbox from "~/app/components/form/Checkbox";
910
import { useNavigationState } from "~/app/hooks/useNavigationState";
1011
import { USER_REJECTED_ERROR } from "~/common/constants";
1112
import msg from "~/common/lib/msg";
1213
import { OriginData } from "~/types";
1314

14-
function NostrConfirm() {
15+
function NostrConfirmEncryptOrDecrypt() {
1516
const { t } = useTranslation("translation", {
1617
keyPrefix: "nostr",
1718
});
1819
const { t: tCommon } = useTranslation("common");
1920
const navState = useNavigationState();
2021
const origin = navState.origin as OriginData;
21-
const description = navState.args?.description;
22-
const details = navState.args?.details;
22+
const action = navState.args?.encryptOrDecrypt?.action;
23+
const peer = navState.args?.encryptOrDecrypt?.peer;
24+
const message = navState.args?.encryptOrDecrypt?.message;
25+
2326
const [loading, setLoading] = useState(false);
27+
const [showDetails, setShowDetails] = useState(false);
28+
2429
const [rememberPermission, setRememberPermission] = useState(true);
2530

2631
function confirm() {
@@ -47,6 +52,10 @@ function NostrConfirm() {
4752
msg.error(USER_REJECTED_ERROR);
4853
}
4954

55+
function toggleShowDetails() {
56+
setShowDetails((current) => !current);
57+
}
58+
5059
function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
5160
event.preventDefault();
5261
confirm();
@@ -62,21 +71,29 @@ function NostrConfirm() {
6271
title={origin.name}
6372
image={origin.icon}
6473
url={origin.host}
65-
isSmall={false}
74+
isSmall={true}
6675
/>
67-
<div className="dark:text-white pt-6 mb-4">
68-
<p className="mb-2">{t("allow", { host: origin.host })}</p>
69-
<p className="dark:text-white">
70-
<CheckIcon className="w-5 h-5 mr-2 inline" />
71-
{description}
72-
{details && (
73-
<>
74-
<br />
75-
<i className="ml-7">{details}</i>
76-
</>
76+
{message && (
77+
<ContentMessage
78+
heading={t(
79+
action == "encrypt" ? "allow_encrypt" : "allow_decrypt",
80+
{
81+
host: origin.host,
82+
}
7783
)}
78-
</p>
84+
content={message}
85+
/>
86+
)}
87+
<div className="flex justify-center mb-4 gap-4">
88+
<Hyperlink onClick={toggleShowDetails}>
89+
{showDetails ? t("hide_details") : t("view_details")}
90+
</Hyperlink>
7991
</div>
92+
{showDetails && (
93+
<div className="whitespace-pre-wrap break-words p-2 mb-4 shadow bg-white rounded-lg dark:bg-surface-02dp text-gray-500 dark:text-gray-400">
94+
{t("peer")}: {peer}
95+
</div>
96+
)}
8097
</div>
8198
<div className="text-center flex flex-col">
8299
<div className="flex items-center mb-4">
@@ -115,4 +132,4 @@ function NostrConfirm() {
115132
);
116133
}
117134

118-
export default NostrConfirm;
135+
export default NostrConfirmEncryptOrDecrypt;

src/app/screens/Nostr/ConfirmSignMessage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function ConfirmSignMessage() {
9090
defaultValue: t("kinds.unknown", { kind: event.kind }),
9191
}),
9292
})}
93-
content={event.content || t("no_content")}
93+
content={event.content || ""}
9494
/>
9595
<div className="flex justify-center mb-4 gap-4">
9696
<Hyperlink onClick={toggleShowJSON}>

src/extension/background-script/actions/nostr/decryptOrPrompt.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
hasPermissionFor,
77
} from "~/extension/background-script/permissions";
88
import state from "~/extension/background-script/state";
9-
import i18n from "~/i18n/i18nConfig";
109
import { MessageDecryptGet, PermissionMethodNostr, Sender } from "~/types";
1110

1211
const decryptOrPrompt = async (message: MessageDecryptGet, sender: Sender) => {
@@ -33,9 +32,13 @@ const decryptOrPrompt = async (message: MessageDecryptGet, sender: Sender) => {
3332
rememberPermission: boolean;
3433
}>({
3534
...message,
36-
action: "public/nostr/confirm",
35+
action: "public/nostr/confirmEncryptOrDecrypt",
3736
args: {
38-
description: i18n.t("permissions:nostr.nip04decrypt"),
37+
encryptOrDecrypt: {
38+
action: "decrypt",
39+
peer: message.args.peer,
40+
message: message.args.ciphertext,
41+
},
3942
},
4043
});
4144

src/extension/background-script/actions/nostr/encryptOrPrompt.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
hasPermissionFor,
77
} from "~/extension/background-script/permissions";
88
import state from "~/extension/background-script/state";
9-
import i18n from "~/i18n/i18nConfig";
109
import { MessageEncryptGet, PermissionMethodNostr, Sender } from "~/types";
1110

1211
const encryptOrPrompt = async (message: MessageEncryptGet, sender: Sender) => {
@@ -24,17 +23,20 @@ const encryptOrPrompt = async (message: MessageEncryptGet, sender: Sender) => {
2423
message.args.peer,
2524
message.args.plaintext
2625
);
27-
2826
return { data: response };
2927
} else {
3028
const promptResponse = await utils.openPrompt<{
3129
confirm: boolean;
3230
rememberPermission: boolean;
3331
}>({
3432
...message,
35-
action: "public/nostr/confirm",
33+
action: "public/nostr/confirmEncryptOrDecrypt",
3634
args: {
37-
description: i18n.t("permissions:nostr.nip04encrypt"),
35+
encryptOrDecrypt: {
36+
action: "encrypt",
37+
peer: message.args.peer,
38+
message: message.args.plaintext,
39+
},
3840
},
3941
});
4042

src/i18n/locales/de/translation.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,8 @@
627627
"30008": "Profilabzeichen",
628628
"30009": "Badge Beschreibung",
629629
"30023": "Langform Inhalte",
630-
"30078": "anwendungsspezifische Daten",
631-
"unknown": "nostr Ereignis der Art {{kind}}"
632-
},
633-
"allow_sign_event": "Erlaube {{host}}, eine {{kind}} zu unterzeichnen:"
630+
"30078": "anwendungsspezifische Daten"
631+
}
634632
},
635633
"confirm_request_permission": {
636634
"title": "Antrag genehmigen",

src/i18n/locales/en/translation.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -894,14 +894,16 @@
894894
"allow": "Allow this website to:",
895895
"content": "This website asks you to sign:",
896896
"allow_sign": "Allow {{host}} to sign:",
897-
"allow_sign_event": "Allow {{host}} to sign a {{kind}}:",
897+
"allow_sign_event": "Allow {{host}} to sign a {{kind}} event",
898+
"allow_encrypt": "Allow {{host}} to encrypt the message:",
899+
"allow_decrypt": "Allow {{host}} to decrypt the message:",
898900
"view_details": "View details",
899901
"hide_details": "Hide details",
900-
"no_content": "(No content)",
901902
"block_and_ignore": "Block and ignore {{host}}",
902903
"block_added": "Added {{host}} to the blocklist, please reload the website.",
904+
"peer": "Peer",
903905
"kinds": {
904-
"unknown": "nostr event of kind {{kind}}",
906+
"unknown": "kind {{kind}}",
905907
"0": "metadata",
906908
"1": "short text note",
907909
"2": "recommend relay",
@@ -1148,9 +1150,9 @@
11481150
},
11491151
"nostr": {
11501152
"getpublickey": "Read your public key",
1153+
"signmessage": "Sign message with your key",
11511154
"nip04encrypt": "Encrypt data",
1152-
"nip04decrypt": "Decrypt data",
1153-
"signmessage": "Sign message with your key"
1155+
"nip04decrypt": "Decrypt data"
11541156
},
11551157
"bitcoin": {
11561158
"getaddress": "Read your Bitcoin receive address"

src/i18n/locales/es/translation.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@
553553
"allow_sign": "Permitir que {{host}} firme:",
554554
"block_and_ignore": "Bloquear e ignorar {{host}}",
555555
"block_added": "Se agregó {{host}} a la lista de bloqueados, vuelva a cargar el sitio web.",
556-
"allow_sign_event": "Permitir que {{host}} firme un {{kind}}:",
557556
"view_details": "Más información",
558557
"hide_details": "Ocultar los detalles",
559558
"no_content": "(Sin contenido)",
@@ -580,8 +579,7 @@
580579
"30008": "distintivos del perfil",
581580
"30009": "definición del distintivo",
582581
"30023": "contenidos largos",
583-
"30078": "datos específicos de la aplicación",
584-
"unknown": "nostr evento del tipo {{kind}}"
582+
"30078": "datos específicos de la aplicación"
585583
}
586584
},
587585
"discover": {

src/i18n/locales/fa/translation.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,6 @@
724724
"allow": "به این وبسایت اجازه دهید که:",
725725
"content": "این وبسایت از شما می خواهد که امضا کنید:",
726726
"allow_sign": "به {{host}} اجاره امضا بدهید:",
727-
"allow_sign_event": "به {{host}} اجازه امضای {{kind}} را بده:",
728727
"view_details": "مشاهده جزییات",
729728
"hide_details": "پنهان کردن جزییات",
730729
"no_content": "(بدون محتوا)",
@@ -753,8 +752,7 @@
753752
"30008": "مدال های نمایه",
754753
"30009": "تعریف مدال",
755754
"30023": "محتوای طولانی",
756-
"30078": "داده ویژه اپلیکیشن",
757-
"unknown": "رویداد ناستر از نوع {{kind}}"
755+
"30078": "داده ویژه اپلیکیشن"
758756
}
759757
},
760758
"transactions": {

src/i18n/locales/hi/translation.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,6 @@
504504
"allow": "इस वेबसाइट को इसकी अनुमति दें:",
505505
"content": "यह वेबसाइट आपसे हस्ताक्षर करने के लिए कहती है:",
506506
"allow_sign": "{{host}} को हस्ताक्षर करने की अनुमति दें:",
507-
"allow_sign_event": "{{host}} को {{kind}} पर हस्ताक्षर करने की अनुमति दें:",
508507
"view_details": "विवरण देखें",
509508
"hide_details": "विवरण छिपाएं",
510509
"no_content": "(कोई सामग्री नहीं)",
@@ -533,8 +532,7 @@
533532
"30008": "प्रोफ़ाइल बैज",
534533
"30009": "बैज परिभाषा",
535534
"30023": "लंबी सामग्री",
536-
"30078": "एप्लिकेशन-विशिष्ट डेटा",
537-
"unknown": "Nostr तरह की कोई घटना {{kind}}"
535+
"30078": "एप्लिकेशन-विशिष्ट डेटा"
538536
}
539537
},
540538
"transactions": {

src/i18n/locales/mr/translation.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@
582582
"allow": "या वेबसाइटला परवानगी द्या:",
583583
"content": "ही वेबसाइट तुम्हाला स्वाक्षरी करण्यास सांगते:",
584584
"allow_sign": "{{host}} ला स्वाक्षरी करण्याची परवानगी द्या:",
585-
"allow_sign_event": "{{host}} ला {{kind}} वर स्वाक्षरी करण्याची परवानगी द्या:",
586585
"view_details": "तपशील पहा",
587586
"hide_details": "तपशील लपवा",
588587
"no_content": "(कोणतीही सामग्री नाही)",
@@ -611,8 +610,7 @@
611610
"30008": "profile बॅज",
612611
"30009": "बिल्ला व्याख्या",
613612
"30023": "दीर्घ स्वरूपाची सामग्री",
614-
"30078": "अनुप्रयोग-विशिष्ट डेटा",
615-
"unknown": "nostr event of kind {{kind}}"
613+
"30078": "अनुप्रयोग-विशिष्ट डेटा"
616614
}
617615
},
618616
"transactions": {

src/i18n/locales/pl/translation.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,8 @@
629629
"30008": "odznaki profile",
630630
"30009": "definicja odznaki",
631631
"30023": "treść długiego formatu",
632-
"30078": "dane specyficzne dla aplikacji",
633-
"unknown": "zdarzenia nostr typu {{kind}}"
632+
"30078": "dane specyficzne dla aplikacji"
634633
},
635-
"allow_sign_event": "Pozwól {{host}} na podpisywanie {{kind}}:",
636634
"view_details": "Pokaż szczegóły"
637635
},
638636
"transactions": {

src/i18n/locales/pt_BR/translation.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,6 @@
661661
"block_added": "{{host}} adicionado na lista de bloqueio, por favor recarregue o site.",
662662
"allow_sign": "Permitir {{host}} assinar:",
663663
"view_details": "Ver detalhes",
664-
"allow_sign_event": "Permitir {{host}} assinar {{kind}}:",
665664
"hide_details": "Ocultar detalhes",
666665
"kinds": {
667666
"0": "metadados",
@@ -670,8 +669,7 @@
670669
"4": "mensagens diretas criptografadas",
671670
"5": "exclusão de evento",
672671
"7": "reação",
673-
"9735": "zap",
674-
"unknown": "evento nostr do tipo {{kind}}"
672+
"9735": "zap"
675673
},
676674
"no_content": "(Sem conteúdo)"
677675
},

src/i18n/locales/sv/translation.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -684,13 +684,11 @@
684684
"30008": "profil badges",
685685
"30009": "badge definition",
686686
"30023": "långformigt innehåll",
687-
"30078": "applikationsspecifika data",
688-
"unknown": "nostr event av sort {{kind}}"
687+
"30078": "applikationsspecifika data"
689688
},
690689
"view_details": "Visa detaljer",
691690
"hide_details": "Göm detaljer",
692691
"block_added": "Lade till {{host}} till blockeringslistan, ladda om webbplatsen.",
693-
"allow_sign_event": "Tillåt {{host}} att signera en {{kind}}:",
694692
"no_content": "(Inget innehåll)",
695693
"allow_sign": "Tillåt {{host}} att signera:",
696694
"content": "Den här webbplatsen ber dig att signera:"

src/i18n/locales/th/translation.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,7 @@
425425
"30008": "โปรไฟล์เหรียญตรา",
426426
"30009": "คำจำกัดความของเหรียญตรา",
427427
"30023": "เนื้อหาแบบยาว",
428-
"30078": "ข้อมูลเฉพาะแอปพลิเคชัน",
429-
"unknown": "ประเภทของ nostr event {{kind}}"
428+
"30078": "ข้อมูลเฉพาะแอปพลิเคชัน"
430429
},
431430
"title": "Nostr",
432431
"block_added": "เพื่ม {{host}} เข้าสู่แบล็คลิส โปรดรีเฟรชหน้าเว็บใหม่",
@@ -435,8 +434,7 @@
435434
"view_details": "ดูรายละเอียด",
436435
"hide_details": "ซ่อนรายละเอียด",
437436
"no_content": "(ไม่มีเนื้อหา)",
438-
"allow_sign": "อนุญาตให้ {{host}} ลงนาม:",
439-
"allow_sign_event": "อนุญาตให้ {{host}} ลงนามใน {{kind}}:"
437+
"allow_sign": "อนุญาตให้ {{host}} ลงนาม:"
440438
},
441439
"choose_path": {
442440
"other": {

src/i18n/locales/zh_Hans/translation.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,6 @@
600600
"content": "该网站要求你签署:",
601601
"allow_sign": "允许{{host}}签署:",
602602
"block_added": "已将{{host}}添加到屏蔽列表,请重新加载网站。",
603-
"allow_sign_event": "允许 {{host}} 签署 {{kind}}:",
604603
"view_details": "查看详情",
605604
"hide_details": "隐藏详情",
606605
"no_content": "(无内容)",
@@ -627,8 +626,7 @@
627626
"30008": "个人资料徽章",
628627
"30009": "徽章定义",
629628
"30023": "长篇内容",
630-
"30078": "应用程序特定数据",
631-
"unknown": "nostr 事件类型 {{kind}}"
629+
"30078": "应用程序特定数据"
632630
}
633631
},
634632
"lnurlpay": {

0 commit comments

Comments
 (0)