From 065894f23c3d6b2980b82725e7436d4aeebba849 Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Tue, 5 Dec 2023 12:18:03 +0100 Subject: [PATCH 01/23] Add a topic field to account for non zero topics --- src/providers/Feeds.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/providers/Feeds.tsx b/src/providers/Feeds.tsx index d0e5e717..2f42acc7 100644 --- a/src/providers/Feeds.tsx +++ b/src/providers/Feeds.tsx @@ -5,6 +5,7 @@ export type IdentityType = 'V3' | 'PRIVATE_KEY' export interface Identity { uuid: string name: string + topic: string, feedHash?: string identity: string address: string From b27881fd29aa9c16aa78eeff6c83b6c224cadf10 Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Tue, 5 Dec 2023 22:23:32 +0100 Subject: [PATCH 02/23] caniuse-lite from"1.0.30001352"to"1.0.30001566" --- package-lock.json | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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": { From 333dbc65dd137fb57a36e7149dec1f4bfa6daf32 Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Tue, 5 Dec 2023 22:25:01 +0100 Subject: [PATCH 03/23] add text input for topic --- src/pages/account/feeds/AccountFeeds.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pages/account/feeds/AccountFeeds.tsx b/src/pages/account/feeds/AccountFeeds.tsx index 22cc6c48..9778a172 100644 --- a/src/pages/account/feeds/AccountFeeds.tsx +++ b/src/pages/account/feeds/AccountFeeds.tsx @@ -10,6 +10,7 @@ import ExpandableListItem from '../../../components/ExpandableListItem' import ExpandableListItemActions from '../../../components/ExpandableListItemActions' import ExpandableListItemKey from '../../../components/ExpandableListItemKey' import { SwarmButton } from '../../../components/SwarmButton' +import { SwarmTextInput } from '../../../components/SwarmTextInput' import { Context as IdentityContext, Identity } from '../../../providers/Feeds' import { ROUTES } from '../../../routes' import { formatEnum } from '../../../utils' @@ -98,7 +99,11 @@ export function AccountFeeds(): ReactElement { - + {x.website ? ( + + ) : ( + + )} {x.feedHash && } From 9f768c624283553479a735f06df4d8830600dd8d Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Tue, 5 Dec 2023 22:28:28 +0100 Subject: [PATCH 04/23] add topic and bool for to extend topic feed use --- src/pages/feeds/CreateNewFeed.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pages/feeds/CreateNewFeed.tsx b/src/pages/feeds/CreateNewFeed.tsx index fdd8f1a4..dc796987 100644 --- a/src/pages/feeds/CreateNewFeed.tsx +++ b/src/pages/feeds/CreateNewFeed.tsx @@ -20,6 +20,8 @@ import { convertWalletToIdentity, generateWallet, persistIdentity } from '../../ interface FormValues { identityName?: string type?: IdentityType + website: boolean + topic: string password?: string } @@ -27,6 +29,8 @@ const initialValues: FormValues = { identityName: '', type: 'PRIVATE_KEY', password: '', + website: true, + topic: '00', } export default function CreateNewFeed(): ReactElement { @@ -108,7 +112,11 @@ export default function CreateNewFeed(): ReactElement { {values.type === 'V3' && } - + {values.website ? ( + + ) : ( + + )} From 1cc4c742228c92a8cfc4a8b3f7a5eabf4cff3c83 Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Tue, 5 Dec 2023 22:29:57 +0100 Subject: [PATCH 05/23] add website bool old and new topic use --- src/providers/Feeds.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/providers/Feeds.tsx b/src/providers/Feeds.tsx index 2f42acc7..321c3924 100644 --- a/src/providers/Feeds.tsx +++ b/src/providers/Feeds.tsx @@ -5,7 +5,8 @@ export type IdentityType = 'V3' | 'PRIVATE_KEY' export interface Identity { uuid: string name: string - topic: string, + website: boolean + topic: string feedHash?: string identity: string address: string From 52a0e88512b29490aa7f8397c605f23fe1881b20 Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Tue, 5 Dec 2023 22:30:23 +0100 Subject: [PATCH 06/23] add website and topic --- src/utils/identity.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/utils/identity.ts b/src/utils/identity.ts index ccfa403c..43d341d6 100644 --- a/src/utils/identity.ts +++ b/src/utils/identity.ts @@ -37,6 +37,8 @@ export async function convertWalletToIdentity( uuid: uuidV4(), name, type: password ? 'V3' : 'PRIVATE_KEY', + topic: '00', + website: true, address: identity.address, identity: identityString, } @@ -50,6 +52,8 @@ export async function importIdentity(name: string, data: string): Promise Date: Fri, 8 Dec 2023 10:42:08 +0100 Subject: [PATCH 07/23] Set feedtype control locally --- src/pages/feeds/CreateNewFeed.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/feeds/CreateNewFeed.tsx b/src/pages/feeds/CreateNewFeed.tsx index dc796987..74d05627 100644 --- a/src/pages/feeds/CreateNewFeed.tsx +++ b/src/pages/feeds/CreateNewFeed.tsx @@ -37,6 +37,7 @@ export default function CreateNewFeed(): ReactElement { const { beeApi, beeDebugApi } = useContext(SettingsContext) const { identities, setIdentities } = useContext(FeedsContext) const [loading, setLoading] = useState(false) + const [website, setFeedType] = useState(true) const { enqueueSnackbar } = useSnackbar() const navigate = useNavigate() @@ -112,7 +113,7 @@ export default function CreateNewFeed(): ReactElement { {values.type === 'V3' && } - {values.website ? ( + {website ? ( ) : ( From 5ec2e6a1ba06ffb9fee8bfe4b698971c4dded82d Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Fri, 8 Dec 2023 18:56:29 +0100 Subject: [PATCH 08/23] Add Array based display of Postes, no data con yet --- src/pages/feeds/FeedSubpage.tsx | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/pages/feeds/FeedSubpage.tsx b/src/pages/feeds/FeedSubpage.tsx index 37702484..89f9264d 100644 --- a/src/pages/feeds/FeedSubpage.tsx +++ b/src/pages/feeds/FeedSubpage.tsx @@ -5,6 +5,8 @@ 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' @@ -25,6 +27,34 @@ export function FeedSubpage(): ReactElement { const identity = identities.find(x => x.uuid === uuid) + const readPostArray: Array<{ + Title: String + Type: String + Category: String + Date: String + Amount: String + Provider: String + Place: String + DocRef: String + }> = [] + + const message = { + Title: 'PS5', + Type: 'Document', + Category: 'Loisir', + Date: '07/12/2023', + Amount: '750€', + Provider: 'Sony', + Place: 'La Defense', + DocRefUrl: '', + } + + try { + readPostArray.push(...[message]) + } catch (e) { + console.log('Failed to: ', e) + } + useEffect(() => { if (!identity || !identity.feedHash) { return @@ -72,6 +102,21 @@ export function FeedSubpage(): ReactElement { )} + // Posts form + {readPostArray.map((x, i) => ( + + + + + + + + + /* Add a clickable bzz link to a bill scan here */ + + + + ))} Close From 8864e5a66c57929853fdd7c5ee4e6c1f163cda51 Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Fri, 8 Dec 2023 18:59:53 +0100 Subject: [PATCH 09/23] Limited impact on the code remove website bool --- src/pages/account/feeds/AccountFeeds.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/account/feeds/AccountFeeds.tsx b/src/pages/account/feeds/AccountFeeds.tsx index 9778a172..18567e9a 100644 --- a/src/pages/account/feeds/AccountFeeds.tsx +++ b/src/pages/account/feeds/AccountFeeds.tsx @@ -99,7 +99,7 @@ export function AccountFeeds(): ReactElement { - {x.website ? ( + {x.topic === '' ? ( ) : ( From 6fdc68b207b0e4eb8249c999cecdef3d2fa717b9 Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Wed, 13 Dec 2023 08:55:20 +0100 Subject: [PATCH 10/23] Add screen to display posts from the feed when topic is not website. --- src/pages/feeds/FeedSubpage.tsx | 47 +++++++++++++-------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/src/pages/feeds/FeedSubpage.tsx b/src/pages/feeds/FeedSubpage.tsx index 89f9264d..c9ed6907 100644 --- a/src/pages/feeds/FeedSubpage.tsx +++ b/src/pages/feeds/FeedSubpage.tsx @@ -10,15 +10,17 @@ 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, Context as IdentityContext } from '../../providers/Feeds' import { Context as SettingsContext } from '../../providers/Settings' import { ROUTES } from '../../routes' import { UploadArea } from '../files/UploadArea' +import { readFeed } from '../../utils/identity' export function FeedSubpage(): ReactElement { const { identities } = useContext(IdentityContext) + const { posts } = useContext(IdentityContext) const { uuid } = useParams() - const { beeApi } = useContext(SettingsContext) + const { beeApi, beeDebugApi } = useContext(SettingsContext) const { status } = useContext(BeeContext) const navigate = useNavigate() @@ -27,32 +29,17 @@ export function FeedSubpage(): ReactElement { const identity = identities.find(x => x.uuid === uuid) - const readPostArray: Array<{ - Title: String - Type: String - Category: String - Date: String - Amount: String - Provider: String - Place: String - DocRef: String - }> = [] - - const message = { - Title: 'PS5', - Type: 'Document', - Category: 'Loisir', - Date: '07/12/2023', - Amount: '750€', - Provider: 'Sony', - Place: 'La Defense', - DocRefUrl: '', + if (!beeApi || !beeDebugApi) { + return <> } - try { - readPostArray.push(...[message]) - } catch (e) { - console.log('Failed to: ', e) + if (identity?.topic === '') { + } else { + try { + const readPostArray = readFeed(beeApi, beeDebugApi, identity as Identity) + } catch (error) { + return <> + } } useEffect(() => { @@ -80,7 +67,11 @@ export function FeedSubpage(): ReactElement { return (
{`${identity.name} Website`} - + {identity.topic === '' ? ( + + ) : ( + + )} {available && identity.feedHash ? ( <> @@ -103,7 +94,7 @@ export function FeedSubpage(): ReactElement { )} // Posts form - {readPostArray.map((x, i) => ( + {posts.map((x, i) => ( From 8a39846b9ba285e0648a17d250f1d6d26333ae6a Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Wed, 13 Dec 2023 08:56:29 +0100 Subject: [PATCH 11/23] Add screen for data input in the case of feed with topic different from website. --- src/pages/files/Upload.tsx | 95 ++++++++++++++++++++++++++++++++++---- 1 file changed, 85 insertions(+), 10 deletions(-) diff --git a/src/pages/files/Upload.tsx b/src/pages/files/Upload.tsx index 16a1594e..0c78822b 100644 --- a/src/pages/files/Upload.tsx +++ b/src/pages/files/Upload.tsx @@ -1,4 +1,7 @@ import { Box } from '@material-ui/core' +import { Form, Formik } from 'formik' +import { SwarmSelect } from '../../components/SwarmSelect' +import { SwarmTextInput } from '../../components/SwarmTextInput' import { useSnackbar } from 'notistack' import { ReactElement, useContext, useEffect, useState } from 'react' import { useNavigate } from 'react-router-dom' @@ -8,7 +11,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 +26,8 @@ import { PostageStampSelector } from '../stamps/PostageStampSelector' import { AssetPreview } from './AssetPreview' import { StampPreview } from './StampPreview' import { UploadActionBar } from './UploadActionBar' +import ExpandableList from '../../components/ExpandableList' +import ExpandableListItemInput from '../../components/ExpandableListItemInput' export function Upload(): ReactElement { const [step, setStep] = useState(0) @@ -41,6 +46,17 @@ export function Upload(): ReactElement { 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: '', + } + const [PostData, setPostData] = useState(msg) useEffect(() => { refresh() @@ -122,7 +138,6 @@ export function Upload(): ReactElement { }) fls.push(packageFile(previewFile)) } - setUploading(true) if (beeDebugApi) { @@ -133,17 +148,24 @@ 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, + PostData as Post, + password as string, + ).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 +186,10 @@ export function Upload(): ReactElement { uploadFiles(password) } + async function onSubmit(values: Post) { + setPostData(values) + } + return ( <> {showPasswordPrompt && ( @@ -205,6 +231,55 @@ export function Upload(): ReactElement { )} {step === 2 && stamp && } + // Posts form + {uploadOrigin.origin === 'POST' && ( + + {({ submitForm, values }) => ( +
+ + + + + + + + + + + + + + + + + + + + + +
+ )} +
+ )} + // Post Form Date: Wed, 13 Dec 2023 09:01:38 +0100 Subject: [PATCH 12/23] Add button for managing Posting data. Also variables for case where no data is needed in post. --- src/pages/files/UploadArea.tsx | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/pages/files/UploadArea.tsx b/src/pages/files/UploadArea.tsx index 9eba267b..edd7c80c 100644 --- a/src/pages/files/UploadArea.tsx +++ b/src/pages/files/UploadArea.tsx @@ -5,6 +5,7 @@ import { ReactElement, useContext, useState } from 'react' import PlusCircle from 'remixicon-react/AddCircleLineIcon' import FilePlus from 'remixicon-react/FileAddLineIcon' import FolderPlus from 'remixicon-react/FolderAddLineIcon' +import PlusMail from 'remixicon-react/MailAddFillIcon' import { useNavigate } from 'react-router-dom' import { DocumentationText } from '../../components/DocumentationText' import { SwarmButton } from '../../components/SwarmButton' @@ -55,7 +56,9 @@ export function UploadArea({ uploadOrigin, showHelp }: Props): ReactElement { const navigate = useNavigate() const { enqueueSnackbar } = useSnackbar() const [strictWebsiteMode, setStrictWebsiteMode] = useState(false) + const [strictPostMode, setStrictPostMode] = useState(false) const [version, setVersion] = useState(0) + const [postData, setNoData] = useState(false) const getDropzoneInputDomElement = () => 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 && ( From 5b0ca5f5a57987b891e958d7834c5fd95f7e0027 Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Wed, 13 Dec 2023 09:02:31 +0100 Subject: [PATCH 13/23] Define post type and post array to be used in feed details. --- src/providers/Feeds.tsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/providers/Feeds.tsx b/src/providers/Feeds.tsx index 321c3924..f0be0f1a 100644 --- a/src/providers/Feeds.tsx +++ b/src/providers/Feeds.tsx @@ -13,14 +13,29 @@ export interface Identity { type: IdentityType } +export interface Post { + Title: String + Type: String + Category: String + Date: String + Amount: String + Provider: String + Place: String + reference: String +} + interface ContextInterface { identities: Identity[] setIdentities: (identities: Identity[]) => void + posts: Post[] + setPosts: (posts: Post[]) => void } const initialValues: ContextInterface = { identities: [], setIdentities: () => {}, // eslint-disable-line + posts: [], + setPosts: () => {}, } export const Context = createContext(initialValues) @@ -32,7 +47,7 @@ interface Props { export function Provider({ children }: Props): ReactElement { const [identities, setIdentities] = useState(initialValues.identities) - + const [posts, setPosts] = useState(initialValues.posts) useEffect(() => { try { setIdentities(JSON.parse(localStorage.getItem('feeds') || '[]')) @@ -41,5 +56,5 @@ export function Provider({ children }: Props): ReactElement { } }, []) // eslint-disable-line react-hooks/exhaustive-deps - return {children} + return {children} } From 30024c32bf1e32563634065b54fe134895fe9ca1 Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Wed, 13 Dec 2023 09:03:05 +0100 Subject: [PATCH 14/23] Add mode POST for upload origin. --- src/providers/File.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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' } From 0841679db98c15cf1345a84b426a5a2d0fae845f Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Wed, 13 Dec 2023 09:05:26 +0100 Subject: [PATCH 15/23] change updateFeed to account for POST update. Add readFeed to retrieve an array of older POST --- src/utils/identity.ts | 90 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 5 deletions(-) diff --git a/src/utils/identity.ts b/src/utils/identity.ts index 43d341d6..e2d89918 100644 --- a/src/utils/identity.ts +++ b/src/utils/identity.ts @@ -1,8 +1,11 @@ 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, Context as IdentityContext } from '../providers/Feeds' +import { FeedUploadOptions } from '@ethersphere/bee-js/dist/types/feed' +import { ReactElement, useContext, useEffect, useState } from 'react' +import { Context as FileContext } from '../providers/File' +import { FileUploadOptions } from '@ethersphere/bee-js' export function generateWallet(): Wallet { return Wallet.createRandom() } @@ -95,18 +98,95 @@ export async function updateFeed( identity: Identity, hash: string, stamp: string, + msg: Post, password?: string, ): Promise { const wallet = await getWalletFromIdentity(identity, password) + const [hexTopic, setTopic] = useState('0x0') + const { uploadOrigin } = useContext(FileContext) + + if (uploadOrigin.origin === 'POST') { + setTopic(beeApi.makeFeedTopic(identity.topic)) + } else { + setTopic('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 (uploadOrigin.origin === '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) { + const result = await writer.upload(stamp, dirHash.reference) + console.log('Feed write result hash: ', result) + } + } else { + await writer.upload(stamp, hash as Reference) + } +} + +function decimalToHex(d: number, padding: number) { + var 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 { + const { posts, setPosts } = useContext(IdentityContext) + const Posts: Post[] = [] + const wallet = await getWalletFromIdentity(identity, password) + const topic = beeApi.makeFeedTopic(identity.topic) + const reader = beeApi.makeFeedWriter('sequence', topic, wallet.address) + const options: FeedUploadOptions = {} + + const { reference, feedIndex, feedIndexNext } = await reader.download() + const I0 = parseInt(feedIndex, 16) + + for (let i = 0; i <= I0; i++) { + options.index = decimalToHex(i, 16).toString() + const fv = await reader + .download(options) + .then(async fv => { + const fjson = await beeApi + .downloadReadableFile(fv.reference, 'file.json') + .then(fjson => { + const jdata = JSON.parse(JSON.stringify(fjson.data)) + try { + Posts.push(...[jdata]) + } catch (e) { + console.log('Failed to: ', e) + } + }) + .catch(error0 => { + console.log(error0) + }) + }) + .catch(error1 => { + console.log(error1) + }) + } + setPosts(Posts) + + return Posts } From 6d9bc552cca42af896807319a63a0d825d5e805a Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Sat, 16 Dec 2023 00:09:47 +0100 Subject: [PATCH 16/23] Create a dropdown list dynamically for identities to choose between. Add the array in the Feed/Identity context. Get password when opening the chosen identity. Read feed to get list of previous posts when displaying a given feed. --- src/pages/account/feeds/AccountFeeds.tsx | 61 ++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/src/pages/account/feeds/AccountFeeds.tsx b/src/pages/account/feeds/AccountFeeds.tsx index 18567e9a..e1fd4705 100644 --- a/src/pages/account/feeds/AccountFeeds.tsx +++ b/src/pages/account/feeds/AccountFeeds.tsx @@ -11,7 +11,7 @@ import ExpandableListItemActions from '../../../components/ExpandableListItemAct import ExpandableListItemKey from '../../../components/ExpandableListItemKey' import { SwarmButton } from '../../../components/SwarmButton' import { SwarmTextInput } from '../../../components/SwarmTextInput' -import { Context as IdentityContext, Identity } from '../../../providers/Feeds' +import { Post, Context as IdentityContext, Identity } from '../../../providers/Feeds' import { ROUTES } from '../../../routes' import { formatEnum } from '../../../utils' import { persistIdentitiesWithoutUpdate } from '../../../utils/identity' @@ -22,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() @@ -33,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) @@ -99,10 +138,22 @@ export function AccountFeeds(): ReactElement { - {x.topic === '' ? ( - + + {x.type === 'V3' && ( + { + setPasswd(e.target.value) + }} + /> + )} + + {x.topic === '00' ? ( + ) : ( - + )} {x.feedHash && } From 92cd7180a50e41efee4e88c4460dfaea9de15fce Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Sat, 16 Dec 2023 00:13:39 +0100 Subject: [PATCH 17/23] Changes related to choosing an Id for feed creation and update. --- src/pages/feeds/CreateNewFeed.tsx | 102 +++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 22 deletions(-) diff --git a/src/pages/feeds/CreateNewFeed.tsx b/src/pages/feeds/CreateNewFeed.tsx index 74d05627..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,10 +12,13 @@ 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 @@ -27,20 +30,29 @@ interface FormValues { const initialValues: FormValues = { identityName: '', - type: 'PRIVATE_KEY', + type: 'V3', password: '', - website: true, + 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) @@ -51,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) { @@ -68,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 @@ -99,30 +132,32 @@ export default function CreateNewFeed(): ReactElement { {({ submitForm, values }) => (
- - - - + {checked ? ( + + ) : ( + + )} + {values.type === 'V3' && } {website ? ( ) : ( - + )} Feeds name - {values.identityName} Website + {values.identityName} @@ -130,9 +165,32 @@ export default function CreateNewFeed(): ReactElement { Create Feed + + Feed + Cancel + + } + /> + + } + /> From df49445f1032f1ae5f2c710a5e97312198613d83 Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Sat, 16 Dec 2023 00:15:21 +0100 Subject: [PATCH 18/23] Update to display posts for a given feed. --- src/pages/feeds/FeedSubpage.tsx | 71 ++++++++++++++++----------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/src/pages/feeds/FeedSubpage.tsx b/src/pages/feeds/FeedSubpage.tsx index c9ed6907..2294a135 100644 --- a/src/pages/feeds/FeedSubpage.tsx +++ b/src/pages/feeds/FeedSubpage.tsx @@ -10,36 +10,37 @@ import ExpandableListItem from '../../components/ExpandableListItem' import { HistoryHeader } from '../../components/HistoryHeader' import { SwarmButton } from '../../components/SwarmButton' import { Context as BeeContext } from '../../providers/Bee' -import { Identity, 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' -import { readFeed } from '../../utils/identity' + +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 { posts } = useContext(IdentityContext) + const { identities, isLoadingPosts, setisLoadingPosts, Posts, setPostsList } = useContext(IdentityContext) const { uuid } = useParams() 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) - if (!beeApi || !beeDebugApi) { - return <> - } - - if (identity?.topic === '') { - } else { - try { - const readPostArray = readFeed(beeApi, beeDebugApi, identity as Identity) - } catch (error) { - return <> - } + function onClose() { + setPostsList([]) + setisLoadingPosts(true) + navigate(ROUTES.ACCOUNT_FEEDS) } useEffect(() => { @@ -60,13 +61,9 @@ export function FeedSubpage(): ReactElement { return <> } - function onClose() { - navigate(ROUTES.ACCOUNT_FEEDS) - } - return (
- {`${identity.name} Website`} + {`${identity.topic}`} {identity.topic === '' ? ( ) : ( @@ -93,21 +90,23 @@ export function FeedSubpage(): ReactElement { )} - // Posts form - {posts.map((x, i) => ( - - - - - - - - - /* Add a clickable bzz link to a bill scan here */ - - - - ))} + + + {isLoadingPosts ? ( + + ) : ( + Posts.map((x, i) => ( + + + + + + + + )) + )} + + Close From 836aacf7ef4bd6bcf86925e54944a1b85f248f1d Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Sat, 16 Dec 2023 00:17:03 +0100 Subject: [PATCH 19/23] Adding a form to insert json objects as posts. --- src/pages/files/Upload.tsx | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/pages/files/Upload.tsx b/src/pages/files/Upload.tsx index 0c78822b..1e8e3fed 100644 --- a/src/pages/files/Upload.tsx +++ b/src/pages/files/Upload.tsx @@ -1,7 +1,9 @@ -import { Box } from '@material-ui/core' -import { Form, Formik } from 'formik' +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' @@ -26,8 +28,7 @@ import { PostageStampSelector } from '../stamps/PostageStampSelector' import { AssetPreview } from './AssetPreview' import { StampPreview } from './StampPreview' import { UploadActionBar } from './UploadActionBar' -import ExpandableList from '../../components/ExpandableList' -import ExpandableListItemInput from '../../components/ExpandableListItemInput' +import Check from 'remixicon-react/CheckLineIcon' export function Upload(): ReactElement { const [step, setStep] = useState(0) @@ -39,8 +40,8 @@ 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() @@ -56,7 +57,6 @@ export function Upload(): ReactElement { Place: 'La Defense', reference: '', } - const [PostData, setPostData] = useState(msg) useEffect(() => { refresh() @@ -150,6 +150,7 @@ export function Upload(): ReactElement { 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 { @@ -159,8 +160,9 @@ export function Upload(): ReactElement { identity as Identity, hash.reference, stamp.batchID, - PostData as Post, password as string, + PostData as Post, + uploadOrigin.origin, ).then(() => { persistIdentity(identities, identity as Identity) setIdentities([...identities]) @@ -186,7 +188,8 @@ export function Upload(): ReactElement { uploadFiles(password) } - async function onSubmit(values: Post) { + function onSubmit(values: Post) { + console.log(values) setPostData(values) } @@ -231,9 +234,8 @@ export function Upload(): ReactElement { )} {step === 2 && stamp && } - // Posts form {uploadOrigin.origin === 'POST' && ( - + {({ submitForm, values }) => (
@@ -275,11 +277,18 @@ export function Upload(): ReactElement { + + + + + Save Feed Data + + + )}
)} - // Post Form Date: Sat, 16 Dec 2023 00:18:07 +0100 Subject: [PATCH 20/23] Add a button in the upload options to include non website feeds updates. --- src/pages/files/UploadArea.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/files/UploadArea.tsx b/src/pages/files/UploadArea.tsx index edd7c80c..91d49783 100644 --- a/src/pages/files/UploadArea.tsx +++ b/src/pages/files/UploadArea.tsx @@ -172,7 +172,7 @@ export function UploadArea({ uploadOrigin, showHelp }: Props): ReactElement { Add Website - + New Post
From 7abdb4613295645c9bc40f071ee7e7eafb9d1a85 Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Sat, 16 Dec 2023 00:19:18 +0100 Subject: [PATCH 21/23] Add some shared data in the Id contexte --- src/providers/Feeds.tsx | 86 ++++++++++++++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 14 deletions(-) diff --git a/src/providers/Feeds.tsx b/src/providers/Feeds.tsx index f0be0f1a..196c3d59 100644 --- a/src/providers/Feeds.tsx +++ b/src/providers/Feeds.tsx @@ -14,28 +14,62 @@ export interface Identity { } export interface Post { - Title: String - Type: String - Category: String - Date: String - Amount: String - Provider: String - Place: String - reference: String + 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 - posts: Post[] - setPosts: (posts: Post[]) => 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 - posts: [], - setPosts: () => {}, + optionsArray: [], + setDDOptions: () => {}, // eslint-disable-line + isLoadingPosts: true, + setisLoadingPosts: () => { + return true + }, + Posts: [], + setPostsList: () => { + return [] + }, + PostData: msg, + setPostData: () => { + return msg + }, } export const Context = createContext(initialValues) @@ -47,14 +81,38 @@ interface Props { export function Provider({ children }: Props): ReactElement { const [identities, setIdentities] = useState(initialValues.identities) - const [posts, setPosts] = useState(initialValues.posts) + 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} + + ) } From fb1f82e63db263c11b11c6413e275efb8300ce39 Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Sat, 16 Dec 2023 00:20:55 +0100 Subject: [PATCH 22/23] Add readFeed function to extract older posts from non website feeds. --- src/utils/identity.ts | 48 +++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/utils/identity.ts b/src/utils/identity.ts index e2d89918..d9866e97 100644 --- a/src/utils/identity.ts +++ b/src/utils/identity.ts @@ -1,10 +1,8 @@ import { BatchId, Bee, BeeDebug, Reference } from '@ethersphere/bee-js' import { Wallet } from 'ethers' import { uuidV4, waitUntilStampUsable } from '.' -import { Identity, IdentityType, Post, Context as IdentityContext } from '../providers/Feeds' +import { Identity, IdentityType, Post } from '../providers/Feeds' import { FeedUploadOptions } from '@ethersphere/bee-js/dist/types/feed' -import { ReactElement, useContext, useEffect, useState } from 'react' -import { Context as FileContext } from '../providers/File' import { FileUploadOptions } from '@ethersphere/bee-js' export function generateWallet(): Wallet { return Wallet.createRandom() @@ -28,6 +26,7 @@ export async function convertWalletToIdentity( identity: Wallet, type: IdentityType, name: string, + topic: string, password?: string, ): Promise { if (type === 'V3' && !password) { @@ -40,7 +39,7 @@ export async function convertWalletToIdentity( uuid: uuidV4(), name, type: password ? 'V3' : 'PRIVATE_KEY', - topic: '00', + topic: topic, website: true, address: identity.address, identity: identityString, @@ -84,7 +83,7 @@ export async function importIdentity(name: string, data: string): Promise { +export function getWalletFromIdentity(identity: Identity, password?: string): Promise { return getWallet(identity.type, identity.identity, password) } @@ -98,17 +97,17 @@ export async function updateFeed( identity: Identity, hash: string, stamp: string, - msg: Post, password?: string, + msg?: Post, + uporigin?: string, ): Promise { const wallet = await getWalletFromIdentity(identity, password) - const [hexTopic, setTopic] = useState('0x0') - const { uploadOrigin } = useContext(FileContext) + let hexTopic = '0x0' - if (uploadOrigin.origin === 'POST') { - setTopic(beeApi.makeFeedTopic(identity.topic)) + if (uporigin === 'POST') { + hexTopic = beeApi.makeFeedTopic(identity.topic) } else { - setTopic('00'.repeat(32)) + hexTopic = '00'.repeat(32) } if (!identity.feedHash) { @@ -121,15 +120,14 @@ export async function updateFeed( await waitUntilStampUsable(stamp as BatchId, beeDebugApi) } - if (uploadOrigin.origin === 'POST') { + 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) { - const result = await writer.upload(stamp, dirHash.reference) - console.log('Feed write result hash: ', result) + await writer.upload(stamp, dirHash.reference) } } else { await writer.upload(stamp, hash as Reference) @@ -137,7 +135,7 @@ export async function updateFeed( } function decimalToHex(d: number, padding: number) { - var hex = Number(d).toString(16) + let hex = Number(d).toString(16) padding = typeof padding === 'undefined' || padding === null ? (padding = 2) : padding while (hex.length < padding) { @@ -153,40 +151,40 @@ export async function readFeed( identity: Identity, password?: string, ): Promise { - const { posts, setPosts } = useContext(IdentityContext) + 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.makeFeedWriter('sequence', topic, wallet.address) + const reader = beeApi.makeFeedReader('sequence', topic, wallet.address) const options: FeedUploadOptions = {} - const { reference, feedIndex, feedIndexNext } = await reader.download() + 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() - const fv = await reader + await reader .download(options) .then(async fv => { - const fjson = await beeApi + await beeApi .downloadReadableFile(fv.reference, 'file.json') .then(fjson => { const jdata = JSON.parse(JSON.stringify(fjson.data)) try { Posts.push(...[jdata]) } catch (e) { - console.log('Failed to: ', e) + throw e } }) .catch(error0 => { - console.log(error0) + throw error0 }) }) .catch(error1 => { - console.log(error1) + throw error1 }) } - setPosts(Posts) return Posts } From 0099e2aa6226d8a9ceb860f01eb68fcaef653e95 Mon Sep 17 00:00:00 2001 From: Binyom Binyom Baleba Etobe Binyom Date: Sat, 16 Dec 2023 00:26:15 +0100 Subject: [PATCH 23/23] allow console.log --- .eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",