Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow console.log #648

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
065894f
Add a topic field to account for non zero topics
Baleba Dec 5, 2023
b27881f
caniuse-lite from"1.0.30001352"to"1.0.30001566"
Baleba Dec 5, 2023
333dbc6
add text input for topic
Baleba Dec 5, 2023
9f768c6
add topic and bool for to extend topic feed use
Baleba Dec 5, 2023
1cc4c74
add website bool old and new topic use
Baleba Dec 5, 2023
52a0e88
add website and topic
Baleba Dec 5, 2023
645c923
Set feedtype control locally
Baleba Dec 8, 2023
5ec2e6a
Add Array based display of Postes, no data con yet
Baleba Dec 8, 2023
8864e5a
Limited impact on the code remove website bool
Baleba Dec 8, 2023
6fdc68b
Add screen to display posts from the feed when topic is not website.
Baleba Dec 13, 2023
8a39846
Add screen for data input in the case of feed with topic different fr…
Baleba Dec 13, 2023
ce15ece
Add button for managing Posting data.
Baleba Dec 13, 2023
5b0ca5f
Define post type and post array to be used in feed details.
Baleba Dec 13, 2023
30024c3
Add mode POST for upload origin.
Baleba Dec 13, 2023
0841679
change updateFeed to account for POST update.
Baleba Dec 13, 2023
6d9bc55
Create a dropdown list dynamically for identities to choose between.
Baleba Dec 15, 2023
92cd718
Changes related to choosing an Id for feed creation and update.
Baleba Dec 15, 2023
df49445
Update to display posts for a given feed.
Baleba Dec 15, 2023
836aacf
Adding a form to insert json objects as posts.
Baleba Dec 15, 2023
94643a8
Add a button in the upload options to include non website feeds updates.
Baleba Dec 15, 2023
7abdb46
Add some shared data in the Id contexte
Baleba Dec 15, 2023
fb1f82e
Add readFeed function to extract older posts from non website feeds.
Baleba Dec 15, 2023
0099e2a
allow console.log
Baleba Dec 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"linebreak-style": ["warn", "unix"],
"no-alert": "error",
"no-case-declarations": "error",
"no-console": "error",
//"no-console": "error",
"no-constant-condition": "error",
"no-continue": "warn",
"no-div-regex": "error",
Expand Down
16 changes: 10 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 59 additions & 3 deletions src/pages/account/feeds/AccountFeeds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import ExpandableListItem from '../../../components/ExpandableListItem'
import ExpandableListItemActions from '../../../components/ExpandableListItemActions'
import ExpandableListItemKey from '../../../components/ExpandableListItemKey'
import { SwarmButton } from '../../../components/SwarmButton'
import { Context as IdentityContext, Identity } from '../../../providers/Feeds'
import { SwarmTextInput } from '../../../components/SwarmTextInput'
import { Post, Context as IdentityContext, Identity } from '../../../providers/Feeds'
import { ROUTES } from '../../../routes'
import { formatEnum } from '../../../utils'
import { persistIdentitiesWithoutUpdate } from '../../../utils/identity'
Expand All @@ -21,9 +22,13 @@ import { AccountNavigation } from '../AccountNavigation'
import { Header } from '../Header'
import TroubleshootConnectionCard from '../../../components/TroubleshootConnectionCard'
import { CheckState, Context as BeeContext } from '../../../providers/Bee'
import { dropDownOption } from '../../../providers/Feeds'
import { Context as SettingsContext } from '../../../providers/Settings'
import { readFeed } from '../../../utils/identity'

export function AccountFeeds(): ReactElement {
const { identities, setIdentities } = useContext(IdentityContext)
const { identities, setIdentities, setDDOptions, isLoadingPosts, setisLoadingPosts, Posts, setPostsList } =
useContext(IdentityContext)
const { status } = useContext(BeeContext)

const navigate = useNavigate()
Expand All @@ -32,15 +37,50 @@ export function AccountFeeds(): ReactElement {
const [showImport, setShowImport] = useState(false)
const [showExport, setShowExport] = useState(false)
const [showDelete, setShowDelete] = useState(false)
const { beeApi, beeDebugApi } = useContext(SettingsContext)
const [pwd, setPasswd] = useState('')

function createNewFeed() {
const oa: dropDownOption[] = [{ label: 'Create a new', value: 'New' }]
const oa1 = new Set()

identities.map((x, i) => {
if (!oa1.has(x.name)) {
oa1.add(x.name)
oa.push({ label: x.name, value: x.name })
}

return oa1
})

setDDOptions(oa)

return navigate(ROUTES.ACCOUNT_FEEDS_NEW)
}

function viewFeed(uuid: string) {
const identity = identities.find(x => x.uuid === uuid)

if (identity?.topic !== '' && beeApi) {
try {
console.log('ID', identity)
readFeed(beeApi, beeDebugApi, identity as Identity, pwd).then(Posts => {
console.log('Success', Posts)
setPostsList(Posts)
setisLoadingPosts(false)
})
} catch {
console.log('Failure')
setPostsList([])
}
}
navigate(ROUTES.ACCOUNT_FEEDS_VIEW.replace(':uuid', uuid))
}

const onChangePassword = (event: React.ChangeEvent<HTMLInputElement>) => {
setPasswd(event.target.value)
}

function onDialogClose() {
setShowDelete(false)
setShowExport(false)
Expand Down Expand Up @@ -98,7 +138,23 @@ export function AccountFeeds(): ReactElement {
<ExpandableListItem label="Identity type" value={formatEnum(x.type)} />
</ExpandableList>
</Box>
<ExpandableListItemKey label="Topic" value={'00'.repeat(32)} />
<Box>
{x.type === 'V3' && (
<SwarmTextInput
name="password"
label="Password"
password
onChange={e => {
setPasswd(e.target.value)
}}
/>
)}
</Box>
{x.topic === '00' ? (
<ExpandableListItemKey label="Website Topic" value={'00'.repeat(32)} />
) : (
<SwarmTextInput name="Topic" label={x.topic} />
)}
{x.feedHash && <ExpandableListItemKey label="Feed hash" value={x.feedHash} />}
<Box mt={0.75}>
<ExpandableListItemActions>
Expand Down
109 changes: 88 additions & 21 deletions src/pages/feeds/CreateNewFeed.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Grid, Typography } from '@material-ui/core'
import { Box, Grid, Typography, Checkbox } from '@material-ui/core'
import { Form, Formik } from 'formik'
import { useSnackbar } from 'notistack'
import { ReactElement, useContext, useState } from 'react'
Expand All @@ -12,30 +12,47 @@ 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 FeedsContext, Identity, IdentityType } from '../../providers/Feeds'
import { Context as SettingsContext } from '../../providers/Settings'
import { ROUTES } from '../../routes'
import { convertWalletToIdentity, generateWallet, persistIdentity } from '../../utils/identity'
import { convertWalletToIdentity, generateWallet, persistIdentity, getWalletFromIdentity } from '../../utils/identity'
import { Wallet } from 'ethers'
import * as React from 'react'
import FormControlLabel from '@material-ui/core/FormControlLabel'

interface FormValues {
identityName?: string
type?: IdentityType
website: boolean
topic: string
password?: string
}

const initialValues: FormValues = {
identityName: '',
type: 'PRIVATE_KEY',
type: 'V3',
password: '',
website: false,
topic: '00',
}

export default function CreateNewFeed(): ReactElement {
const { beeApi, beeDebugApi } = useContext(SettingsContext)
const { identities, setIdentities } = useContext(FeedsContext)
const { identities, setIdentities, optionsArray } = useContext(FeedsContext)
const [loading, setLoading] = useState(false)
const [website, setFeedType] = useState(true)
const { enqueueSnackbar } = useSnackbar()

const navigate = useNavigate()
const [checked, setChecked] = React.useState(true)
const [checkedpk, setCheckedk] = React.useState(true)

const handleChangeNewId = (event: React.ChangeEvent<HTMLInputElement>) => {
setChecked(event.target.checked)
}

const handleChangeV3oPk = (event: React.ChangeEvent<HTMLInputElement>) => {
setCheckedk(event.target.checked)
}

async function onSubmit(values: FormValues) {
setLoading(true)
Expand All @@ -46,7 +63,17 @@ export default function CreateNewFeed(): ReactElement {

return
}
const wallet = generateWallet()
let wallet: Wallet

if (values.identityName === 'New') {
wallet = generateWallet()
} else {
const identity = identities.find(x => x.name === values.identityName)
{
identity ? (wallet = await getWalletFromIdentity(identity, values.password)) : (wallet = generateWallet())
}
}

const stamps = await beeDebugApi?.getAllPostageBatch()

if (!stamps || !stamps.length) {
Expand All @@ -63,17 +90,28 @@ export default function CreateNewFeed(): ReactElement {
return
}

const identity = await convertWalletToIdentity(wallet, values.type, values.identityName, values.password)
const identity = await convertWalletToIdentity(
wallet,
values.type,
values.identityName,
values.topic,
values.password,
)
persistIdentity(identities, identity)
setIdentities(identities)
navigate(ROUTES.ACCOUNT_FEEDS)
setLoading(false)
enqueueSnackbar(<span>Done saving new ID</span>, { variant: 'error' })
}

function cancel() {
navigate(-1)
}

function setTopic() {
setFeedType(false)
}

return (
<div>
<HistoryHeader>Create new feed</HistoryHeader>
Expand All @@ -94,36 +132,65 @@ export default function CreateNewFeed(): ReactElement {
{({ submitForm, values }) => (
<Form>
<Box mb={0.25}>
<SwarmTextInput name="identityName" label="Identity name" formik />
</Box>
<Box mb={0.25}>
<SwarmSelect
formik
name="type"
options={[
{ label: 'Keypair Only', value: 'PRIVATE_KEY' },
{ label: 'Password Protected', value: 'V3' },
]}
/>
{checked ? (
<SwarmTextInput name="identityName" label="Identity name" formik />
) : (
<SwarmSelect formik name="identityName" label="Identity name" options={optionsArray} />
)}
</Box>
<SwarmSelect
formik
name="Type"
options={[
{ label: 'V3', value: 'V3' },
{ label: 'PRIVATE_KEY', value: 'PRIVATE_KEY' },
]}
/>
{values.type === 'V3' && <SwarmTextInput name="password" label="Password" password formik />}
<Box mt={2}>
<ExpandableListItemKey label="Topic" value={'00'.repeat(32)} />
{website ? (
<ExpandableListItemKey label="topic" value={'00'.repeat(32)} />
) : (
<SwarmTextInput name="topic" label="Specify Feed Topic" formik />
)}
</Box>
<Box mt={2} sx={{ bgcolor: '#fcf2e8' }} p={2}>
<Grid container justifyContent="space-between">
<Typography>Feeds name</Typography>
<Typography>{values.identityName} Website</Typography>
<Typography>{values.identityName}</Typography>
</Grid>
</Box>
<Box mt={1.25}>
<ExpandableListItemActions>
<SwarmButton onClick={submitForm} iconType={Check} disabled={loading} loading={loading}>
Create Feed
</SwarmButton>
<SwarmButton onClick={setTopic} iconType={Check} disabled={loading} loading={loading}>
Feed
</SwarmButton>
<SwarmButton onClick={cancel} iconType={X} disabled={loading} cancel>
Cancel
</SwarmButton>
<FormControlLabel
label="Create a new ID"
control={
<Checkbox
checked={checked}
onChange={handleChangeNewId}
inputProps={{ 'aria-label': 'controlled' }}
/>
}
/>
<FormControlLabel
label="V3 or Privatk"
control={
<Checkbox
checked={checked}
onChange={handleChangeV3oPk}
inputProps={{ 'aria-label': 'controlled' }}
/>
}
/>
</ExpandableListItemActions>
</Box>
</Form>
Expand Down
Loading