From 9e6be6156f033324c42245bc76a4f00576957e2f Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Fri, 5 Sep 2025 13:41:37 +0530 Subject: [PATCH] chore: update verification status enum --- src/components/FeedSidebar.tsx | 9 +- src/components/Header.tsx | 36 +-- src/components/PostList.tsx | 30 ++- src/components/examples/HookDemoComponent.tsx | 7 +- src/components/ui/delegation-step.tsx | 21 +- src/components/ui/verification-step.tsx | 3 +- src/components/ui/wallet-wizard.tsx | 26 +- src/contexts/AuthContext.tsx | 56 ++-- src/contexts/ForumContext.tsx | 2 +- src/hooks/actions/useAuthActions.ts | 69 ++--- src/hooks/actions/useForumActions.ts | 17 +- src/hooks/actions/useUserActions.ts | 6 +- src/hooks/core/useAuth.ts | 64 ++++- src/hooks/core/useEnhancedAuth.ts | 248 ----------------- src/hooks/core/useEnhancedUserDisplay.ts | 10 +- src/hooks/core/useForumData.ts | 6 +- src/hooks/core/usePermissions.ts | 159 +++++++++++ src/hooks/derived/useCell.ts | 9 +- src/hooks/derived/useCellPosts.ts | 2 +- src/hooks/derived/usePost.ts | 2 +- src/hooks/derived/usePostComments.ts | 2 +- src/hooks/derived/useUserVotes.ts | 2 +- src/hooks/index.ts | 14 +- src/hooks/utilities/useNetworkStatus.ts | 41 ++- src/hooks/utilities/usePermissions.ts | 254 ------------------ src/lib/database/LocalDatabase.ts | 2 +- src/lib/forum/ForumActions.ts | 178 ++++++------ src/lib/forum/RelevanceCalculator.ts | 13 +- src/lib/forum/__tests__/relevance.test.ts | 10 +- src/lib/services/UserIdentityService.ts | 14 +- src/pages/FeedPage.tsx | 4 +- src/pages/ProfilePage.tsx | 98 ++++--- src/types/identity.ts | 7 +- 33 files changed, 581 insertions(+), 840 deletions(-) delete mode 100644 src/hooks/core/useEnhancedAuth.ts create mode 100644 src/hooks/core/usePermissions.ts delete mode 100644 src/hooks/utilities/usePermissions.ts diff --git a/src/components/FeedSidebar.tsx b/src/components/FeedSidebar.tsx index dfd4be4..fb837d5 100644 --- a/src/components/FeedSidebar.tsx +++ b/src/components/FeedSidebar.tsx @@ -5,6 +5,7 @@ import { TrendingUp, Users, Eye } from 'lucide-react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { useForumData, useForumSelectors, useAuth } from '@/hooks'; +import { EVerificationStatus } from '@/types/identity'; import { CypherImage } from '@/components/ui/CypherImage'; import { useUserDisplay } from '@/hooks'; @@ -29,9 +30,9 @@ const FeedSidebar: React.FC = () => { // User's verification status display const getVerificationBadge = () => { - if (verificationStatus.level === 'verified-owner') { + if (verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED) { return { text: 'Verified Owner', color: 'bg-green-500' }; - } else if (verificationStatus.level === 'verified-basic') { + } else if (verificationStatus === EVerificationStatus.WALLET_CONNECTED) { return { text: 'Verified', color: 'bg-blue-500' }; } else if (ensName) { return { text: 'ENS User', color: 'bg-purple-500' }; @@ -67,14 +68,14 @@ const FeedSidebar: React.FC = () => { - {verificationStatus.level === 'unverified' && ( + {verificationStatus === EVerificationStatus.WALLET_UNCONNECTED && (
Read-only mode. Verify wallet to participate.
)} - {verificationStatus.level === 'verified-basic' && + {verificationStatus === EVerificationStatus.WALLET_CONNECTED && !ordinalDetails && (
diff --git a/src/components/Header.tsx b/src/components/Header.tsx index eb4cdd3..2d5cbb1 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -1,6 +1,8 @@ import React, { useState } from 'react'; import { Link, useLocation } from 'react-router-dom'; import { useAuth, useNetworkStatus } from '@/hooks'; +import { useAuth as useAuthContext } from '@/contexts/useAuth'; +import { EVerificationStatus } from '@/types/identity'; import { useForum } from '@/contexts/useForum'; import { Button } from '@/components/ui/button'; @@ -27,7 +29,9 @@ import { WalletWizard } from '@/components/ui/wallet-wizard'; import { useUserDisplay } from '@/hooks'; const Header = () => { - const { verificationStatus, delegationInfo } = useAuth(); + const { verificationStatus } = useAuth(); + const { getDelegationStatus } = useAuthContext(); + const delegationInfo = getDelegationStatus(); const networkStatus = useNetworkStatus(); const location = useLocation(); const { toast } = useToast(); @@ -94,14 +98,10 @@ const Header = () => { const getAccountStatusText = () => { if (!isConnected) return 'Connect Wallet'; - if (verificationStatus.level === 'verified-owner') { - return delegationInfo.isActive ? 'Ready to Post' : 'Delegation Expired'; - } else if (verificationStatus.level === 'verified-basic') { + if (verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED) { + return delegationInfo.isValid ? 'Ready to Post' : 'Delegation Expired'; + } else if (verificationStatus === EVerificationStatus.WALLET_CONNECTED) { return 'Verified (Read-only)'; - } else if (verificationStatus.level === 'unverified') { - return verificationStatus.hasOrdinal - ? 'Verify Wallet' - : 'No Ordinals Found'; } else { return 'Verify Wallet'; } @@ -111,13 +111,15 @@ const Header = () => { if (!isConnected) return 'text-red-400'; if ( - verificationStatus.level === 'verified-owner' && - delegationInfo.isActive + verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED && + delegationInfo.isValid ) { return 'text-green-400'; - } else if (verificationStatus.level === 'verified-basic') { + } else if (verificationStatus === EVerificationStatus.WALLET_CONNECTED) { return 'text-yellow-400'; - } else if (verificationStatus.hasOrdinal || verificationStatus.hasENS) { + } else if ( + verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED + ) { return 'text-orange-400'; } else { return 'text-red-400'; @@ -128,13 +130,15 @@ const Header = () => { if (!isConnected) return ; if ( - verificationStatus.level === 'verified-owner' && - delegationInfo.isActive + verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED && + delegationInfo.isValid ) { return ; - } else if (verificationStatus.level === 'verified-basic') { + } else if (verificationStatus === EVerificationStatus.WALLET_CONNECTED) { return ; - } else if (verificationStatus.hasOrdinal || verificationStatus.hasENS) { + } else if ( + verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED + ) { return ; } else { return ; diff --git a/src/components/PostList.tsx b/src/components/PostList.tsx index 0d12407..6edca69 100644 --- a/src/components/PostList.tsx +++ b/src/components/PostList.tsx @@ -8,6 +8,7 @@ import { useUserVotes, useAuth, } from '@/hooks'; +import { EVerificationStatus } from '@/types/identity'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Textarea } from '@/components/ui/textarea'; @@ -218,21 +219,22 @@ const PostList = () => {
)} - {!canPost && verificationStatus.level === 'verified-basic' && ( -
-
- -

Read-Only Mode

+ {!canPost && + verificationStatus === EVerificationStatus.WALLET_CONNECTED && ( +
+
+ +

Read-Only Mode

+
+

+ Your wallet does not contain any Ordinal Operators. You can browse + threads but cannot post or interact. +

+ + No Ordinals Found +
-

- Your wallet does not contain any Ordinal Operators. You can browse - threads but cannot post or interact. -

- - No Ordinals Found - -
- )} + )} {!canPost && !currentUser && (
diff --git a/src/components/examples/HookDemoComponent.tsx b/src/components/examples/HookDemoComponent.tsx index f8fea2b..44834f2 100644 --- a/src/components/examples/HookDemoComponent.tsx +++ b/src/components/examples/HookDemoComponent.tsx @@ -9,6 +9,7 @@ import { useNetworkStatus, useForumSelectors, } from '@/hooks'; +import { useAuth as useAuthContext } from '@/contexts/useAuth'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; @@ -22,6 +23,7 @@ export function HookDemoComponent() { // Core data hooks - reactive and optimized const forumData = useForumData(); const auth = useAuth(); + const { getDelegationStatus } = useAuthContext(); // Derived hooks for specific data const userVotes = useUserVotes(); @@ -131,12 +133,11 @@ export function HookDemoComponent() {
- Verification Level:{' '} - {auth.verificationStatus.level} + Verification Level: {auth.verificationStatus}
Delegation Active:{' '} - {auth.delegationInfo.isActive ? 'Yes' : 'No'} + {getDelegationStatus().isValid ? 'Yes' : 'No'}
diff --git a/src/components/ui/delegation-step.tsx b/src/components/ui/delegation-step.tsx index 4bb21b4..74feab5 100644 --- a/src/components/ui/delegation-step.tsx +++ b/src/components/ui/delegation-step.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { Button } from './button'; import { useAuth, useAuthActions } from '@/hooks'; +import { useAuth as useAuthContext } from '@/contexts/useAuth'; import { CheckCircle, AlertCircle, Trash2 } from 'lucide-react'; import { DelegationDuration } from '@/lib/delegation'; @@ -17,7 +18,9 @@ export function DelegationStep({ isLoading, setIsLoading, }: DelegationStepProps) { - const { currentUser, delegationInfo, isAuthenticating } = useAuth(); + const { currentUser, isAuthenticating } = useAuth(); + const { getDelegationStatus } = useAuthContext(); + const delegationInfo = getDelegationStatus(); const { delegateKey, clearDelegation } = useAuthActions(); const [selectedDuration, setSelectedDuration] = @@ -125,19 +128,19 @@ export function DelegationStep({
{/* Status */}
- {delegationInfo.isActive ? ( + {delegationInfo.isValid ? ( ) : ( )} - {delegationInfo.isActive ? 'Delegated' : 'Required'} + {delegationInfo.isValid ? 'Delegated' : 'Required'} - {delegationInfo.isActive && delegationInfo.timeRemaining && ( + {delegationInfo.isValid && delegationInfo.timeRemaining && ( {delegationInfo.timeRemaining} remaining @@ -145,7 +148,7 @@ export function DelegationStep({
{/* Duration Selection */} - {!delegationInfo.isActive && ( + {!delegationInfo.isValid && (