| |
| |
| |
| import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; |
| import { api } from '../services/api'; |
| import { db } from '../services/supabase'; |
| import { useAppStore } from '../store/appStore'; |
|
|
| |
| export const useHealthCheck = () => { |
| return useQuery({ |
| queryKey: ['health'], |
| queryFn: async () => { |
| const result = await api.health(); |
| return result; |
| }, |
| refetchInterval: 30000, |
| retry: 3, |
| }); |
| }; |
|
|
| |
| export const useWalletAnalysis = () => { |
| const setError = useAppStore((state) => state.setError); |
|
|
| return useMutation({ |
| mutationFn: async ({ address, chain }: { address: string; chain?: string }) => { |
| const result = await api.analyzeWallet(address, chain); |
| return result; |
| }, |
| onError: (error: any) => { |
| setError(error.message || 'Failed to analyze wallet'); |
| }, |
| }); |
| }; |
|
|
| |
| export const useWalletLookup = (address: string, chain: string = 'ethereum') => { |
| return useQuery({ |
| queryKey: ['wallet', address, chain], |
| queryFn: async () => { |
| if (!address || address.length < 10) return null; |
| const result = await api.lookupWallet(address, chain); |
| return result; |
| }, |
| enabled: address.length >= 10, |
| staleTime: 5 * 60 * 1000, |
| gcTime: 10 * 60 * 1000, |
| }); |
| }; |
|
|
| |
| export const useAIAnalysis = () => { |
| const setError = useAppStore((state) => state.setError); |
|
|
| return useMutation({ |
| mutationFn: async ({ |
| address, |
| chain, |
| tier, |
| }: { |
| address: string; |
| chain?: string; |
| tier?: string; |
| }) => { |
| const result = await api.aiAnalyze(address, chain, tier); |
| return result; |
| }, |
| onError: (error: any) => { |
| setError(error.message || 'AI analysis failed'); |
| }, |
| }); |
| }; |
|
|
| |
| export const usePatternDetection = () => { |
| return useMutation({ |
| mutationFn: async ({ address, chain }: { address: string; chain?: string }) => { |
| const result = await api.detectPatterns(address, chain); |
| return result; |
| }, |
| }); |
| }; |
|
|
| |
| export const useSystemStats = () => { |
| return useQuery({ |
| queryKey: ['stats'], |
| queryFn: async () => { |
| const result = await api.getStats(); |
| return result; |
| }, |
| refetchInterval: 60000, |
| }); |
| }; |
|
|
| |
| export const useWallets = () => { |
| return useQuery({ |
| queryKey: ['wallets'], |
| queryFn: async () => { |
| const { data, error } = await db.wallets.getAll(); |
| if (error) throw error; |
| return data || []; |
| }, |
| }); |
| }; |
|
|
| |
| export const useInvestigations = () => { |
| return useQuery({ |
| queryKey: ['investigations'], |
| queryFn: async () => { |
| const { data, error } = await db.investigations.getAll(); |
| if (error) throw error; |
| return data || []; |
| }, |
| }); |
| }; |
|
|
| |
| export const useCreateInvestigation = () => { |
| const queryClient = useQueryClient(); |
| const addInvestigation = useAppStore((state) => state.addInvestigation); |
|
|
| return useMutation({ |
| mutationFn: async (investigation: { |
| title: string; |
| description?: string; |
| wallet_addresses?: string[]; |
| status?: string; |
| }) => { |
| const { data, error } = await db.investigations.create(investigation); |
| if (error) throw error; |
| return data?.[0]; |
| }, |
| onSuccess: (data) => { |
| if (data) { |
| addInvestigation(data); |
| queryClient.invalidateQueries({ queryKey: ['investigations'] }); |
| } |
| }, |
| }); |
| }; |
|
|
| |
| export const useEvidence = () => { |
| return useQuery({ |
| queryKey: ['evidence'], |
| queryFn: async () => { |
| const { data, error } = await db.evidence.getAll(); |
| if (error) throw error; |
| return data || []; |
| }, |
| }); |
| }; |
|
|
| |
| export const useCreateWallet = () => { |
| const queryClient = useQueryClient(); |
|
|
| return useMutation({ |
| mutationFn: async (wallet: { |
| address: string; |
| chain: string; |
| label?: string; |
| status?: string; |
| }) => { |
| const { data, error } = await db.wallets.create(wallet); |
| if (error) throw error; |
| return data?.[0]; |
| }, |
| onSuccess: () => { |
| queryClient.invalidateQueries({ queryKey: ['wallets'] }); |
| }, |
| }); |
| }; |
|
|