diff --git a/examples/buddybook/src/components/Chain/Create/CreationPreview.tsx b/examples/buddybook/src/components/Chain/Create/CreationPreview.tsx index 6558f7b..54c5537 100644 --- a/examples/buddybook/src/components/Chain/Create/CreationPreview.tsx +++ b/examples/buddybook/src/components/Chain/Create/CreationPreview.tsx @@ -12,6 +12,7 @@ import { v4 as uuidv4 } from 'uuid'; import { useWaku } from '@waku/react'; import { LightNode } from '@waku/sdk'; import { createMessage, encoder } from '@/lib/waku'; +import { useWalletPrompt } from '@/hooks/useWalletPrompt'; interface FormData { title: string; @@ -66,6 +67,8 @@ const ChainCreationForm: React.FC = () => { } }); + const { ensureWalletConnected } = useWalletPrompt(); + const handleInputChange = (e: React.ChangeEvent) => { const { name, value } = e.target; setFormData(prevData => ({ @@ -94,6 +97,9 @@ const ChainCreationForm: React.FC = () => { const handleCreateChain = (e: React.FormEvent) => { e.preventDefault(); + if (!ensureWalletConnected()) { + return; + } if (validateForm()) { setShowModal(true); } diff --git a/examples/buddybook/src/components/Chain/SignChain.tsx b/examples/buddybook/src/components/Chain/SignChain.tsx index 6bbfeb2..cdb7415 100644 --- a/examples/buddybook/src/components/Chain/SignChain.tsx +++ b/examples/buddybook/src/components/Chain/SignChain.tsx @@ -8,6 +8,7 @@ import { Button } from "@/components/ui/button"; import { Loader2 } from "lucide-react"; import QRCode from '@/components/QRCode'; import { v4 as uuidv4 } from 'uuid'; +import { useWalletPrompt } from '@/hooks/useWalletPrompt'; interface SignChainProps { block: BlockPayload; @@ -23,6 +24,7 @@ const SignChain: React.FC = ({ block, chainsData, onSuccess }) = const { address } = useAccount(); const { data: ensName } = useEnsName({ address }); const { node } = useWaku(); + const { ensureWalletConnected } = useWalletPrompt(); useEffect(() => { if (address) { @@ -100,6 +102,9 @@ const SignChain: React.FC = ({ block, chainsData, onSuccess }) = }); const handleSign = () => { + if (!ensureWalletConnected()) { + return; + } // Add an additional check here before signing if (alreadySigned) { setError('You have already signed this chain.'); diff --git a/examples/buddybook/src/hooks/useWalletPrompt.ts b/examples/buddybook/src/hooks/useWalletPrompt.ts new file mode 100644 index 0000000..75a2909 --- /dev/null +++ b/examples/buddybook/src/hooks/useWalletPrompt.ts @@ -0,0 +1,20 @@ +import { useAccount, useConnect } from 'wagmi' + +export function useWalletPrompt() { + const { isConnected } = useAccount() + const { connect, connectors } = useConnect() + + const ensureWalletConnected = () => { + if (!isConnected) { + // Find the first available connector (usually injected/metamask) + const connector = connectors[0] + if (connector) { + connect({ connector }) + } + return false + } + return true + } + + return { ensureWalletConnected } +} \ No newline at end of file diff --git a/examples/buddybook/tasks.md b/examples/buddybook/tasks.md index 6118deb..538283e 100644 --- a/examples/buddybook/tasks.md +++ b/examples/buddybook/tasks.md @@ -1,8 +1,11 @@ - [ x ] waku connections on header should have green/yellow/red color indicator - - [ ] clicking on the indicator should show a list of peers - [ x ] chains can't be signed twice by an address - [ ] generate waku peer id using the wallet address - [ ] telemetry - [ x ] disclaimer - [ ] functionality -- [ ] landing page \ No newline at end of file +- [ ] landing page +- [ ] look into high initial loading times +- [ ] fix deployment/hosting +- [ ] sign shared chain route should show spinner while waiting for the store query to resolve +- [ ] create chain -> QR modal should have a sharable link instead of the object \ No newline at end of file