diff --git a/src/app/error.tsx b/src/app/error.tsx index 42722f38..b3505668 100644 --- a/src/app/error.tsx +++ b/src/app/error.tsx @@ -1,85 +1,138 @@ -import { useEffect, useState } from 'react'; -import { useLocation, useRouteError } from 'react-router-dom'; +import { downloadDir } from '@tauri-apps/api/path'; +import { message, save } from '@tauri-apps/plugin-dialog'; +import { writeTextFile } from '@tauri-apps/plugin-fs'; +import { relaunch } from '@tauri-apps/plugin-process'; +import { useRouteError } from 'react-router-dom'; + +import { useStorage } from '@libs/storage/provider'; interface RouteError { statusText: string; message: string; } -interface DebugInfo { - os: null | string; - appDir: null | string; -} - export function ErrorScreen() { + const { db } = useStorage(); const error = useRouteError() as RouteError; - const location = useLocation(); - const [debugInfo, setDebugInfo] = useState({ - os: null, - appDir: null, - }); + const restart = async () => { + await relaunch(); + }; - useEffect(() => { - async function getInformation() { - const { platform, version } = await import('@tauri-apps/plugin-os'); - const { appConfigDir } = await import('@tauri-apps/api/path'); - - const platformName = await platform(); - const osVersion = await version(); - const appDir = await appConfigDir(); - - setDebugInfo({ - os: platformName + ' ' + osVersion, - appDir: appDir, + const download = async () => { + try { + const downloadPath = await downloadDir(); + const fileName = `nostr_keys_${new Date().toISOString()}.txt`; + const filePath = await save({ + defaultPath: downloadPath + '/' + fileName, }); - } + const nsec = await db.secureLoad(db.account.pubkey); - getInformation(); - }, []); + if (filePath) { + if (nsec) { + await writeTextFile( + filePath, + `Nostr account, generated by Lume (lume.nu)\nPublic key: ${db.account.id}\nPrivate key: ${nsec}` + ); + } else { + await writeTextFile( + filePath, + `Nostr account, generated by Lume (lume.nu)\nPublic key: ${db.account.id}` + ); + } + } // else { user cancel action } + } catch (e) { + await message(e, { title: 'Cannot download account keys', type: 'error' }); + } + }; return ( -
-
+
+
-

+

Sorry, an unexpected error has occurred.

-
-

- {error.statusText || error.message} -

-
-
-

- Current location: {location.pathname} -

-

- Platform: {debugInfo.os} -

-
+

+ Don't be panic, your account is safe. +
+ Here are what things you can do: +

-
- - Click here to report the issue on GitHub - - - +
+
+
+ 1. Try close and re-open app +
+ +
+
+
+ 2. Backup Nostr account +
+ +
+
+
+
+
+ 3. Report this issue to Lume's Devs +
+ + Report + +
+
+

+ {error.statusText || error.message} +

+
+
+
+
+
+
+ 4. Use other Nostr client +
+
+

+ While waiting Lume's Devs release the bug fixes, you always can use + other Nostr client with your account: +

+ +
+
+