fix: linting errors + stricter rules

This commit is contained in:
Danish Arora 2025-08-28 19:07:26 +05:30
parent 4e29990e12
commit d43d3bfec7
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E
29 changed files with 63 additions and 86 deletions

View File

@ -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": "^_"
}],
},
}
);

View File

@ -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 => ({

View File

@ -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();

View File

@ -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 <div>Invalid post ID</div>;

View File

@ -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,

View File

@ -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 (

View File

@ -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);

View File

@ -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" });

View File

@ -28,7 +28,7 @@ export function WalletWizard({
}: WalletWizardProps) {
const [currentStep, setCurrentStep] = React.useState<WizardStep>(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

View File

@ -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<OpchanMessage | null> => {
return cryptoServiceRef.current.signMessage(message);

View File

@ -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';

View File

@ -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<ToasterToast>
}
| {
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 }),
}
}

View File

@ -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 = {

View File

@ -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;

View File

@ -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');

View File

@ -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;

View File

@ -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<WalletInfo | null> {
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

View File

@ -14,7 +14,7 @@ export async function urlLoads(url: string, timeoutMs: number = 5000): Promise<b
clearTimeout(timeoutId);
return response.ok;
} catch (error) {
} catch {
return false;
}
}

View File

@ -1,4 +1,4 @@
import { NetworkConfig, ShardInfo } from "@waku/sdk";
import { NetworkConfig } from "@waku/sdk";
import { MessageType } from "./types";
/**

View File

@ -1,13 +1,12 @@
//TODO: perhaps store all messages in an indexed DB? (helpful when Waku is down)
// with a `isPublished` flag to indicate if the message has been sent to the network
import { createDecoder, createLightNode, HealthStatus, HealthStatusChangeEvents, LightNode } from "@waku/sdk";
import { BOOTSTRAP_NODES } from "./constants";
import { createLightNode, LightNode } from "@waku/sdk";
import StoreManager from "./store";
import { CommentCache, MessageType, VoteCache, ModerateMessage } from "./types";
import { PostCache } from "./types";
import { CellCache } from "./types";
import { OpchanMessage } from "@/types";
import { OpchanMessage } from "@/types/forum";
import { EphemeralProtocolsManager } from "./lightpush_filter";
import { NETWORK_CONFIG } from "./constants";

View File

@ -1,6 +1,5 @@
import { IDecodedMessage, LightNode } from "@waku/sdk";
import { decodeMessage, decoders} from "./codec";
import { CONTENT_TOPICS } from "./constants";
import { CellMessage, PostMessage, CommentMessage, VoteMessage } from "./types";
class StoreManager {

View File

@ -1,5 +1,5 @@
import React, { useMemo, useState } from 'react';
import { RefreshCw, Plus, TrendingUp, Clock } from 'lucide-react';
import { RefreshCw, TrendingUp, Clock } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Skeleton } from '@/components/ui/skeleton';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';

View File

@ -36,7 +36,7 @@ export interface Cell {
name: string;
description: string;
icon?: string;
signature?: string; // Message signature
signature: string; // Message signature
browserPubKey?: string; // Public key that signed the message
relevanceScore?: number; // Calculated relevance score
activeMemberCount?: number; // Number of active members in the cell

View File

@ -15,11 +15,11 @@
"jsx": "react-jsx",
/* Linting */
"strict": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitAny": false,
"noFallthroughCasesInSwitch": false,
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitAny": true,
"noFallthroughCasesInSwitch": true,
"baseUrl": ".",
"paths": {

View File

@ -9,11 +9,11 @@
"paths": {
"@/*": ["./src/*"]
},
"noImplicitAny": false,
"noUnusedParameters": false,
"noImplicitAny": true,
"noUnusedParameters": true,
"skipLibCheck": true,
"allowJs": true,
"noUnusedLocals": false,
"strictNullChecks": false
"noUnusedLocals": true,
"strictNullChecks": true
}
}