@@ -11,10 +11,11 @@ import { v4 as uuidv4 } from 'uuid';
1111
1212interface SignChainProps {
1313 block : BlockPayload ;
14+ chainsData : BlockPayload [ ] ; // Add this prop
1415 onSuccess : ( newBlock : BlockPayload ) => void ;
1516}
1617
17- const SignChain : React . FC < SignChainProps > = ( { block, onSuccess } ) => {
18+ const SignChain : React . FC < SignChainProps > = ( { block, chainsData , onSuccess } ) => {
1819 const [ isOpen , setIsOpen ] = useState ( false ) ;
1920 const [ isSigning , setIsSigning ] = useState ( false ) ;
2021 const [ error , setError ] = useState < string | null > ( null ) ;
@@ -25,17 +26,37 @@ const SignChain: React.FC<SignChainProps> = ({ block, onSuccess }) => {
2526
2627 useEffect ( ( ) => {
2728 if ( address ) {
28- const hasAlreadySigned = block . signatures . some ( sig => sig . address . toLowerCase ( ) === address . toLowerCase ( ) ) ;
29+ // Check if the address has signed this block or any blocks in the chain
30+ const checkSignatures = ( blockToCheck : BlockPayload ) : boolean => {
31+ // Check current block's signatures
32+ if ( blockToCheck . signatures . some (
33+ sig => sig . address . toLowerCase ( ) === address . toLowerCase ( )
34+ ) ) {
35+ return true ;
36+ }
37+
38+ // Check parent blocks
39+ const parentBlock = chainsData . find ( b => b . blockUUID === blockToCheck . parentBlockUUID ) ;
40+ if ( parentBlock && checkSignatures ( parentBlock ) ) {
41+ return true ;
42+ }
43+
44+ // Check child blocks
45+ const childBlocks = chainsData . filter ( b => b . parentBlockUUID === blockToCheck . blockUUID ) ;
46+ return childBlocks . some ( childBlock => checkSignatures ( childBlock ) ) ;
47+ } ;
48+
49+ const hasAlreadySigned = checkSignatures ( block ) ;
2950 setAlreadySigned ( hasAlreadySigned ) ;
3051 }
31- } , [ address , block . signatures ] ) ;
52+ } , [ address , block , chainsData ] ) ;
3253
3354 const { signMessage } = useSignMessage ( {
3455 mutation : {
3556 async onSuccess ( signature ) {
3657 if ( ! address || ! node ) return ;
3758
38- // Check if the address has already signed
59+ // Double check signature before proceeding
3960 if ( block . signatures . some ( sig => sig . address . toLowerCase ( ) === address . toLowerCase ( ) ) ) {
4061 setError ( 'You have already signed this chain.' ) ;
4162 setIsSigning ( false ) ;
@@ -79,6 +100,7 @@ const SignChain: React.FC<SignChainProps> = ({ block, onSuccess }) => {
79100 } ) ;
80101
81102 const handleSign = ( ) => {
103+ // Add an additional check here before signing
82104 if ( alreadySigned ) {
83105 setError ( 'You have already signed this chain.' ) ;
84106 return ;
@@ -102,7 +124,7 @@ const SignChain: React.FC<SignChainProps> = ({ block, onSuccess }) => {
102124 { alreadySigned ? 'Already Signed' : 'Sign Chain' }
103125 </ Button >
104126 < Dialog open = { isOpen } onOpenChange = { setIsOpen } >
105- < DialogContent >
127+ < DialogContent className = "sm:max-w-md" >
106128 < DialogHeader >
107129 < DialogTitle > Sign Chain</ DialogTitle >
108130 < DialogDescription >
@@ -111,7 +133,14 @@ const SignChain: React.FC<SignChainProps> = ({ block, onSuccess }) => {
111133 : 'Review the block details and sign to add your signature to the chain.' }
112134 </ DialogDescription >
113135 </ DialogHeader >
114- < QRCode data = { block } />
136+ < div className = "flex flex-col space-y-4" >
137+ < div className = "space-y-2" >
138+ < h4 className = "font-medium" > Block Details</ h4 >
139+ < p className = "text-sm text-muted-foreground" > { block . title } </ p >
140+ < p className = "text-sm text-muted-foreground" > { block . description } </ p >
141+ </ div >
142+ < QRCode text = { `${ window . location . origin } /sign/${ block . chainUUID } /${ block . blockUUID } ` } />
143+ </ div >
115144 { error && < p className = "text-sm text-destructive" > { error } </ p > }
116145 < DialogFooter >
117146 < Button variant = "secondary" onClick = { ( ) => setIsOpen ( false ) } > Cancel</ Button >
0 commit comments