import { useAuth } from '@testinprod-io/privacy-boost-react';
import { createWalletRegistry } from '@testinprod-io/privacy-boost';
function AuthComponent() {
const {
isConnected,
isAuthenticated,
isWalletAvailable,
address,
privacyAddress,
authenticateInjected,
authenticate,
logout,
} = useAuth();
const [loading, setLoading] = useState(false);
const handleMetaMask = async () => {
setLoading(true);
try {
await authenticateInjected();
} catch (error) {
if (error.code !== 'WALLET_USER_REJECTED') {
alert('Connection failed');
}
} finally {
setLoading(false);
}
};
const handleWalletConnect = async () => {
setLoading(true);
try {
const registry = createWalletRegistry({
chains: [1],
walletConnect: { projectId: 'your-project-id' },
});
const adapter = registry.getAdapter('walletconnect');
await authenticate(adapter);
} finally {
setLoading(false);
}
};
if (isAuthenticated) {
return (
<div>
<p>Wallet: {address?.slice(0, 10)}...</p>
<p>Privacy: {privacyAddress?.slice(0, 20)}...</p>
<button onClick={logout}>Logout</button>
</div>
);
}
return (
<div>
<button
onClick={handleMetaMask}
disabled={loading || !isWalletAvailable}
>
MetaMask
</button>
<button onClick={handleWalletConnect} disabled={loading}>
WalletConnect
</button>
</div>
);
}