import { PowerCircleIcon } from "lucide-react"; import React, { ChangeEvent, useState } from "react"; import { useNavigate } from "react-router"; import Loading from "src/components/Loading"; import PasswordInput from "src/components/password/PasswordInput"; import TwoColumnLayoutHeader from "src/components/TwoColumnLayoutHeader"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "src/components/ui/alert-dialog"; import { LoadingButton } from "src/components/ui/custom/loading-button"; import { Input } from "src/components/ui/input"; import { Label } from "src/components/ui/label"; import { useInfo } from "src/hooks/useInfo"; import { handleRequestError } from "src/utils/handleRequestError"; import { isHttpMode } from "src/utils/isHttpMode"; import { request } from "src/utils/request"; export function RestoreNode() { const navigate = useNavigate(); const [unlockPassword, setUnlockPassword] = useState(""); const [file, setFile] = useState(null); const [showAlert, setShowAlert] = useState(false); const [loading, setLoading] = useState(false); const [restored, setRestored] = useState(false); const { data: info } = useInfo(restored); const _isHttpMode = isHttpMode(); React.useEffect(() => { if (restored && info?.setupCompleted) { navigate("/"); } }, [info?.setupCompleted, navigate, restored]); if (restored) { return (

If you're running in a cloud VM or linux service, your Alby Hub will restart automatically. Otherwise, please manually restart your Alby Hub to finish the restore process.

Waiting for restart...

); } const onSubmit = (e: React.FormEvent) => { e.preventDefault(); setShowAlert(true); }; const restoreNode = async () => { try { setLoading(true); if (_isHttpMode) { const formData = new FormData(); formData.append("unlockPassword", unlockPassword); if (file !== null) { formData.append("backup", file); } await request("/api/restore", { method: "POST", body: formData, }); } else { await request("/api/restore", { method: "POST", body: JSON.stringify({ unlockPassword, }), }); } setRestored(true); } catch (error) { handleRequestError("Failed to restore backup", error); } finally { setShowAlert(false); setLoading(false); } }; const handleChangeFile = (e: ChangeEvent) => { const files = e.currentTarget.files; if (files) { setFile(files[0]); } }; return (
{_isHttpMode && (
)} Import Wallet Restore Node from Migration File

As part of the node restore process your Alby Hub will be shut down.

If you're running in a cloud VM or linux service, your Alby Hub will restart automatically. Otherwise, please manually restart your Alby Hub to finish the restore process.

setShowAlert(false)}> Cancel Continue
); }