diff --git a/eslint.config.js b/eslint.config.js index e67846f..9c6c22e 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -23,7 +23,10 @@ export default tseslint.config( "warn", { allowConstantExport: true }, ], - "@typescript-eslint/no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": ["error", { + "argsIgnorePattern": "^_", + "varsIgnorePattern": "^_" + }], }, } ); diff --git a/src/components/ActivityFeed.tsx b/src/components/ActivityFeed.tsx index 94a7b46..ab1d03f 100644 --- a/src/components/ActivityFeed.tsx +++ b/src/components/ActivityFeed.tsx @@ -34,7 +34,7 @@ interface CommentFeedItem extends FeedItemBase { type FeedItem = PostFeedItem | CommentFeedItem; const ActivityFeed: React.FC = () => { - const { posts, comments, cells, getCellById, isInitialLoading, userVerificationStatus } = useForum(); + const { posts, comments, getCellById, isInitialLoading, userVerificationStatus } = useForum(); const combinedFeed: FeedItem[] = [ ...posts.map((post): PostFeedItem => ({ diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 7847df6..5dc44c2 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -4,7 +4,7 @@ import { useAuth } from '@/contexts/useAuth'; import { useForum } from '@/contexts/useForum'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; -import { LogOut, Terminal, Wifi, WifiOff, AlertTriangle, CheckCircle, Key, RefreshCw, CircleSlash, Home, Grid3X3, Plus } from 'lucide-react'; +import { LogOut, Terminal, Wifi, WifiOff, AlertTriangle, CheckCircle, Key, RefreshCw, CircleSlash, Home, Grid3X3} from 'lucide-react'; import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; import { useToast } from '@/components/ui/use-toast'; import { useAppKitAccount, useDisconnect } from '@reown/appkit/react'; @@ -13,12 +13,8 @@ import { WalletWizard } from '@/components/ui/wallet-wizard'; const Header = () => { const { currentUser, - isAuthenticated, verificationStatus, - verifyOwnership, - delegateKey, isDelegationValid, - delegationTimeRemaining } = useAuth(); const { isNetworkConnected, isRefreshing } = useForum(); const location = useLocation(); diff --git a/src/components/PostDetail.tsx b/src/components/PostDetail.tsx index 2175f98..65e7bc0 100644 --- a/src/components/PostDetail.tsx +++ b/src/components/PostDetail.tsx @@ -4,11 +4,10 @@ import { useForum } from '@/contexts/useForum'; import { useAuth } from '@/contexts/useAuth'; import { Button } from '@/components/ui/button'; import { Textarea } from '@/components/ui/textarea'; -import { ArrowLeft, ArrowUp, ArrowDown, Clock, MessageCircle, Send, RefreshCw, Eye, Loader2 } from 'lucide-react'; +import { ArrowLeft, ArrowUp, ArrowDown, Clock, MessageCircle, Send, Eye, Loader2 } from 'lucide-react'; import { formatDistanceToNow } from 'date-fns'; -import { Comment } from '@/types'; +import { Comment } from '@/types/forum'; import { CypherImage } from './ui/CypherImage'; -import { Badge } from '@/components/ui/badge'; import { RelevanceIndicator } from './ui/relevance-indicator'; import { AuthorDisplay } from './ui/author-display'; @@ -17,7 +16,6 @@ const PostDetail = () => { const navigate = useNavigate(); const { posts, - comments, getCommentsByPost, createComment, votePost, @@ -26,13 +24,11 @@ const PostDetail = () => { isInitialLoading, isPostingComment, isVoting, - isRefreshing, - refreshData, moderateComment, moderateUser, userVerificationStatus } = useForum(); - const { currentUser, isAuthenticated, verificationStatus } = useAuth(); + const { currentUser, verificationStatus } = useAuth(); const [newComment, setNewComment] = useState(''); if (!postId) return
Invalid post ID
; diff --git a/src/components/PostList.tsx b/src/components/PostList.tsx index 446a79e..3db8050 100644 --- a/src/components/PostList.tsx +++ b/src/components/PostList.tsx @@ -6,7 +6,7 @@ import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Textarea } from '@/components/ui/textarea'; import { Skeleton } from '@/components/ui/skeleton'; -import { ArrowLeft, MessageSquare, MessageCircle, ArrowUp, ArrowDown, Clock, RefreshCw, Eye } from 'lucide-react'; +import { ArrowLeft, MessageSquare, MessageCircle, ArrowUp, ArrowDown, RefreshCw, Eye } from 'lucide-react'; import { formatDistanceToNow } from 'date-fns'; import { CypherImage } from './ui/CypherImage'; import { Badge } from '@/components/ui/badge'; @@ -17,7 +17,6 @@ const PostList = () => { const { getCellById, getPostsByCell, - getCommentsByPost, createPost, isInitialLoading, isPostingPost, diff --git a/src/components/ui/delegation-step.tsx b/src/components/ui/delegation-step.tsx index d1821ef..0bbfca1 100644 --- a/src/components/ui/delegation-step.tsx +++ b/src/components/ui/delegation-step.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { Button } from './button'; import { useAuth } from '@/contexts/useAuth'; import { CheckCircle, AlertCircle, Trash2 } from 'lucide-react'; -import { DelegationDuration } from '@/lib/identity/services/CryptoService'; +import { DelegationDuration } from '@/lib/services/CryptoService'; interface DelegationStepProps { onComplete: () => void; @@ -61,7 +61,7 @@ export function DelegationStep({ } catch (error) { setDelegationResult({ success: false, - message: "Delegation failed. Please try again." + message: `Delegation failed. Please try again: ${error}` }); } finally { setIsLoading(false); @@ -72,10 +72,6 @@ export function DelegationStep({ onComplete(); }; - const handleRefresh = () => { - window.location.reload(); - }; - // Show delegation result if (delegationResult) { return ( diff --git a/src/components/ui/verification-step.tsx b/src/components/ui/verification-step.tsx index a33199e..3b50f9e 100644 --- a/src/components/ui/verification-step.tsx +++ b/src/components/ui/verification-step.tsx @@ -1,6 +1,5 @@ import * as React from "react"; import { Button } from "@/components/ui/button"; -import { Badge } from "@/components/ui/badge"; import { Bitcoin, Coins, Shield, ShieldCheck, Loader2, AlertCircle } from "lucide-react"; import { useAuth } from "@/contexts/useAuth"; import { useAppKitAccount } from "@reown/appkit/react"; @@ -31,7 +30,7 @@ export function VerificationStep({ const isBitcoinConnected = bitcoinAccount.isConnected; const isEthereumConnected = ethereumAccount.isConnected; - const walletType = isBitcoinConnected ? 'bitcoin' : 'ethereum'; + const walletType = isBitcoinConnected ? 'bitcoin' : isEthereumConnected ? 'ethereum' : undefined; const [verificationResult, setVerificationResult] = React.useState<{ success: boolean; @@ -69,7 +68,7 @@ export function VerificationStep({ } catch (error) { setVerificationResult({ success: false, - message: "Verification failed. Please try again." + message: `Verification failed. Please try again: ${error}` }); } finally { setIsLoading(false); diff --git a/src/components/ui/wallet-connection-step.tsx b/src/components/ui/wallet-connection-step.tsx index 154fe6f..bf33bbb 100644 --- a/src/components/ui/wallet-connection-step.tsx +++ b/src/components/ui/wallet-connection-step.tsx @@ -1,4 +1,3 @@ -import * as React from "react"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Bitcoin, Coins, Loader2 } from "lucide-react"; @@ -7,7 +6,6 @@ import { useAppKitAccount, useAppKitState } from "@reown/appkit/react"; -import { useAuth } from "@/contexts/useAuth"; interface WalletConnectionStepProps { onComplete: () => void; @@ -22,7 +20,6 @@ export function WalletConnectionStep({ }: WalletConnectionStepProps) { const { initialized } = useAppKitState(); const appKit = useAppKit(); - const { isAuthenticated } = useAuth(); // Get account info for different chains const bitcoinAccount = useAppKitAccount({ namespace: "bip122" }); diff --git a/src/components/ui/wallet-wizard.tsx b/src/components/ui/wallet-wizard.tsx index bc4e007..14793b5 100644 --- a/src/components/ui/wallet-wizard.tsx +++ b/src/components/ui/wallet-wizard.tsx @@ -28,7 +28,7 @@ export function WalletWizard({ }: WalletWizardProps) { const [currentStep, setCurrentStep] = React.useState(1); const [isLoading, setIsLoading] = React.useState(false); - const { currentUser, isAuthenticated, verificationStatus, isDelegationValid } = useAuth(); + const { isAuthenticated, verificationStatus, isDelegationValid } = useAuth(); const hasInitialized = React.useRef(false); // Reset wizard when opened and determine starting step diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index d14634a..09badfa 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -1,8 +1,8 @@ -import React, { createContext, useContext, useState, useEffect, useRef } from 'react'; +import React, { createContext, useState, useEffect, useRef } from 'react'; import { useToast } from '@/components/ui/use-toast'; import { User, OpchanMessage, EVerificationStatus } from '@/types/forum'; -import { AuthService, CryptoService, MessageService, DelegationDuration } from '@/lib/identity/services'; -import { AuthResult } from '@/lib/identity/services/AuthService'; +import { AuthService, CryptoService, DelegationDuration } from '@/lib/services'; +import { AuthResult } from '@/lib/services/AuthService'; import { useAppKitAccount, useDisconnect, modal } from '@reown/appkit/react'; export type VerificationStatus = 'unverified' | 'verified-none' | 'verified-basic' | 'verified-owner' | 'verifying'; @@ -49,7 +49,6 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { // Create service instances that persist between renders const cryptoServiceRef = useRef(new CryptoService()); const authServiceRef = useRef(new AuthService(cryptoServiceRef.current)); - const messageServiceRef = useRef(new MessageService(authServiceRef.current, cryptoServiceRef.current)); // Set AppKit instance and accounts in AuthService useEffect(() => { @@ -324,10 +323,6 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { }); }; - const isWalletAvailable = (): boolean => { - return isConnected; - }; - const messageSigning = { signMessage: async (message: OpchanMessage): Promise => { return cryptoServiceRef.current.signMessage(message); diff --git a/src/contexts/ForumContext.tsx b/src/contexts/ForumContext.tsx index 1b60471..305fff9 100644 --- a/src/contexts/ForumContext.tsx +++ b/src/contexts/ForumContext.tsx @@ -1,4 +1,4 @@ -import React, { createContext, useContext, useState, useEffect, useCallback, useMemo } from 'react'; +import React, { createContext, useState, useEffect, useCallback, useMemo } from 'react'; import { Cell, Post, Comment, OpchanMessage, User, EVerificationStatus } from '@/types/forum'; import { useToast } from '@/components/ui/use-toast'; import { useAuth } from '@/contexts/useAuth'; @@ -20,7 +20,7 @@ import messageManager from '@/lib/waku'; import { getDataFromCache } from '@/lib/forum/transformers'; import { RelevanceCalculator } from '@/lib/forum/relevance'; import { UserVerificationStatus } from '@/types/forum'; -import { CryptoService, AuthService } from '@/lib/identity/services'; +import { CryptoService, AuthService } from '@/lib/services'; import { getEnsName } from '@wagmi/core'; import { config } from '@/lib/identity/wallets/appkit'; diff --git a/src/hooks/use-toast.ts b/src/hooks/use-toast.ts index 2c14125..4b55b2d 100644 --- a/src/hooks/use-toast.ts +++ b/src/hooks/use-toast.ts @@ -15,12 +15,12 @@ type ToasterToast = ToastProps & { action?: ToastActionElement } -const actionTypes = { - ADD_TOAST: "ADD_TOAST", - UPDATE_TOAST: "UPDATE_TOAST", - DISMISS_TOAST: "DISMISS_TOAST", - REMOVE_TOAST: "REMOVE_TOAST", -} as const +enum ActionTypes { + ADD_TOAST = "ADD_TOAST", + UPDATE_TOAST = "UPDATE_TOAST", + DISMISS_TOAST = "DISMISS_TOAST", + REMOVE_TOAST = "REMOVE_TOAST", +} let count = 0 @@ -29,23 +29,22 @@ function genId() { return count.toString() } -type ActionType = typeof actionTypes type Action = | { - type: ActionType["ADD_TOAST"] + type: ActionTypes.ADD_TOAST toast: ToasterToast } | { - type: ActionType["UPDATE_TOAST"] + type: ActionTypes.UPDATE_TOAST toast: Partial } | { - type: ActionType["DISMISS_TOAST"] + type: ActionTypes.DISMISS_TOAST toastId?: ToasterToast["id"] } | { - type: ActionType["REMOVE_TOAST"] + type: ActionTypes.REMOVE_TOAST toastId?: ToasterToast["id"] } @@ -63,7 +62,7 @@ const addToRemoveQueue = (toastId: string) => { const timeout = setTimeout(() => { toastTimeouts.delete(toastId) dispatch({ - type: "REMOVE_TOAST", + type: ActionTypes.REMOVE_TOAST, toastId: toastId, }) }, TOAST_REMOVE_DELAY) @@ -73,13 +72,13 @@ const addToRemoveQueue = (toastId: string) => { export const reducer = (state: State, action: Action): State => { switch (action.type) { - case "ADD_TOAST": + case ActionTypes.ADD_TOAST: return { ...state, toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT), } - case "UPDATE_TOAST": + case ActionTypes.UPDATE_TOAST: return { ...state, toasts: state.toasts.map((t) => @@ -87,7 +86,7 @@ export const reducer = (state: State, action: Action): State => { ), } - case "DISMISS_TOAST": { + case ActionTypes.DISMISS_TOAST: { const { toastId } = action // ! Side effects ! - This could be extracted into a dismissToast() action, @@ -112,7 +111,7 @@ export const reducer = (state: State, action: Action): State => { ), } } - case "REMOVE_TOAST": + case ActionTypes.REMOVE_TOAST: if (action.toastId === undefined) { return { ...state, @@ -144,13 +143,13 @@ function toast({ ...props }: Toast) { const update = (props: ToasterToast) => dispatch({ - type: "UPDATE_TOAST", + type: ActionTypes.UPDATE_TOAST, toast: { ...props, id }, }) - const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id }) + const dismiss = () => dispatch({ type: ActionTypes.DISMISS_TOAST, toastId: id }) dispatch({ - type: "ADD_TOAST", + type: ActionTypes.ADD_TOAST, toast: { ...props, id, @@ -184,7 +183,7 @@ function useToast() { return { ...state, toast, - dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }), + dismiss: (toastId?: string) => dispatch({ type: ActionTypes.DISMISS_TOAST, toastId }), } } diff --git a/src/lib/forum/__tests__/relevance.test.ts b/src/lib/forum/__tests__/relevance.test.ts index a285800..369119d 100644 --- a/src/lib/forum/__tests__/relevance.test.ts +++ b/src/lib/forum/__tests__/relevance.test.ts @@ -146,7 +146,6 @@ describe('RelevanceCalculator', () => { describe('timeDecay', () => { it('should apply time decay to older posts', () => { const now = Date.now(); - const oneDayAgo = now - (24 * 60 * 60 * 1000); const oneWeekAgo = now - (7 * 24 * 60 * 60 * 1000); const recentPost: Post = { diff --git a/src/lib/forum/actions.ts b/src/lib/forum/actions.ts index ffb6fc3..b8fa346 100644 --- a/src/lib/forum/actions.ts +++ b/src/lib/forum/actions.ts @@ -9,7 +9,7 @@ import { } from '@/lib/waku/types'; import { Cell, Comment, Post, User } from '@/types/forum'; import { transformCell, transformComment, transformPost } from './transformers'; -import { MessageService, AuthService, CryptoService } from '@/lib/identity/services'; +import { MessageService, AuthService, CryptoService } from '@/lib/services'; type ToastFunction = (props: { title: string; diff --git a/src/lib/forum/relevance.ts b/src/lib/forum/relevance.ts index 76b7134..bcdbc0e 100644 --- a/src/lib/forum/relevance.ts +++ b/src/lib/forum/relevance.ts @@ -151,7 +151,6 @@ export class RelevanceCalculator { calculateCellScore( cell: Cell, posts: Post[], - userVerificationStatus: UserVerificationStatus ): { score: number; details: RelevanceScoreDetails } { // Apply base score let score = this.applyBaseScore('CELL'); diff --git a/src/lib/forum/transformers.ts b/src/lib/forum/transformers.ts index 6c7ac87..f134151 100644 --- a/src/lib/forum/transformers.ts +++ b/src/lib/forum/transformers.ts @@ -1,7 +1,8 @@ -import { Cell, Post, Comment, OpchanMessage, User } from '@/types'; -import { CellMessage, CommentMessage, MessageType, PostMessage, VoteMessage } from '@/lib/waku/types'; +import { Cell, Post, Comment, OpchanMessage } from '@/types/forum'; +import { CellMessage, CommentMessage, PostMessage, VoteMessage } from '@/lib/waku/types'; import messageManager from '@/lib/waku'; -import { RelevanceCalculator, UserVerificationStatus } from './relevance'; +import { RelevanceCalculator } from './relevance'; +import { UserVerificationStatus } from '@/types/forum'; type VerifyFunction = (message: OpchanMessage) => boolean; diff --git a/src/lib/identity/wallets/ReOwnWalletService.ts b/src/lib/identity/wallets/ReOwnWalletService.ts index 3c4066e..e08b3df 100644 --- a/src/lib/identity/wallets/ReOwnWalletService.ts +++ b/src/lib/identity/wallets/ReOwnWalletService.ts @@ -1,5 +1,5 @@ import { UseAppKitAccountReturn } from '@reown/appkit/react'; -import { CryptoService, DelegationDuration } from '../services/CryptoService'; +import { CryptoService, DelegationDuration } from '../../services/CryptoService'; import { AppKit } from '@reown/appkit'; import { getEnsName } from '@wagmi/core'; import { ChainNamespace } from '@reown/appkit-common'; @@ -212,7 +212,7 @@ export class ReOwnWalletService { /** * Clear delegation for the connected wallet */ - clearDelegation(walletType: 'bitcoin' | 'ethereum'): void { + clearDelegation(): void { this.cryptoService.clearDelegation(); } @@ -222,7 +222,7 @@ export class ReOwnWalletService { async getWalletInfo(): Promise { if (this.bitcoinAccount?.isConnected) { return { - address: this.bitcoinAccount.address, + address: this.bitcoinAccount.address as string, walletType: 'bitcoin', isConnected: true }; @@ -240,7 +240,7 @@ export class ReOwnWalletService { } return { - address: this.ethereumAccount.address, + address: this.ethereumAccount.address as string, walletType: 'ethereum', ensName, isConnected: true diff --git a/src/lib/identity/services/AuthService.ts b/src/lib/services/AuthService.ts similarity index 100% rename from src/lib/identity/services/AuthService.ts rename to src/lib/services/AuthService.ts diff --git a/src/lib/identity/services/CryptoService.ts b/src/lib/services/CryptoService.ts similarity index 100% rename from src/lib/identity/services/CryptoService.ts rename to src/lib/services/CryptoService.ts diff --git a/src/lib/identity/services/MessageService.ts b/src/lib/services/MessageService.ts similarity index 100% rename from src/lib/identity/services/MessageService.ts rename to src/lib/services/MessageService.ts diff --git a/src/lib/identity/services/index.ts b/src/lib/services/index.ts similarity index 100% rename from src/lib/identity/services/index.ts rename to src/lib/services/index.ts diff --git a/src/lib/utils/urlLoads.ts b/src/lib/utils/urlLoads.ts index 4ff70ee..ba6b464 100644 --- a/src/lib/utils/urlLoads.ts +++ b/src/lib/utils/urlLoads.ts @@ -14,7 +14,7 @@ export async function urlLoads(url: string, timeoutMs: number = 5000): Promise