diff --git a/examples/buddybook/src/App.tsx b/examples/buddybook/src/App.tsx index 4921f53..51c7f6a 100644 --- a/examples/buddybook/src/App.tsx +++ b/examples/buddybook/src/App.tsx @@ -24,7 +24,6 @@ function App() { const [isListening, setIsListening] = useState(false); const [chainsData, setChainsData] = useState([]) const { isLoading: isWakuLoading, error: wakuError, node } = useWaku(); - // Add this new state const [wakuStatus, setWakuStatus] = useState({ filter: 'in-progress', store: 'in-progress', @@ -39,11 +38,51 @@ function App() { } }, []); + const handleChainUpdate = (newBlock: BlockPayload) => { + setChainsData(prevChains => { + const blockExists = prevChains.some(block => block.blockUUID === newBlock.blockUUID); + if (blockExists) { + return prevChains; + } + return [...prevChains, newBlock]; + }); + }; + + const startMessageListening = async () => { + console.log("Starting message listening") + try { + setWakuStatus(prev => ({ ...prev, store: 'in-progress' })); + setIsLoadingChains(true); + const messageGenerator = getMessagesFromStore(node as LightNode); + + for await (const message of messageGenerator) { + handleChainUpdate(message); + } + + setWakuStatus(prev => ({ ...prev, store: 'success' })); + } catch (error) { + console.error("Error fetching messages from store:", error); + setWakuStatus(prev => ({ ...prev, store: 'error' })); + } finally { + setIsLoadingChains(false); + } + + try { + setWakuStatus(prev => ({ ...prev, filter: 'in-progress' })); + await subscribeToFilter(node as LightNode, handleChainUpdate); + setWakuStatus(prev => ({ ...prev, filter: 'success' })); + } catch (error) { + console.error("Error subscribing to filter:", error); + setWakuStatus(prev => ({ ...prev, filter: 'error' })); + } + } + useEffect(() => { - if (isWakuLoading || !node || node.libp2p.getConnections().length === 0 || chainsData.length > 0 || isListening) return; - setIsListening(true); - startMessageListening(); - }, [node, isWakuLoading, wakuStatus]) + if (isWakuLoading || !node || node.libp2p.getConnections().length === 0 || chainsData.length > 0 || isListening) return; + setIsListening(true); + startMessageListening(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [node, isWakuLoading, chainsData.length, isListening]); const handleTelemetryOptIn = (optIn: boolean) => { setTelemetryOptIn(optIn); @@ -64,42 +103,6 @@ function App() { ); } - const startMessageListening = async () => { - console.log("Starting message listening") - try { - setWakuStatus(prev => ({ ...prev, store: 'in-progress' })); - setIsLoadingChains(true); - const messageGenerator = getMessagesFromStore(node as LightNode); - - // Process messages as they arrive - for await (const message of messageGenerator) { - setChainsData(prevChains => { - const blockExists = prevChains.some(block => block.blockUUID === message.blockUUID); - if (blockExists) return prevChains; - return [...prevChains, message]; - }); - } - - setWakuStatus(prev => ({ ...prev, store: 'success' })); - } catch (error) { - console.error("Error fetching messages from store:", error); - setWakuStatus(prev => ({ ...prev, store: 'error' })); - } finally { - setIsLoadingChains(false); - } - - try { - setWakuStatus(prev => ({ ...prev, filter: 'in-progress' })); - await subscribeToFilter(node as LightNode, (message) => { - handleChainUpdate(message); // Use the same function for both updates - }) - setWakuStatus(prev => ({ ...prev, filter: 'success' })); - } catch (error) { - console.error("Error subscribing to filter:", error); - setWakuStatus(prev => ({ ...prev, filter: 'error' })); - } - } - if (wakuError) { return (
@@ -109,17 +112,6 @@ function App() { ); } - const handleChainUpdate = (newBlock: BlockPayload) => { - setChainsData(prevChains => { - // Check if the block already exists - const blockExists = prevChains.some(block => block.blockUUID === newBlock.blockUUID); - if (blockExists) { - return prevChains; // Don't add duplicate blocks - } - return [...prevChains, newBlock]; - }); - }; - if (telemetryOptIn === null) { return ; } diff --git a/examples/buddybook/src/components/ui/button.tsx b/examples/buddybook/src/components/ui/button.tsx index ed0f627..0f3493c 100644 --- a/examples/buddybook/src/components/ui/button.tsx +++ b/examples/buddybook/src/components/ui/button.tsx @@ -54,4 +54,5 @@ const Button = React.forwardRef( ) Button.displayName = "Button" +// eslint-disable-next-line react-refresh/only-export-components export { Button, buttonVariants } diff --git a/examples/buddybook/tasks.md b/examples/buddybook/tasks.md index cfc9059..a7286b5 100644 --- a/examples/buddybook/tasks.md +++ b/examples/buddybook/tasks.md @@ -1,12 +1,12 @@ - [ x ] waku connections on header should have green/yellow/red color indicator - [ x ] chains can't be signed twice by an address - [ ] generate waku peer id using the wallet address -- [ ] telemetry - - [ x ] disclaimer - - [ ] functionality -- [ ] landing page -- [ ] look into high initial loading times -- [ ] fix deployment/hosting - [ x ] sign shared chain route should show spinner while waiting for the store query to resolve - [ x ] create chain -> QR modal should have a sharable link instead of the object - [ x ] store query should yield messages as they come in, instead of waiting for all of them to come in before displaying anything +- [ ] landing page +- [ ] look into high initial loading times +- [ ] fix deployment/hosting +- [ ] telemetry + - [ x ] disclaimer + - [ ] functionality