-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(buddychain): multi signing and view sharable links (#103)
- Loading branch information
1 parent
fc20680
commit 49460a2
Showing
6 changed files
with
133 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
examples/buddybook/src/components/Chain/SignSharedChain.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useParams, useNavigate } from 'react-router-dom'; | ||
import { BlockPayload } from '@/lib/waku'; | ||
import SignChain from './SignChain'; | ||
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card"; | ||
import { Button } from "@/components/ui/button"; | ||
|
||
interface SignSharedChainProps { | ||
chainsData: BlockPayload[]; | ||
onChainUpdate: (newBlock: BlockPayload) => void; | ||
} | ||
|
||
const SignSharedChain: React.FC<SignSharedChainProps> = ({ chainsData, onChainUpdate }) => { | ||
const { chainUUID, blockUUID } = useParams(); | ||
const [block, setBlock] = useState<BlockPayload | null>(null); | ||
const navigate = useNavigate(); | ||
|
||
useEffect(() => { | ||
const foundBlock = chainsData.find(b => b.chainUUID === chainUUID && b.blockUUID === blockUUID); | ||
if (foundBlock) { | ||
setBlock(foundBlock); | ||
} | ||
}, [chainsData, chainUUID, blockUUID]); | ||
|
||
if (!block) { | ||
return ( | ||
<Card className="w-full max-w-md mx-auto"> | ||
<CardHeader> | ||
<CardTitle>Chain Not Found</CardTitle> | ||
</CardHeader> | ||
<CardContent> | ||
<p className="mb-4">The requested chain or block could not be found.</p> | ||
<Button onClick={() => navigate('/view')}>View All Chains</Button> | ||
</CardContent> | ||
</Card> | ||
); | ||
} | ||
|
||
return ( | ||
<Card className="w-full max-w-2xl mx-auto"> | ||
<CardHeader> | ||
<CardTitle>Sign Shared Chain</CardTitle> | ||
</CardHeader> | ||
<CardContent> | ||
<h2 className="text-xl font-semibold mb-2">{block.title}</h2> | ||
<p className="mb-4">{block.description}</p> | ||
<SignChain block={block} onSuccess={onChainUpdate} /> | ||
</CardContent> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default SignSharedChain; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,18 @@ | ||
import React from 'react'; | ||
import { QRCodeSVG } from 'qrcode.react'; | ||
import { BlockPayload } from '@/lib/waku'; | ||
import { Button } from '@/components/ui/button'; | ||
import { useEnsName } from 'wagmi'; | ||
|
||
interface QRCodeProps { | ||
data: BlockPayload; | ||
size?: number; | ||
onSign?: () => void; | ||
text: string; | ||
width?: number; | ||
height?: number; | ||
} | ||
|
||
const QRCode: React.FC<QRCodeProps> = ({ data, size = 256, onSign }) => { | ||
const shareableLink = `${window.location.origin}/view/${data.chainUUID}/${data.blockUUID}`; | ||
|
||
const QRCode: React.FC<QRCodeProps> = ({ text, width = 256, height = 256 }) => { | ||
return ( | ||
<div className="flex flex-col items-center space-y-4"> | ||
<QRCodeSVG value={shareableLink} size={size} /> | ||
<div className="text-sm text-muted-foreground"> | ||
<p><strong>Title:</strong> {data.title}</p> | ||
<p><strong>Description:</strong> {data.description}</p> | ||
<p><strong>Timestamp:</strong> {new Date(data.timestamp).toLocaleString()}</p> | ||
<p><strong>Signed Message:</strong> {`0x${data.signedMessage.slice(2, 6)}....${data.signedMessage.slice(-6)}`}</p> | ||
<p><strong>Parent Block:</strong> {data.parentBlockUUID || 'Root'}</p> | ||
<p><strong>Signatures:</strong></p> | ||
<ul> | ||
{data.signatures.map((sig, index) => ( | ||
<SignatureItem key={index} address={sig.address} /> | ||
))} | ||
</ul> | ||
</div> | ||
<input | ||
type="text" | ||
value={shareableLink} | ||
readOnly | ||
className="w-full p-2 border rounded" | ||
/> | ||
{onSign && <Button onClick={onSign}>Sign This Block</Button>} | ||
<QRCodeSVG value={text} size={Math.min(width, height)} /> | ||
</div> | ||
); | ||
}; | ||
|
||
const SignatureItem: React.FC<{ address: `0x${string}` }> = ({ address }) => { | ||
const { data: ensName } = useEnsName({ address }); | ||
|
||
return ( | ||
<li> | ||
{ensName || `${address.slice(0, 6)}...${address.slice(-4)}`} | ||
</li> | ||
); | ||
}; | ||
|
||
export default QRCode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters