mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {useCallback} from 'react'
2import {useQueryClient} from '@tanstack/react-query'
3
4import {logger} from '#/logger'
5import {updateProfileShadow} from '#/state/cache/profile-shadow'
6import {useAgent} from '#/state/session'
7import type * as bsky from '#/types/bsky'
8
9/**
10 * Fetches a fresh verification state from the app view and updates our profile
11 * cache. This state is computed using a variety of factors on the server, so
12 * we need to get this data from the server.
13 */
14export function useUpdateProfileVerificationCache() {
15 const qc = useQueryClient()
16 const agent = useAgent()
17
18 return useCallback(
19 async ({profile}: {profile: bsky.profile.AnyProfileView}) => {
20 try {
21 const {data: updated} = await agent.getProfile({
22 actor: profile.did ?? '',
23 })
24 updateProfileShadow(qc, profile.did, {
25 verification: updated.verification,
26 })
27 } catch (e) {
28 logger.error(`useUpdateProfileVerificationCache failed`, {
29 safeMessage: e,
30 })
31 }
32 },
33 [agent, qc],
34 )
35}