"use client"; import React, { useState, useEffect } from 'react'; import { RLNStatusIndicator } from '../../RLNStatusIndicator'; import { KeystoreEntity } from '@waku/rln'; import { useRLN } from '../../../contexts/rln/RLNContext'; import { useWallet } from '../../../contexts/wallet'; import { TerminalWindow } from '../../ui/terminal-window'; import { ToggleGroup, ToggleGroupItem } from '../../ui/toggle-group'; import { Button } from '../../ui/button'; import { membershipRegistration, type ContentSegment } from '../../../content/index'; import { toast } from 'sonner'; import { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } from '../../ui/tooltip'; interface MembershipRegistrationProps { tabId?: string; } // eslint-disable-next-line @typescript-eslint/no-unused-vars export function MembershipRegistration({ tabId: _tabId }: MembershipRegistrationProps) { const { registerMembership, isInitialized, isStarted, error, isLoading } = useRLN(); const { isConnected, chainId } = useWallet(); // Replace slider state with discrete options const [rateLimit, setRateLimit] = useState(300); // Default to Standard const [isRegistering, setIsRegistering] = useState(false); const [saveToKeystore, setSaveToKeystore] = useState(true); const [keystorePassword, setKeystorePassword] = useState(''); const [registrationResult, setRegistrationResult] = useState<{ success?: boolean; error?: string; txHash?: string; warning?: string; credentials?: KeystoreEntity; keystoreHash?: string; }>({}); const isLineaSepolia = chainId === 59141; useEffect(() => { if (error) { toast.error(error); } }, [error]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!isConnected) { setRegistrationResult({ success: false, error: 'Please connect your wallet first' }); return; } if (!isInitialized || !isStarted) { setRegistrationResult({ success: false, error: 'RLN is not initialized' }); return; } if (!isLineaSepolia) { setRegistrationResult({ success: false, error: 'Please switch to Linea Sepolia network' }); return; } // Validate keystore password if saving to keystore if (saveToKeystore && keystorePassword.length < 8) { setRegistrationResult({ success: false, error: 'Keystore password must be at least 8 characters long' }); return; } setIsRegistering(true); setRegistrationResult({}); try { setRegistrationResult({ success: undefined, warning: 'Please check your wallet to sign the registration message.' }); // Pass save options if saving to keystore const saveOptions = saveToKeystore ? { password: keystorePassword } : undefined; const result = await registerMembership(rateLimit, saveOptions); setRegistrationResult({ ...result, credentials: result.credentials }); // Clear password field after successful registration if (result.success) { setKeystorePassword(''); } } catch (error) { setRegistrationResult({ success: false, error: error instanceof Error ? error.message : 'Registration failed' }); } finally { setIsRegistering(false); } }; return (

{membershipRegistration.title}

{/* Network Warning */} {isConnected && !isLineaSepolia && (

⚠️ {membershipRegistration.networkWarning}

)} {/* Informational Box */}
{">"}

{membershipRegistration.infoHeader}

{membershipRegistration.aboutTitle}

{membershipRegistration.about.map((paragraph: ContentSegment[], i: number) => (

{paragraph.map((segment: ContentSegment, j: number) => ( segment.type === 'link' ? ( {segment.content} ) : ( {segment.content} ) ))}

))}
{!isConnected ? (
ℹ️ {membershipRegistration.connectWalletPrompt}
) : !isInitialized || !isStarted ? (
ℹ️ {isLoading ? 'Initializing RLN...' : membershipRegistration.initializePrompt}
) : (
{ if (value === '300' || value === '600') setRateLimit(Number(value)); }} className="w-full" > Standard (300) lower deposit Max (600) requires higher deposit. more messages.
setSaveToKeystore(e.target.checked)} className="h-4 w-4 rounded bg-terminal-background border-terminal-border text-primary focus:ring-primary" />
{saveToKeystore && (
setKeystorePassword(e.target.value)} placeholder={membershipRegistration.form.passwordPlaceholder} className="w-full px-3 py-2 bg-terminal-background border border-terminal-border rounded-md text-sm font-mono focus:outline-none focus:ring-2 focus:ring-primary" />
)}
)}
{/* Registration Result */} {registrationResult.warning && (

⚠️ {registrationResult.warning}

)} {registrationResult.error && (

⚠️ {registrationResult.error}

)} {registrationResult.success && (

Membership registered successfully!

{registrationResult.txHash && (

Transaction Hash: {registrationResult.txHash}

)}
)}
); }