mirror of
https://github.com/logos-messaging/lab.waku.org.git
synced 2026-01-08 08:43:12 +00:00
chore: remove loading credentials
This commit is contained in:
parent
cb5f76021e
commit
ecb136a612
@ -12,16 +12,6 @@ export function RLNImplementationToggle() {
|
|||||||
RLN Implementation
|
RLN Implementation
|
||||||
</label>
|
</label>
|
||||||
<div className="flex space-x-4">
|
<div className="flex space-x-4">
|
||||||
<button
|
|
||||||
onClick={() => setImplementation('standard')}
|
|
||||||
className={`px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
|
|
||||||
implementation === 'standard'
|
|
||||||
? 'bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300'
|
|
||||||
: 'bg-gray-100 text-gray-700 hover:bg-gray-200 dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
Standard
|
|
||||||
</button>
|
|
||||||
<button
|
<button
|
||||||
onClick={() => setImplementation('light')}
|
onClick={() => setImplementation('light')}
|
||||||
className={`px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
|
className={`px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
|
||||||
@ -32,11 +22,21 @@ export function RLNImplementationToggle() {
|
|||||||
>
|
>
|
||||||
Light
|
Light
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => setImplementation('standard')}
|
||||||
|
className={`px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
|
||||||
|
implementation === 'standard'
|
||||||
|
? 'bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300'
|
||||||
|
: 'bg-gray-100 text-gray-700 hover:bg-gray-200 dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
Standard
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-gray-500 dark:text-gray-400">
|
<p className="text-xs text-gray-500 dark:text-gray-400">
|
||||||
{implementation === 'standard'
|
{implementation === 'light'
|
||||||
? 'Standard implementation with full security features'
|
? 'Light implementation, without Zerokit. Instant initalisation.'
|
||||||
: 'Light implementation with optimized performance'
|
: 'Standard implementation, with Zerokit. Initialisation takes 10-15 seconds for WASM module'
|
||||||
}
|
}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import React from 'react';
|
|||||||
import { useRLN } from '../contexts/rln';
|
import { useRLN } from '../contexts/rln';
|
||||||
|
|
||||||
export function RLNInitButton() {
|
export function RLNInitButton() {
|
||||||
const { initializeRLN, isInitialized, isStarted, error } = useRLN();
|
const { initializeRLN, isInitialized, isStarted, error, isLoading } = useRLN();
|
||||||
|
|
||||||
const handleInitialize = async () => {
|
const handleInitialize = async () => {
|
||||||
try {
|
try {
|
||||||
@ -14,18 +14,46 @@ export function RLNInitButton() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getButtonText = () => {
|
||||||
|
if (isLoading) return 'Initializing...';
|
||||||
|
if (isInitialized && isStarted) return 'RLN Initialized';
|
||||||
|
return 'Initialize RLN';
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-start gap-2">
|
<div className="flex flex-col items-start gap-2">
|
||||||
<button
|
<button
|
||||||
onClick={handleInitialize}
|
onClick={handleInitialize}
|
||||||
disabled={isInitialized && isStarted}
|
disabled={isLoading || (isInitialized && isStarted)}
|
||||||
className={`px-4 py-2 rounded-lg font-medium transition-colors ${
|
className={`
|
||||||
isInitialized && isStarted
|
px-4 py-2 rounded-lg font-medium transition-colors relative
|
||||||
? 'bg-gray-200 text-gray-500 cursor-not-allowed dark:bg-gray-700 dark:text-gray-400'
|
${
|
||||||
: 'bg-blue-600 text-white hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-600'
|
isLoading
|
||||||
}`}
|
? 'bg-gray-200 text-gray-500 cursor-not-allowed dark:bg-gray-700 dark:text-gray-400'
|
||||||
|
: isInitialized && isStarted
|
||||||
|
? 'bg-green-600 text-white cursor-default dark:bg-green-500'
|
||||||
|
: 'bg-blue-600 text-white hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-600'
|
||||||
|
}
|
||||||
|
`}
|
||||||
>
|
>
|
||||||
{isInitialized && isStarted ? 'RLN Initialized' : 'Initialize RLN'}
|
{isLoading && (
|
||||||
|
<span className="absolute left-2 top-1/2 -translate-y-1/2">
|
||||||
|
<svg className="animate-spin h-5 w-5 text-current" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
||||||
|
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
|
||||||
|
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{isInitialized && isStarted && (
|
||||||
|
<span className="absolute left-2 top-1/2 -translate-y-1/2">
|
||||||
|
<svg className="h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||||
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<span className={(isLoading || (isInitialized && isStarted)) ? 'pl-7' : ''}>
|
||||||
|
{getButtonText()}
|
||||||
|
</span>
|
||||||
</button>
|
</button>
|
||||||
{error && (
|
{error && (
|
||||||
<p className="text-sm text-red-600 dark:text-red-400">
|
<p className="text-sm text-red-600 dark:text-red-400">
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useEffect, useState } from 'react';
|
import React from 'react';
|
||||||
import { useKeystore } from '../../../contexts/keystore';
|
import { useKeystore } from '../../../contexts/keystore';
|
||||||
import { useAppState } from '../../../contexts/AppStateContext';
|
import { useAppState } from '../../../contexts/AppStateContext';
|
||||||
import { useRLN } from '../../../contexts/rln';
|
import { useRLN } from '../../../contexts/rln';
|
||||||
import { saveKeystoreToFile, readKeystoreFromFile } from '../../../utils/fileUtils';
|
import { saveKeystoreToFile, readKeystoreFromFile } from '../../../utils/fileUtils';
|
||||||
import { KeystoreEntity } from '@waku/rln';
|
|
||||||
|
|
||||||
export function KeystoreManagement() {
|
export function KeystoreManagement() {
|
||||||
const {
|
const {
|
||||||
@ -14,20 +13,12 @@ export function KeystoreManagement() {
|
|||||||
error,
|
error,
|
||||||
exportKeystore,
|
exportKeystore,
|
||||||
importKeystore,
|
importKeystore,
|
||||||
removeCredential,
|
removeCredential
|
||||||
loadCredential
|
|
||||||
} = useKeystore();
|
} = useKeystore();
|
||||||
const { setGlobalError } = useAppState();
|
const { setGlobalError } = useAppState();
|
||||||
const { isInitialized, isStarted } = useRLN();
|
const { isInitialized, isStarted } = useRLN();
|
||||||
|
|
||||||
const [selectedHash, setSelectedHash] = useState<string | null>(null);
|
React.useEffect(() => {
|
||||||
const [password, setPassword] = useState('');
|
|
||||||
const [loadingCredential, setLoadingCredential] = useState(false);
|
|
||||||
const [loadError, setLoadError] = useState<string | null>(null);
|
|
||||||
const [loadedCredential, setLoadedCredential] = useState<KeystoreEntity | null>(null);
|
|
||||||
const [showSuccess, setShowSuccess] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (error) {
|
if (error) {
|
||||||
setGlobalError(error);
|
setGlobalError(error);
|
||||||
}
|
}
|
||||||
@ -57,52 +48,11 @@ export function KeystoreManagement() {
|
|||||||
const handleRemoveCredential = (hash: string) => {
|
const handleRemoveCredential = (hash: string) => {
|
||||||
try {
|
try {
|
||||||
removeCredential(hash);
|
removeCredential(hash);
|
||||||
if (selectedHash === hash) {
|
|
||||||
setSelectedHash(null);
|
|
||||||
setPassword('');
|
|
||||||
setLoadedCredential(null);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setGlobalError(err instanceof Error ? err.message : 'Failed to remove credential');
|
setGlobalError(err instanceof Error ? err.message : 'Failed to remove credential');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleLoadCredential = async (hash: string) => {
|
|
||||||
if (!password) {
|
|
||||||
setLoadError('Please enter a password');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isInitialized || !isStarted) {
|
|
||||||
setLoadError('Please initialize RLN first');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setLoadingCredential(true);
|
|
||||||
setLoadError(null);
|
|
||||||
setShowSuccess(false);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const credential = await loadCredential(hash, password);
|
|
||||||
if (credential) {
|
|
||||||
setLoadedCredential(credential);
|
|
||||||
setLoadError(null);
|
|
||||||
setPassword('');
|
|
||||||
setShowSuccess(true);
|
|
||||||
// Auto-hide success message after 3 seconds
|
|
||||||
setTimeout(() => setShowSuccess(false), 3000);
|
|
||||||
} else {
|
|
||||||
setLoadError('Failed to load credential');
|
|
||||||
setLoadedCredential(null);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
setLoadError(err instanceof Error ? err.message : 'Failed to load credential');
|
|
||||||
setLoadedCredential(null);
|
|
||||||
} finally {
|
|
||||||
setLoadingCredential(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<div className="bg-white dark:bg-gray-800 shadow sm:rounded-lg p-6">
|
<div className="bg-white dark:bg-gray-800 shadow sm:rounded-lg p-6">
|
||||||
@ -131,39 +81,11 @@ export function KeystoreManagement() {
|
|||||||
{!isInitialized || !isStarted ? (
|
{!isInitialized || !isStarted ? (
|
||||||
<div className="bg-yellow-50 dark:bg-yellow-900 p-4 rounded-lg">
|
<div className="bg-yellow-50 dark:bg-yellow-900 p-4 rounded-lg">
|
||||||
<p className="text-sm text-yellow-700 dark:text-yellow-300">
|
<p className="text-sm text-yellow-700 dark:text-yellow-300">
|
||||||
⚠️ Please initialize RLN before loading credentials
|
⚠️ Please initialize RLN before managing credentials
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* Loaded Credential Info */}
|
|
||||||
{loadedCredential && (
|
|
||||||
<div className="bg-gray-50 dark:bg-gray-900 p-4 rounded-lg border border-gray-200 dark:border-gray-700">
|
|
||||||
<h4 className="text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
|
||||||
Currently Loaded Credential
|
|
||||||
</h4>
|
|
||||||
<div className="space-y-2">
|
|
||||||
<p className="text-sm text-gray-600 dark:text-gray-400">
|
|
||||||
<span className="font-medium">Hash:</span>{' '}
|
|
||||||
<code className="break-all">{selectedHash}</code>
|
|
||||||
</p>
|
|
||||||
<p className="text-sm text-gray-600 dark:text-gray-400">
|
|
||||||
<span className="font-medium">Status:</span>{' '}
|
|
||||||
<span className="text-green-600 dark:text-green-400">Active</span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Success Message */}
|
|
||||||
{showSuccess && (
|
|
||||||
<div className="bg-green-50 dark:bg-green-900 p-4 rounded-lg">
|
|
||||||
<p className="text-sm text-green-700 dark:text-green-300">
|
|
||||||
✓ Credential loaded successfully
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Stored Credentials */}
|
{/* Stored Credentials */}
|
||||||
<div className="border-t border-gray-200 dark:border-gray-700 pt-6">
|
<div className="border-t border-gray-200 dark:border-gray-700 pt-6">
|
||||||
<h3 className="text-sm font-medium text-gray-700 dark:text-gray-300 mb-4">
|
<h3 className="text-sm font-medium text-gray-700 dark:text-gray-300 mb-4">
|
||||||
@ -175,73 +97,25 @@ export function KeystoreManagement() {
|
|||||||
{storedCredentialsHashes.map((hash) => (
|
{storedCredentialsHashes.map((hash) => (
|
||||||
<div
|
<div
|
||||||
key={hash}
|
key={hash}
|
||||||
className={`p-4 rounded-lg border ${
|
className="p-4 rounded-lg border border-gray-200 dark:border-gray-700"
|
||||||
selectedHash === hash
|
|
||||||
? 'border-blue-500 dark:border-blue-400'
|
|
||||||
: 'border-gray-200 dark:border-gray-700'
|
|
||||||
}`}
|
|
||||||
>
|
>
|
||||||
<div className="flex items-start justify-between">
|
<div className="flex items-start justify-between">
|
||||||
<div className="space-y-1">
|
<code className="text-sm text-gray-600 dark:text-gray-400 break-all">
|
||||||
<code className="text-sm text-gray-600 dark:text-gray-400 break-all">
|
{hash}
|
||||||
{hash}
|
</code>
|
||||||
</code>
|
<button
|
||||||
{selectedHash === hash && (
|
onClick={() => handleRemoveCredential(hash)}
|
||||||
<div className="pt-3 space-y-3">
|
className="ml-4 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300"
|
||||||
<input
|
>
|
||||||
type="password"
|
Remove
|
||||||
value={password}
|
</button>
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
|
||||||
placeholder="Enter password to load credential"
|
|
||||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100"
|
|
||||||
/>
|
|
||||||
{loadError && (
|
|
||||||
<p className="text-sm text-red-600 dark:text-red-400">
|
|
||||||
{loadError}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className="flex space-x-2">
|
|
||||||
<button
|
|
||||||
onClick={() => {
|
|
||||||
if (selectedHash === hash) {
|
|
||||||
setSelectedHash(null);
|
|
||||||
setPassword('');
|
|
||||||
setLoadedCredential(null);
|
|
||||||
} else {
|
|
||||||
setSelectedHash(hash);
|
|
||||||
setPassword('');
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
className="px-3 py-1 text-sm bg-blue-100 text-blue-700 rounded-md hover:bg-blue-200 dark:bg-blue-900 dark:text-blue-300 dark:hover:bg-blue-800"
|
|
||||||
>
|
|
||||||
{selectedHash === hash ? 'Cancel' : 'Load'}
|
|
||||||
</button>
|
|
||||||
{selectedHash === hash && (
|
|
||||||
<button
|
|
||||||
onClick={() => handleLoadCredential(hash)}
|
|
||||||
disabled={loadingCredential || !isInitialized || !isStarted}
|
|
||||||
className="px-3 py-1 text-sm bg-green-100 text-green-700 rounded-md hover:bg-green-200 dark:bg-green-900 dark:text-green-300 dark:hover:bg-green-800 disabled:opacity-50 disabled:cursor-not-allowed"
|
|
||||||
>
|
|
||||||
{loadingCredential ? 'Loading...' : 'Confirm'}
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
<button
|
|
||||||
onClick={() => handleRemoveCredential(hash)}
|
|
||||||
className="px-3 py-1 text-sm bg-red-100 text-red-700 rounded-md hover:bg-red-200 dark:bg-red-900 dark:text-red-300 dark:hover:bg-red-800"
|
|
||||||
>
|
|
||||||
Remove
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<p className="text-sm text-gray-500 dark:text-gray-400">
|
<p className="text-sm text-gray-500 dark:text-gray-400">
|
||||||
No credentials stored yet.
|
No credentials stored
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -139,11 +139,6 @@ export function MembershipRegistration() {
|
|||||||
|
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<RLNInitButton />
|
<RLNInitButton />
|
||||||
{isInitialized && isStarted && (
|
|
||||||
<span className="text-sm text-green-600 dark:text-green-400">
|
|
||||||
✓ RLN Initialized
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!isConnected ? (
|
{!isConnected ? (
|
||||||
|
|||||||
@ -11,7 +11,6 @@ interface KeystoreContextType {
|
|||||||
hasStoredCredentials: boolean;
|
hasStoredCredentials: boolean;
|
||||||
storedCredentialsHashes: string[];
|
storedCredentialsHashes: string[];
|
||||||
saveCredentials: (credentials: KeystoreEntity, password: string) => Promise<string>;
|
saveCredentials: (credentials: KeystoreEntity, password: string) => Promise<string>;
|
||||||
loadCredential: (hash: string, password: string) => Promise<KeystoreEntity | undefined>;
|
|
||||||
exportKeystore: () => string;
|
exportKeystore: () => string;
|
||||||
importKeystore: (keystoreJson: string) => boolean;
|
importKeystore: (keystoreJson: string) => boolean;
|
||||||
removeCredential: (hash: string) => void;
|
removeCredential: (hash: string) => void;
|
||||||
@ -83,19 +82,6 @@ export function KeystoreProvider({ children }: { children: ReactNode }) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadCredential = async (hash: string, password: string): Promise<KeystoreEntity | undefined> => {
|
|
||||||
if (!keystore) {
|
|
||||||
throw new Error("Keystore not initialized");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return await keystore.readCredential(hash, password);
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Error loading credential:", err);
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const exportKeystore = (): string => {
|
const exportKeystore = (): string => {
|
||||||
if (!keystore) {
|
if (!keystore) {
|
||||||
throw new Error("Keystore not initialized");
|
throw new Error("Keystore not initialized");
|
||||||
@ -138,7 +124,6 @@ export function KeystoreProvider({ children }: { children: ReactNode }) {
|
|||||||
hasStoredCredentials: storedCredentialsHashes.length > 0,
|
hasStoredCredentials: storedCredentialsHashes.length > 0,
|
||||||
storedCredentialsHashes,
|
storedCredentialsHashes,
|
||||||
saveCredentials,
|
saveCredentials,
|
||||||
loadCredential,
|
|
||||||
exportKeystore,
|
exportKeystore,
|
||||||
importKeystore,
|
importKeystore,
|
||||||
removeCredential
|
removeCredential
|
||||||
|
|||||||
@ -25,6 +25,7 @@ interface RLNContextType {
|
|||||||
getCurrentRateLimit: () => Promise<number | null>;
|
getCurrentRateLimit: () => Promise<number | null>;
|
||||||
getRateLimitsBounds: () => Promise<{ success: boolean; rateMinLimit: number; rateMaxLimit: number; error?: string }>;
|
getRateLimitsBounds: () => Promise<{ success: boolean; rateMinLimit: number; rateMaxLimit: number; error?: string }>;
|
||||||
saveCredentialsToKeystore: (credentials: KeystoreEntity, password: string) => Promise<string>;
|
saveCredentialsToKeystore: (credentials: KeystoreEntity, password: string) => Promise<string>;
|
||||||
|
isLoading: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RLNContext = createContext<RLNContextType | undefined>(undefined);
|
const RLNContext = createContext<RLNContextType | undefined>(undefined);
|
||||||
@ -35,6 +36,7 @@ export function RLNProvider({ children }: { children: ReactNode }) {
|
|||||||
const [isInitialized, setIsInitialized] = useState(false);
|
const [isInitialized, setIsInitialized] = useState(false);
|
||||||
const [isStarted, setIsStarted] = useState(false);
|
const [isStarted, setIsStarted] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
// Get the signer from window.ethereum
|
// Get the signer from window.ethereum
|
||||||
const [signer, setSigner] = useState<ethers.Signer | null>(null);
|
const [signer, setSigner] = useState<ethers.Signer | null>(null);
|
||||||
@ -98,6 +100,7 @@ export function RLNProvider({ children }: { children: ReactNode }) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
setError(null);
|
setError(null);
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
if (!rln) {
|
if (!rln) {
|
||||||
console.log(`Creating RLN ${implementation} instance...`);
|
console.log(`Creating RLN ${implementation} instance...`);
|
||||||
@ -150,9 +153,19 @@ export function RLNProvider({ children }: { children: ReactNode }) {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error in initializeRLN:', err);
|
console.error('Error in initializeRLN:', err);
|
||||||
setError(err instanceof Error ? err.message : 'Failed to initialize RLN');
|
setError(err instanceof Error ? err.message : 'Failed to initialize RLN');
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
}, [isConnected, signer, implementation, rln, isStarted]);
|
}, [isConnected, signer, implementation, rln, isStarted]);
|
||||||
|
|
||||||
|
// Auto-initialize effect for Light implementation
|
||||||
|
useEffect(() => {
|
||||||
|
if (implementation === 'light' && isConnected && signer && !isInitialized && !isStarted && !isLoading) {
|
||||||
|
console.log('Auto-initializing Light RLN implementation...');
|
||||||
|
initializeRLN();
|
||||||
|
}
|
||||||
|
}, [implementation, isConnected, signer, isInitialized, isStarted, isLoading, initializeRLN]);
|
||||||
|
|
||||||
const getCurrentRateLimit = async (): Promise<number | null> => {
|
const getCurrentRateLimit = async (): Promise<number | null> => {
|
||||||
try {
|
try {
|
||||||
if (!rln || !rln.contract || !isStarted) {
|
if (!rln || !rln.contract || !isStarted) {
|
||||||
@ -339,7 +352,8 @@ export function RLNProvider({ children }: { children: ReactNode }) {
|
|||||||
rateMaxLimit,
|
rateMaxLimit,
|
||||||
getCurrentRateLimit,
|
getCurrentRateLimit,
|
||||||
getRateLimitsBounds,
|
getRateLimitsBounds,
|
||||||
saveCredentialsToKeystore
|
saveCredentialsToKeystore: saveToKeystore,
|
||||||
|
isLoading
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ interface RLNImplementationContextType {
|
|||||||
const RLNImplementationContext = createContext<RLNImplementationContextType | undefined>(undefined);
|
const RLNImplementationContext = createContext<RLNImplementationContextType | undefined>(undefined);
|
||||||
|
|
||||||
export function RLNImplementationProvider({ children }: { children: ReactNode }) {
|
export function RLNImplementationProvider({ children }: { children: ReactNode }) {
|
||||||
const [implementation, setImplementation] = useState<RLNImplementationType>('standard');
|
const [implementation, setImplementation] = useState<RLNImplementationType>('light');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RLNImplementationContext.Provider value={{ implementation, setImplementation }}>
|
<RLNImplementationContext.Provider value={{ implementation, setImplementation }}>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user