From 03d4ba38a060468405f3423724833ae4d5dffdd7 Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Tue, 22 Apr 2025 10:39:32 +0530 Subject: [PATCH] feat: integrate Waku, remove mock functions --- package-lock.json | 30 +- package.json | 2 + src/App.tsx | 12 + src/components/CellList.tsx | 63 ++-- src/components/CreateCellDialog.tsx | 11 +- src/components/Header.tsx | 38 ++- src/components/PostDetail.tsx | 59 ++-- src/components/PostList.tsx | 73 +++-- src/contexts/ForumContext.tsx | 447 +++++++++++++++++++++++----- src/lib/waku/codec.ts | 64 ++-- src/lib/waku/constants.ts | 14 +- src/lib/waku/index.ts | 111 ++++++- src/lib/waku/lightpush_filter.ts | 38 +-- src/lib/waku/store.ts | 30 +- src/pages/Index.tsx | 20 +- 15 files changed, 757 insertions(+), 255 deletions(-) diff --git a/package-lock.json b/package-lock.json index 98138f4..e5684ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -56,6 +56,7 @@ "sonner": "^1.5.0", "tailwind-merge": "^2.5.2", "tailwindcss-animate": "^1.0.7", + "uuid": "^11.1.0", "vaul": "^0.9.3", "zod": "^3.23.8" }, @@ -65,6 +66,7 @@ "@types/node": "^22.5.5", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", + "@types/uuid": "^10.0.0", "@vitejs/plugin-react-swc": "^3.5.0", "autoprefixer": "^10.4.20", "eslint": "^9.9.0", @@ -3485,6 +3487,13 @@ "integrity": "sha512-XISRgDJ2Tc5q4TRqvgJtzsRkFYNJzZrhTdtMoGVBttwzzQJkPnS3WWTFc7kuDRoPtPakl+T+OfdEUjYJj7Jbow==", "license": "MIT" }, + "node_modules/@types/uuid": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/ws": { "version": "8.18.1", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz", @@ -3770,6 +3779,19 @@ } } }, + "node_modules/@waku/core/node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@waku/discovery": { "version": "0.0.7", "resolved": "https://registry.npmjs.org/@waku/discovery/-/discovery-0.0.7.tgz", @@ -8382,16 +8404,16 @@ "license": "MIT" }, "node_modules/uuid": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", - "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.0.tgz", + "integrity": "sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==", "funding": [ "https://github.com/sponsors/broofa", "https://github.com/sponsors/ctavan" ], "license": "MIT", "bin": { - "uuid": "dist/bin/uuid" + "uuid": "dist/esm/bin/uuid" } }, "node_modules/vaul": { diff --git a/package.json b/package.json index 7f6f1c3..389b6e7 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "sonner": "^1.5.0", "tailwind-merge": "^2.5.2", "tailwindcss-animate": "^1.0.7", + "uuid": "^11.1.0", "vaul": "^0.9.3", "zod": "^3.23.8" }, @@ -68,6 +69,7 @@ "@types/node": "^22.5.5", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", + "@types/uuid": "^10.0.0", "@vitejs/plugin-react-swc": "^3.5.0", "autoprefixer": "^10.4.20", "eslint": "^9.9.0", diff --git a/src/App.tsx b/src/App.tsx index 2aeba6e..9185ed2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,3 +1,15 @@ +//TODO: research into having signatures somehow? +//TODO research: **each message sent should not be able to be spoofed** +/** + * Reference: + * https://www.notion.so/Logos-Forum-PoC-Waku-Powered-Opchan-1968f96fb65c8078b343c43429d66d0a#1968f96fb65c8025a929c2c9255a57c4 + * Also note that for UX purposes, **we should not ask a user to sign with their Bitcoin wallet for every action.** + * + * Instead, a key delegation system should be developed. + * + * - User sign an in-browser key with their wallet and broadcast it + * - Browser uses in-browser key to sign messages moving forward + */ import { Toaster } from "@/components/ui/toaster"; import { Toaster as Sonner } from "@/components/ui/sonner"; diff --git a/src/components/CellList.tsx b/src/components/CellList.tsx index 1bced67..a37a95b 100644 --- a/src/components/CellList.tsx +++ b/src/components/CellList.tsx @@ -1,15 +1,15 @@ - import React from 'react'; import { Link } from 'react-router-dom'; import { useForum } from '@/contexts/ForumContext'; import { Skeleton } from '@/components/ui/skeleton'; -import { Layout, MessageSquare } from 'lucide-react'; +import { Layout, MessageSquare, RefreshCw } from 'lucide-react'; import { CreateCellDialog } from './CreateCellDialog'; +import { Button } from '@/components/ui/button'; const CellList = () => { - const { cells, loading, posts } = useForum(); + const { cells, isInitialLoading, posts, refreshData, isRefreshing } = useForum(); - if (loading) { + if (isInitialLoading) { return (

Loading Cells...

@@ -42,29 +42,48 @@ const CellList = () => {

Cells

- +
+ + +
- {cells.map((cell) => ( - -
- {cell.name} -
-

{cell.name}

-

{cell.description}

-
- - {getPostCount(cell.id)} threads + {cells.length === 0 ? ( +
+
+ No cells found. Be the first to create one! +
+
+ ) : ( + cells.map((cell) => ( + +
+ {cell.name} +
+

{cell.name}

+

{cell.description}

+
+ + {getPostCount(cell.id)} threads +
-
- - ))} + + )) + )}
); diff --git a/src/components/CreateCellDialog.tsx b/src/components/CreateCellDialog.tsx index 552e332..ca4f0c7 100644 --- a/src/components/CreateCellDialog.tsx +++ b/src/components/CreateCellDialog.tsx @@ -1,4 +1,3 @@ - import React from 'react'; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; @@ -32,7 +31,7 @@ const formSchema = z.object({ }); export function CreateCellDialog() { - const { createCell } = useForum(); + const { createCell, isPostingCell } = useForum(); const { isAuthenticated } = useAuth(); const [open, setOpen] = React.useState(false); @@ -73,7 +72,7 @@ export function CreateCellDialog() { Title - + @@ -89,6 +88,7 @@ export function CreateCellDialog() {