import { Stack, Typography } from '@mui/material' import { GetStartedButton, LearnMoreButton } from './styled' import { DOMAIN } from '@/utils/consts' import { useSearchParams } from 'react-router-dom' import { swicCall } from '@/modules/swic' import { useEnqueueSnackbar } from '@/hooks/useEnqueueSnackbar' import { ModalConfirmConnect } from '@/components/Modal/ModalConfirmConnect/ModalConfirmConnect' import { useModalSearchParams } from '@/hooks/useModalSearchParams' import { MODAL_PARAMS_KEYS } from '@/types/modal' import { useState } from 'react' import { getReferrerAppUrl } from '@/utils/helpers/helpers' import { LoadingSpinner } from '@/shared/LoadingSpinner/LoadingSpinner' const CreatePage = () => { const notify = useEnqueueSnackbar() const { handleOpen } = useModalSearchParams() const [created, setCreated] = useState(false) const [searchParams] = useSearchParams() const [isLoading, setIsLoading] = useState(false) const name = searchParams.get('name') || '' const token = searchParams.get('token') || '' const appNpub = searchParams.get('appNpub') || '' const isValid = name && token && appNpub const nip05 = `${name}@${DOMAIN}` const handleLearnMore = () => { // @ts-ignore window.open(`https://${DOMAIN}`, '_blank').focus() } const handleClickAddAccount = async () => { try { setIsLoading(true) const key: any = await swicCall('generateKey', name) const appUrl = getReferrerAppUrl() console.log('Created', key.npub, 'app', appUrl) setCreated(true) setIsLoading(false) handleOpen(MODAL_PARAMS_KEYS.CONFIRM_CONNECT, { search: { npub: key.npub, appNpub, appUrl, token, // needed for this screen itself name, // will close after all done popup: 'true', }, replace: true, }) } catch (error: any) { notify(error.message || error.toString(), 'error') setIsLoading(false) } } if (!isValid) { return ( Bad parameters. ) } return ( <> {created && ( <> Account created! User name: {nip05} )} {!created && ( <> Welcome to Nostr! Chosen name: {nip05} Create account {isLoading && } What you need to know:
  1. Nostr accounts are based on cryptographic keys.
  2. All your actions on Nostr will be signed by your keys.
  3. Nsec.app is one of many services to manage Nostr keys.
  4. When you create an account, a new key will be created.
  5. This key can later be used with other Nostr websites.
Learn more
)}
) } export default CreatePage