diff --git a/.eslintrc b/.eslintrc index 5a7969bf..93406f24 100644 --- a/.eslintrc +++ b/.eslintrc @@ -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", diff --git a/package-lock.json b/package-lock.json index b5f99e8b..b7b3557f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6996,9 +6996,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001352", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001352.tgz", - "integrity": "sha512-GUgH8w6YergqPQDGWhJGt8GDRnY0L/iJVQcU3eJ46GYf52R8tk0Wxp0PymuFVZboJYXGiCqwozAYZNRjVj6IcA==", + "version": "1.0.30001566", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001566.tgz", + "integrity": "sha512-ggIhCsTxmITBAMmK8yZjEhCO5/47jKXPu6Dha/wuCS4JePVL+3uiDEBuhu2aIoT+bqTOR8L76Ip1ARL9xYsEJA==", "dev": true, "funding": [ { @@ -7008,6 +7008,10 @@ { "type": "tidelift", "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" } ] }, @@ -25628,9 +25632,9 @@ } }, "caniuse-lite": { - "version": "1.0.30001352", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001352.tgz", - "integrity": "sha512-GUgH8w6YergqPQDGWhJGt8GDRnY0L/iJVQcU3eJ46GYf52R8tk0Wxp0PymuFVZboJYXGiCqwozAYZNRjVj6IcA==", + "version": "1.0.30001566", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001566.tgz", + "integrity": "sha512-ggIhCsTxmITBAMmK8yZjEhCO5/47jKXPu6Dha/wuCS4JePVL+3uiDEBuhu2aIoT+bqTOR8L76Ip1ARL9xYsEJA==", "dev": true }, "case-sensitive-paths-webpack-plugin": { diff --git a/src/pages/account/feeds/AccountFeeds.tsx b/src/pages/account/feeds/AccountFeeds.tsx index 22cc6c48..e1fd4705 100644 --- a/src/pages/account/feeds/AccountFeeds.tsx +++ b/src/pages/account/feeds/AccountFeeds.tsx @@ -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' @@ -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() @@ -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) => { + setPasswd(event.target.value) + } + function onDialogClose() { setShowDelete(false) setShowExport(false) @@ -98,7 +138,23 @@ export function AccountFeeds(): ReactElement { - + + {x.type === 'V3' && ( + { + setPasswd(e.target.value) + }} + /> + )} + + {x.topic === '00' ? ( + + ) : ( + + )} {x.feedHash && } diff --git a/src/pages/feeds/CreateNewFeed.tsx b/src/pages/feeds/CreateNewFeed.tsx index fdd8f1a4..fae5462a 100644 --- a/src/pages/feeds/CreateNewFeed.tsx +++ b/src/pages/feeds/CreateNewFeed.tsx @@ -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' @@ -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) => { + setChecked(event.target.checked) + } + + const handleChangeV3oPk = (event: React.ChangeEvent) => { + setCheckedk(event.target.checked) + } async function onSubmit(values: FormValues) { setLoading(true) @@ -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) { @@ -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(Done saving new ID, { variant: 'error' }) } function cancel() { navigate(-1) } + function setTopic() { + setFeedType(false) + } + return (
Create new feed @@ -94,26 +132,32 @@ export default function CreateNewFeed(): ReactElement { {({ submitForm, values }) => (
- - - - + {checked ? ( + + ) : ( + + )} + {values.type === 'V3' && } - + {website ? ( + + ) : ( + + )} Feeds name - {values.identityName} Website + {values.identityName} @@ -121,9 +165,32 @@ export default function CreateNewFeed(): ReactElement { Create Feed + + Feed + Cancel + + } + /> + + } + /> diff --git a/src/pages/feeds/FeedSubpage.tsx b/src/pages/feeds/FeedSubpage.tsx index 37702484..2294a135 100644 --- a/src/pages/feeds/FeedSubpage.tsx +++ b/src/pages/feeds/FeedSubpage.tsx @@ -5,26 +5,44 @@ import X from 'remixicon-react/CloseLineIcon' import { DocumentationText } from '../../components/DocumentationText' import ExpandableListItemActions from '../../components/ExpandableListItemActions' import ExpandableListItemKey from '../../components/ExpandableListItemKey' +import ExpandableList from '../../components/ExpandableList' +import ExpandableListItem from '../../components/ExpandableListItem' import { HistoryHeader } from '../../components/HistoryHeader' import { SwarmButton } from '../../components/SwarmButton' import { Context as BeeContext } from '../../providers/Bee' -import { Context as IdentityContext } from '../../providers/Feeds' +import { Identity, Post, Context as IdentityContext } from '../../providers/Feeds' import { Context as SettingsContext } from '../../providers/Settings' import { ROUTES } from '../../routes' import { UploadArea } from '../files/UploadArea' +const msg: Post = { + Title: 'PS5', + Type: 'Document', + Category: 'Loisir', + Date: '07/12/2023', + Amount: '750€', + Provider: 'Sony', + Place: 'La Defense', + reference: '', +} + export function FeedSubpage(): ReactElement { - const { identities } = useContext(IdentityContext) + const { identities, isLoadingPosts, setisLoadingPosts, Posts, setPostsList } = useContext(IdentityContext) const { uuid } = useParams() - const { beeApi } = useContext(SettingsContext) + const { beeApi, beeDebugApi } = useContext(SettingsContext) const { status } = useContext(BeeContext) - const navigate = useNavigate() const [available, setAvailable] = useState(false) const identity = identities.find(x => x.uuid === uuid) + function onClose() { + setPostsList([]) + setisLoadingPosts(true) + navigate(ROUTES.ACCOUNT_FEEDS) + } + useEffect(() => { if (!identity || !identity.feedHash) { return @@ -43,14 +61,14 @@ export function FeedSubpage(): ReactElement { return <> } - function onClose() { - navigate(ROUTES.ACCOUNT_FEEDS) - } - return (
- {`${identity.name} Website`} - + {`${identity.topic}`} + {identity.topic === '' ? ( + + ) : ( + + )} {available && identity.feedHash ? ( <> @@ -72,6 +90,23 @@ export function FeedSubpage(): ReactElement { )} + + + {isLoadingPosts ? ( + + ) : ( + Posts.map((x, i) => ( + + + + + + + + )) + )} + + Close diff --git a/src/pages/files/Upload.tsx b/src/pages/files/Upload.tsx index 16a1594e..1e8e3fed 100644 --- a/src/pages/files/Upload.tsx +++ b/src/pages/files/Upload.tsx @@ -1,4 +1,9 @@ -import { Box } from '@material-ui/core' +import { Box, Button } from '@material-ui/core' +import { Form, Formik, FormikProvider } from 'formik' +import { SwarmSelect } from '../../components/SwarmSelect' +import { SwarmTextInput } from '../../components/SwarmTextInput' +import { SwarmButton } from '../../components/SwarmButton' +import ExpandableListItemActions from '../../components/ExpandableListItemActions' import { useSnackbar } from 'notistack' import { ReactElement, useContext, useEffect, useState } from 'react' import { useNavigate } from 'react-router-dom' @@ -8,7 +13,7 @@ import { ProgressIndicator } from '../../components/ProgressIndicator' import TroubleshootConnectionCard from '../../components/TroubleshootConnectionCard' import { META_FILE_NAME, PREVIEW_FILE_NAME } from '../../constants' import { Context as BeeContext, CheckState } from '../../providers/Bee' -import { Identity, Context as IdentityContext } from '../../providers/Feeds' +import { Identity, Post, Context as IdentityContext } from '../../providers/Feeds' import { Context as FileContext } from '../../providers/File' import { Context as SettingsContext } from '../../providers/Settings' import { EnrichedPostageBatch, Context as StampsContext } from '../../providers/Stamps' @@ -23,6 +28,7 @@ import { PostageStampSelector } from '../stamps/PostageStampSelector' import { AssetPreview } from './AssetPreview' import { StampPreview } from './StampPreview' import { UploadActionBar } from './UploadActionBar' +import Check from 'remixicon-react/CheckLineIcon' export function Upload(): ReactElement { const [step, setStep] = useState(0) @@ -34,13 +40,23 @@ export function Upload(): ReactElement { const { stamps, refresh } = useContext(StampsContext) const { beeApi, beeDebugApi } = useContext(SettingsContext) const { files, setFiles, uploadOrigin, metadata, previewUri, previewBlob } = useContext(FileContext) - const { identities, setIdentities } = useContext(IdentityContext) const { status } = useContext(BeeContext) + const { identities, setIdentities, PostData, setPostData } = useContext(IdentityContext) const { enqueueSnackbar } = useSnackbar() const navigate = useNavigate() const hasAnyStamps = stamps !== null && stamps.length > 0 + const msg: Post = { + Title: 'PS5', + Type: 'Document', + Category: 'Loisir', + Date: '07/12/2023', + Amount: '750€', + Provider: 'Sony', + Place: 'La Defense', + reference: '', + } useEffect(() => { refresh() @@ -122,7 +138,6 @@ export function Upload(): ReactElement { }) fls.push(packageFile(previewFile)) } - setUploading(true) if (beeDebugApi) { @@ -133,17 +148,26 @@ export function Upload(): ReactElement { .uploadFiles(stamp.batchID, fls, { indexDocument, deferred: true }) .then(hash => { putHistory(HISTORY_KEYS.UPLOAD_HISTORY, hash.reference, getAssetNameFromFiles(files)) + // Load data in the Json/object + PostData.reference = hash.reference if (uploadOrigin.origin === 'UPLOAD') { navigate(ROUTES.HASH.replace(':hash', hash.reference), { replace: true }) } else { - updateFeed(beeApi, beeDebugApi, identity as Identity, hash.reference, stamp.batchID, password as string).then( - () => { - persistIdentity(identities, identity as Identity) - setIdentities([...identities]) - navigate(ROUTES.ACCOUNT_FEEDS_VIEW.replace(':uuid', uploadOrigin.uuid as string), { replace: true }) - }, - ) + updateFeed( + beeApi, + beeDebugApi, + identity as Identity, + hash.reference, + stamp.batchID, + password as string, + PostData as Post, + uploadOrigin.origin, + ).then(() => { + persistIdentity(identities, identity as Identity) + setIdentities([...identities]) + navigate(ROUTES.ACCOUNT_FEEDS_VIEW.replace(':uuid', uploadOrigin.uuid as string), { replace: true }) + }) } }) .catch(e => { @@ -164,6 +188,11 @@ export function Upload(): ReactElement { uploadFiles(password) } + function onSubmit(values: Post) { + console.log(values) + setPostData(values) + } + return ( <> {showPasswordPrompt && ( @@ -205,6 +234,61 @@ export function Upload(): ReactElement { )} {step === 2 && stamp && } + {uploadOrigin.origin === 'POST' && ( + + {({ submitForm, values }) => ( +
+ + + + + + + + + + + + + + + + + + + + + + + + + + Save Feed Data + + + +
+ )} +
+ )} document.querySelector('.MuiDropzoneArea-root input') as HTMLInputElement @@ -80,6 +83,15 @@ export function UploadArea({ uploadOrigin, showHelp }: Props): ReactElement { setStrictWebsiteMode(false) } + const onUploadPostDataClick = () => { + onUploadCollectionClick() + setStrictPostMode(false) + } + + const onNewPostClick = () => { + navigate(ROUTES.UPLOAD_IN_PROGRESS) // Create a Post Form + } + const onUploadFileClick = () => { const element = getDropzoneInputDomElement() @@ -98,6 +110,12 @@ export function UploadArea({ uploadOrigin, showHelp }: Props): ReactElement { }, 0) } + const resetComponentOnConfirmNoData = () => { + setTimeout(() => { + setNoData(true) + }, 0) + } + const handleChange = (files?: File[]) => { if (files) { const FilePaths = files as FilePath[] @@ -112,6 +130,18 @@ export function UploadArea({ uploadOrigin, showHelp }: Props): ReactElement { return } + if (files.length && strictPostMode) { + enqueueSnackbar( + 'To create a new Post you may need to upload some data first, please confirm you have no data to attach to your post!', + { + variant: 'error', + }, + ) + resetComponentOnConfirmNoData() + + return + } + setFiles(FilePaths) if (files.length) { @@ -142,6 +172,9 @@ export function UploadArea({ uploadOrigin, showHelp }: Props): ReactElement { Add Website + + New Post +
{showHelp && ( diff --git a/src/providers/Feeds.tsx b/src/providers/Feeds.tsx index d0e5e717..196c3d59 100644 --- a/src/providers/Feeds.tsx +++ b/src/providers/Feeds.tsx @@ -5,20 +5,71 @@ export type IdentityType = 'V3' | 'PRIVATE_KEY' export interface Identity { uuid: string name: string + website: boolean + topic: string feedHash?: string identity: string address: string type: IdentityType } +export interface Post { + Title: string + Type: string + Category: string + Date: string + Amount: string + Provider: string + Place: string + reference: string +} + +export interface dropDownOption { + label: string + value: string +} + +const msg: Post = { + Title: '', + Type: 'Expenditure', + Category: 'Groceries', + Date: '11/12/2023', + Amount: '0€', + Provider: 'Africa', + Place: 'Mbeng', + reference: '', +} + interface ContextInterface { identities: Identity[] setIdentities: (identities: Identity[]) => void + optionsArray: dropDownOption[] + setDDOptions: (optionsArray: dropDownOption[]) => void + isLoadingPosts: boolean + setisLoadingPosts: (isLoadingPosts: boolean) => void + Posts: Post[] + setPostsList: (Posts: Post[]) => void + PostData: Post + setPostData: (PostData: Post) => void } const initialValues: ContextInterface = { identities: [], setIdentities: () => {}, // eslint-disable-line + optionsArray: [], + setDDOptions: () => {}, // eslint-disable-line + isLoadingPosts: true, + setisLoadingPosts: () => { + return true + }, + Posts: [], + setPostsList: () => { + return [] + }, + PostData: msg, + setPostData: () => { + return msg + }, } export const Context = createContext(initialValues) @@ -30,14 +81,38 @@ interface Props { export function Provider({ children }: Props): ReactElement { const [identities, setIdentities] = useState(initialValues.identities) + const [optionsArray, setDDOptions] = useState(initialValues.optionsArray) + const [isLoadingPosts, setisLoadingPosts] = useState(initialValues.isLoadingPosts) + const [Posts, setPostsList] = useState(initialValues.Posts) + const [PostData, setPostData] = useState(initialValues.PostData) useEffect(() => { + const oa: dropDownOption[] = [] try { setIdentities(JSON.parse(localStorage.getItem('feeds') || '[]')) + identities.map((x, i) => oa.push({ label: x.name, value: x.name })) + setDDOptions(oa) } catch { setIdentities([]) } }, []) // eslint-disable-line react-hooks/exhaustive-deps - return {children} + return ( + + {children} + + ) } diff --git a/src/providers/File.tsx b/src/providers/File.tsx index 54a0c679..d6d6bc7d 100644 --- a/src/providers/File.tsx +++ b/src/providers/File.tsx @@ -5,7 +5,7 @@ import { getMetadata } from '../utils/file' import { resize } from '../utils/image' import { PREVIEW_DIMENSIONS } from '../constants' -export type UploadOrigin = { origin: 'UPLOAD' | 'FEED'; uuid?: string } +export type UploadOrigin = { origin: 'UPLOAD' | 'FEED' | 'POST'; uuid?: string } export const defaultUploadOrigin: UploadOrigin = { origin: 'UPLOAD' } diff --git a/src/utils/identity.ts b/src/utils/identity.ts index ccfa403c..d9866e97 100644 --- a/src/utils/identity.ts +++ b/src/utils/identity.ts @@ -1,8 +1,9 @@ import { BatchId, Bee, BeeDebug, Reference } from '@ethersphere/bee-js' import { Wallet } from 'ethers' import { uuidV4, waitUntilStampUsable } from '.' -import { Identity, IdentityType } from '../providers/Feeds' - +import { Identity, IdentityType, Post } from '../providers/Feeds' +import { FeedUploadOptions } from '@ethersphere/bee-js/dist/types/feed' +import { FileUploadOptions } from '@ethersphere/bee-js' export function generateWallet(): Wallet { return Wallet.createRandom() } @@ -25,6 +26,7 @@ export async function convertWalletToIdentity( identity: Wallet, type: IdentityType, name: string, + topic: string, password?: string, ): Promise { if (type === 'V3' && !password) { @@ -37,6 +39,8 @@ export async function convertWalletToIdentity( uuid: uuidV4(), name, type: password ? 'V3' : 'PRIVATE_KEY', + topic: topic, + website: true, address: identity.address, identity: identityString, } @@ -50,6 +54,8 @@ export async function importIdentity(name: string, data: string): Promise { +export function getWalletFromIdentity(identity: Identity, password?: string): Promise { return getWallet(identity.type, identity.identity, password) } @@ -84,17 +98,93 @@ export async function updateFeed( hash: string, stamp: string, password?: string, + msg?: Post, + uporigin?: string, ): Promise { const wallet = await getWalletFromIdentity(identity, password) + let hexTopic = '0x0' + + if (uporigin === 'POST') { + hexTopic = beeApi.makeFeedTopic(identity.topic) + } else { + hexTopic = '00'.repeat(32) + } if (!identity.feedHash) { - identity.feedHash = (await beeApi.createFeedManifest(stamp, 'sequence', '00'.repeat(32), wallet.address)).reference + identity.feedHash = (await beeApi.createFeedManifest(stamp, 'sequence', hexTopic, wallet.address)).reference } - const writer = beeApi.makeFeedWriter('sequence', '00'.repeat(32), wallet.privateKey) + const writer = beeApi.makeFeedWriter('sequence', hexTopic, wallet.privateKey) if (beeDebugApi) { await waitUntilStampUsable(stamp as BatchId, beeDebugApi) } - await writer.upload(stamp, hash as Reference) + + if (uporigin === 'POST') { + const postData = JSON.stringify(msg) + const fileoptions: FileUploadOptions = {} + fileoptions.contentType = 'application/json' + const dirHash = await beeApi.uploadFile(stamp, postData, 'file.json', fileoptions) + + if (dirHash) { + await writer.upload(stamp, dirHash.reference) + } + } else { + await writer.upload(stamp, hash as Reference) + } +} + +function decimalToHex(d: number, padding: number) { + let hex = Number(d).toString(16) + padding = typeof padding === 'undefined' || padding === null ? (padding = 2) : padding + + while (hex.length < padding) { + hex = '0' + hex + } + + return hex +} + +export async function readFeed( + beeApi: Bee, + beeDebugApi: BeeDebug | null, + identity: Identity, + password?: string, +): Promise { + console.log('Inside reading feed') + const Posts: Post[] = [] + console.log('read feed: ', identity, 'Password: ', password) + const wallet = await getWalletFromIdentity(identity, password) + const topic = beeApi.makeFeedTopic(identity.topic) + const reader = beeApi.makeFeedReader('sequence', topic, wallet.address) + const options: FeedUploadOptions = {} + + const { feedIndex } = await reader.download() + const I0 = parseInt(feedIndex, 16) + console.log('I0: ', I0) + for (let i = 0; i <= I0; i++) { + options.index = decimalToHex(i, 16).toString() + await reader + .download(options) + .then(async fv => { + await beeApi + .downloadReadableFile(fv.reference, 'file.json') + .then(fjson => { + const jdata = JSON.parse(JSON.stringify(fjson.data)) + try { + Posts.push(...[jdata]) + } catch (e) { + throw e + } + }) + .catch(error0 => { + throw error0 + }) + }) + .catch(error1 => { + throw error1 + }) + } + + return Posts }