diff --git a/src/clients/ErrorClient.ts b/src/clients/ErrorClient.ts index ba12bb3..5caee7b 100644 --- a/src/clients/ErrorClient.ts +++ b/src/clients/ErrorClient.ts @@ -1,9 +1,9 @@ import { Governance } from './Governance' export class ErrorClient { - public static report(errorMsg: string, extraInfo?: Record) { + public static async report(errorMsg: string, extraInfo?: Record, options?: { sign: boolean }) { try { - Governance.get().reportErrorToServer(errorMsg, extraInfo) + await Governance.get().reportErrorToServer(errorMsg, extraInfo, options) } catch (e) { console.error('Error reporting error', e) } diff --git a/src/clients/Governance.ts b/src/clients/Governance.ts index 92da86f..9096456 100644 --- a/src/clients/Governance.ts +++ b/src/clients/Governance.ts @@ -418,11 +418,11 @@ export class Governance extends API { }) } - async reportErrorToServer(message: string, extraInfo?: Record) { + async reportErrorToServer(message: string, extraInfo?: Record, options = { sign: true }) { return await this.fetchApiResponse(`/debug/report-error`, { method: 'POST', - sign: true, json: { message, extraInfo }, + ...options, }) } diff --git a/src/hooks/useGovernanceProfile.ts b/src/hooks/useGovernanceProfile.ts index d91cb62..2acc96c 100644 --- a/src/hooks/useGovernanceProfile.ts +++ b/src/hooks/useGovernanceProfile.ts @@ -3,28 +3,38 @@ import isEthereumAddress from 'validator/lib/isEthereumAddress' import { ErrorClient } from '../clients/ErrorClient' import { Governance } from '../clients/Governance' +import { useAuthContext } from '../context/AuthProvider.tsx' import { ErrorCategory } from '../utils/errorCategories' import { DEFAULT_QUERY_STALE_TIME } from './constants' -export default function useGovernanceProfile(address?: string | null) { +export default function useGovernanceProfile(profileAddress?: string | null) { + const [address] = useAuthContext() const { data, isLoading: isLoadingGovernanceProfile } = useQuery({ - queryKey: [`userGovernanceProfile`, address], + queryKey: [`userGovernanceProfile`, profileAddress], queryFn: async () => { - if (!address || !isEthereumAddress(address)) return null + if (!profileAddress || !isEthereumAddress(profileAddress)) return null try { - return await Governance.get().getUserProfile(address) + return await Governance.get().getUserProfile(profileAddress) // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { if (error.statusCode !== 404) { - ErrorClient.report('Error getting governance profile', { error, address, category: ErrorCategory.Profile }) + ErrorClient.report( + 'Error getting governance profile', + { + error, + address: profileAddress, + category: ErrorCategory.Profile, + }, + { sign: !!address } + ) } return null } }, staleTime: DEFAULT_QUERY_STALE_TIME, - enabled: !!address, + enabled: !!profileAddress, }) return { profile: data, isProfileValidated: !!data?.forum_id, isLoadingGovernanceProfile }