about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2023-11-09 20:39:54 -0600
committerEric Bailey <git@esb.lol>2023-11-09 20:39:54 -0600
commit2d7b89c6a1fab05c5214068005298cb71468f06a (patch)
tree062bedee5c940d6eddbd135f048590f545c63880 /src
parentab878ba9a6afaa57805aeab988b01c5b47bc9286 (diff)
downloadvoidsky-2d7b89c6a1fab05c5214068005298cb71468f06a.tar.zst
Cleanup getProfile
Diffstat (limited to 'src')
-rw-r--r--src/data/index.ts5
-rw-r--r--src/data/useGetProfile.ts26
-rw-r--r--src/state/session/index.tsx5
3 files changed, 9 insertions, 27 deletions
diff --git a/src/data/index.ts b/src/data/index.ts
new file mode 100644
index 000000000..ae3d1595c
--- /dev/null
+++ b/src/data/index.ts
@@ -0,0 +1,5 @@
+import {BskyAgent} from '@atproto/api'
+
+export const PUBLIC_BSKY_AGENT = new BskyAgent({
+  service: 'https://api.bsky.app',
+})
diff --git a/src/data/useGetProfile.ts b/src/data/useGetProfile.ts
index 58f24a4e8..5e0ab907d 100644
--- a/src/data/useGetProfile.ts
+++ b/src/data/useGetProfile.ts
@@ -1,32 +1,12 @@
-import React from 'react'
 import {useQuery} from '@tanstack/react-query'
-import {BskyAgent} from '@atproto/api'
 
-import {useSession} from '#/state/session'
+import {PUBLIC_BSKY_AGENT} from '#/data'
 
 export function useGetProfile({did}: {did: string}) {
-  const {accounts} = useSession()
-  const account = React.useMemo(
-    () => accounts.find(a => a.did === did),
-    [did, accounts],
-  )
-
   return useQuery({
-    enabled: !!account,
-    queryKey: ['getProfile', account],
+    queryKey: ['getProfile', did],
     queryFn: async () => {
-      if (!account) {
-        throw new Error(`useGetProfile: local account not found for ${did}`)
-      }
-
-      const agent = new BskyAgent({
-        // needs to be public data, so remap PDS URLs to App View for now
-        service: account.service.includes('bsky.social')
-          ? 'https://api.bsky.app'
-          : account.service,
-      })
-
-      const res = await agent.getProfile({actor: did})
+      const res = await PUBLIC_BSKY_AGENT.getProfile({actor: did})
       return res.data
     },
   })
diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx
index 668d9d8ca..a5362ac6b 100644
--- a/src/state/session/index.tsx
+++ b/src/state/session/index.tsx
@@ -4,6 +4,7 @@ import {BskyAgent, AtpPersistSessionHandler} from '@atproto/api'
 import {networkRetry} from '#/lib/async/retry'
 import {logger} from '#/logger'
 import * as persisted from '#/state/persisted'
+import {PUBLIC_BSKY_AGENT} from '#/data'
 
 export type SessionAccount = persisted.PersistedAccount
 
@@ -43,10 +44,6 @@ export type ApiContext = {
   clearCurrentAccount: () => void
 }
 
-export const PUBLIC_BSKY_AGENT = new BskyAgent({
-  service: 'https://api.bsky.app',
-})
-
 const StateContext = React.createContext<StateContext>({
   agent: PUBLIC_BSKY_AGENT,
   hasSession: false,