From 09ab5361c42e23b39bbea1be75430ee5a1e22920 Mon Sep 17 00:00:00 2001 From: Adithya Vardhan Date: Fri, 10 Feb 2023 14:12:14 +0530 Subject: [PATCH 1/2] fix: show toast if nostr key is malformed --- src/app/screens/Accounts/Show/index.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/app/screens/Accounts/Show/index.tsx b/src/app/screens/Accounts/Show/index.tsx index 9ca86c7a27..307df5b301 100644 --- a/src/app/screens/Accounts/Show/index.tsx +++ b/src/app/screens/Accounts/Show/index.tsx @@ -231,12 +231,16 @@ function AccountScreen() { }, [fetchData, isLoadingSettings]); useEffect(() => { - setNostrPublicKey( - currentPrivateKey ? generatePublicKey(currentPrivateKey) : "" - ); - setNostrPrivateKey( - currentPrivateKey ? nostrlib.hexToNip19(currentPrivateKey, "nsec") : "" - ); + try { + setNostrPublicKey( + currentPrivateKey ? generatePublicKey(currentPrivateKey) : "" + ); + setNostrPrivateKey( + currentPrivateKey ? nostrlib.hexToNip19(currentPrivateKey, "nsec") : "" + ); + } catch (e) { + if (e instanceof Error) toast.error(e.message); + } }, [currentPrivateKey]); return !account ? ( From 0937f2a16650854a6223505c565c98a1159b55b2 Mon Sep 17 00:00:00 2001 From: Adithya Vardhan Date: Fri, 10 Feb 2023 14:34:44 +0530 Subject: [PATCH 2/2] chore: modify error message --- src/app/screens/Accounts/Show/index.tsx | 11 +++++++++-- src/i18n/locales/en/translation.json | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/app/screens/Accounts/Show/index.tsx b/src/app/screens/Accounts/Show/index.tsx index 307df5b301..1e6c6679b4 100644 --- a/src/app/screens/Accounts/Show/index.tsx +++ b/src/app/screens/Accounts/Show/index.tsx @@ -239,9 +239,16 @@ function AccountScreen() { currentPrivateKey ? nostrlib.hexToNip19(currentPrivateKey, "nsec") : "" ); } catch (e) { - if (e instanceof Error) toast.error(e.message); + if (e instanceof Error) + toast.error( +

+ {t("nostr.errors.failed_to_load")} +
+ {e.message} +

+ ); } - }, [currentPrivateKey]); + }, [currentPrivateKey, t]); return !account ? (
diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json index 9fac8b461f..0b520d50ff 100644 --- a/src/i18n/locales/en/translation.json +++ b/src/i18n/locales/en/translation.json @@ -417,6 +417,9 @@ }, "actions": { "generate": "Generate a new key" + }, + "errors": { + "failed_to_load": "Failed to load the Nostr key. Is it a valid Nostr key?" } }, "remove": {