import { useState, useEffect, Fragment } from 'react'; import { Button, Card, CardContent, Dialog, DialogActions, DialogContent, DialogTitle, Stack, Typography } from '@mui/material'; import { useNavigate, useParams } from 'react-router'; import { Identity } from '@hyper-hyper-space/core'; import { Contacts } from '@hyper-hyper-space/home'; function NoHomeDialog(props: {onClose?: () => void}) { const [open, setOpen] = useState(true); const navigate = useNavigate(); const close = () => { setOpen(false); if (props.onClose !== undefined) { props.onClose(); } } const { next } = useParams() as { next: string}; const destination = next.split('/')[0]; let [message, setMessage] = useState(); let [valid, setValid] = useState(); useEffect(() => { const init = async () => { if (destination === 'add-contact') { let id: Identity; try { const rawId = decodeURIComponent(next.split('/')[1]); console.log(rawId); const identity = await Contacts.importIdentity(JSON.parse(rawId)); setValid(true); setMessage('You are about to add ' + identity.info?.name + ' as a contact in Hyper Hyper Space. You need to initialize your Home space first!'); } catch (e) { setValid(false); setMessage('The contact in the link you followed invalid, sorry. Please check that the link was not modified.'); } } else { setValid(false); setMessage('You received an invalid link, sorry.'); } }; init(); }, []); return { (valid === undefined || message === undefined) && Loading... } { !(valid === undefined || message === undefined) && Welcome to Hyper Hyper Space! {message} {valid && } } } export default NoHomeDialog;