import { Box, Grid, Typography } from '@material-ui/core' import { Form, Formik } from 'formik' import { useSnackbar } from 'notistack' import { ReactElement, useContext, useState } from 'react' import Check from 'remixicon-react/CheckLineIcon' import X from 'remixicon-react/CloseLineIcon' import { useNavigate } from 'react-router' import { DocumentationText } from '../../components/DocumentationText' import ExpandableListItemActions from '../../components/ExpandableListItemActions' import ExpandableListItemKey from '../../components/ExpandableListItemKey' import { HistoryHeader } from '../../components/HistoryHeader' import { SwarmButton } from '../../components/SwarmButton' import { SwarmSelect } from '../../components/SwarmSelect' import { SwarmTextInput } from '../../components/SwarmTextInput' import { Context as FeedsContext, IdentityType } from '../../providers/Feeds' import { Context as SettingsContext } from '../../providers/Settings' import { ROUTES } from '../../routes' import { convertWalletToIdentity, generateWallet, persistIdentity } from '../../utils/identity' interface FormValues { identityName?: string type?: IdentityType password?: string } const initialValues: FormValues = { identityName: '', type: 'PRIVATE_KEY', password: '', } export default function CreateNewFeed(): ReactElement { const { beeApi, beeDebugApi } = useContext(SettingsContext) const { identities, setIdentities } = useContext(FeedsContext) const [loading, setLoading] = useState(false) const { enqueueSnackbar } = useSnackbar() const navigate = useNavigate() async function onSubmit(values: FormValues) { setLoading(true) if (!beeApi) { enqueueSnackbar(Bee API unavailabe, { variant: 'error' }) setLoading(false) return } const wallet = generateWallet() const stamps = await beeDebugApi?.getAllPostageBatch() if (!stamps || !stamps.length) { enqueueSnackbar(No stamp available, { variant: 'error' }) setLoading(false) return } if (!values.identityName || !values.type) { enqueueSnackbar(Form is unfinished, { variant: 'error' }) setLoading(false) return } const identity = await convertWalletToIdentity(wallet, values.type, values.identityName, values.password) persistIdentity(identities, identity) setIdentities(identities) navigate(ROUTES.ACCOUNT_FEEDS) setLoading(false) } function cancel() { navigate(-1) } return (
Create new feed To create a feed you will need to create an identity. Please refer to the{' '} official Bee documentation {' '} to understand how feeds work. {({ submitForm, values }) => (
{values.type === 'V3' && } Feeds name {values.identityName} Website Create Feed Cancel )}
) }