Skip to content

Commit 8f2ff0f

Browse files
committed
♻️ Re-use did resolver helper function
1 parent 2b836b9 commit 8f2ff0f

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

Diff for: app/repositories/[id]/[...record]/page-content.tsx

+7-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ModActionPanelQuick } from 'app/actions/ModActionPanel/QuickAction'
1616
import { emitEvent } from '@/mod-event/helpers/emitEvent'
1717
import { useEffect } from 'react'
1818
import { useTitle } from 'react-use'
19+
import { getDidFromHandle } from '@/lib/identity'
1920

2021
const buildPageTitle = ({
2122
handle,
@@ -62,18 +63,16 @@ export default function RecordViewPageContent({
6263
} = useQuery({
6364
queryKey: ['record', { id, collection, rkey }],
6465
queryFn: async () => {
65-
let did: string
66+
let did: string | null
6667
if (id.startsWith('did:')) {
6768
did = id
6869
} else {
69-
const { data } = await client.api.com.atproto.identity.resolveHandle(
70-
{
71-
handle: id,
72-
},
73-
{ headers: client.proxyHeaders() },
74-
)
75-
did = data.did
70+
did = await getDidFromHandle(id)
7671
}
72+
if (!did) {
73+
throw new Error('Failed to resolve DID for the record')
74+
}
75+
7776
const uri = createAtUri({ did, collection, rkey })
7877
const getRecord = async () => {
7978
const { data: record } = await client.api.com.atproto.admin.getRecord(

Diff for: components/repositories/useRepoAndProfile.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import client from '@/lib/client'
2+
import { getDidFromHandle } from '@/lib/identity'
23
import { useQuery } from '@tanstack/react-query'
34

45
export const useRepoAndProfile = ({ id }: { id: string }) =>
@@ -10,12 +11,7 @@ export const useRepoAndProfile = ({ id }: { id: string }) =>
1011
if (id.startsWith('did:')) {
1112
did = id
1213
} else {
13-
const { data: resolved } =
14-
await client.api.com.atproto.identity.resolveHandle(
15-
{ handle: id },
16-
{ headers: client.proxyHeaders() },
17-
)
18-
did = resolved.did
14+
did = await getDidFromHandle(id)
1915
}
2016
const { data: repo } = await client.api.com.atproto.admin.getRepo(
2117
{ did },

0 commit comments

Comments
 (0)