Skip to content

Commit

Permalink
Merge pull request #2095 from getAlby/task-account-error
Browse files Browse the repository at this point in the history
fix: show toast if nostr key is malformed
  • Loading branch information
bumi authored Feb 10, 2023
2 parents 896bd4a + 0937f2a commit 13b8148
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/app/screens/Accounts/Show/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,24 @@ function AccountScreen() {
}, [fetchData, isLoadingSettings]);

useEffect(() => {
setNostrPublicKey(
currentPrivateKey ? generatePublicKey(currentPrivateKey) : ""
);
setNostrPrivateKey(
currentPrivateKey ? nostrlib.hexToNip19(currentPrivateKey, "nsec") : ""
);
}, [currentPrivateKey]);
try {
setNostrPublicKey(
currentPrivateKey ? generatePublicKey(currentPrivateKey) : ""
);
setNostrPrivateKey(
currentPrivateKey ? nostrlib.hexToNip19(currentPrivateKey, "nsec") : ""
);
} catch (e) {
if (e instanceof Error)
toast.error(
<p>
{t("nostr.errors.failed_to_load")}
<br />
{e.message}
</p>
);
}
}, [currentPrivateKey, t]);

return !account ? (
<div className="flex justify-center mt-5">
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 13b8148

Please sign in to comment.