Skip to content

Commit 4eb2d2e

Browse files
authored
upd api (#46)
1 parent 9c1e717 commit 4eb2d2e

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

packages/blinks-core/src/hooks/useBlinkList.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { BLINK_CLIENT_KEY_HEADER, clientKey } from '../utils/client-key.ts';
33

44
export interface UseBlinkListOptions {
55
id: string;
6+
wallet?: string; // user wallet address
67
}
78

89
export interface BlinkList {
@@ -21,15 +22,15 @@ export interface BlinkListEntry {
2122
icon?: string;
2223
}
2324

24-
export const useBlinkList = ({ id }: UseBlinkListOptions) => {
25+
export const useBlinkList = ({ id, wallet }: UseBlinkListOptions) => {
2526
const [loading, setLoading] = useState(false);
2627
const [data, setData] = useState<BlinkList>();
2728

2829
const refetch = useCallback(() => {
2930
let ignore = false;
3031

3132
setLoading(true);
32-
fetchBlinkList(id)
33+
fetchBlinkList(id, wallet)
3334
.then((data) => {
3435
if (!ignore) {
3536
setData(data);
@@ -44,7 +45,7 @@ export const useBlinkList = ({ id }: UseBlinkListOptions) => {
4445
return () => {
4546
ignore = true;
4647
};
47-
}, [id]);
48+
}, [id, wallet]);
4849

4950
useEffect(() => {
5051
const cancel = refetch();
@@ -61,18 +62,24 @@ export const useBlinkList = ({ id }: UseBlinkListOptions) => {
6162
};
6263
};
6364

64-
export async function fetchBlinkList(id: string): Promise<BlinkList> {
65+
export async function fetchBlinkList(
66+
id: string,
67+
wallet: string | undefined,
68+
): Promise<BlinkList> {
6569
try {
66-
const response = await fetch(
70+
const urlObj = new URL(
6771
`https://registry.dial.to/v1/private/blink-lists/${id}`,
68-
{
69-
method: 'GET',
70-
headers: {
71-
Accept: 'application/json',
72-
...(clientKey && { [BLINK_CLIENT_KEY_HEADER]: clientKey }),
73-
},
74-
},
7572
);
73+
if (wallet) {
74+
urlObj.searchParams.append('account', wallet);
75+
}
76+
const response = await fetch(urlObj, {
77+
method: 'GET',
78+
headers: {
79+
Accept: 'application/json',
80+
...(clientKey && { [BLINK_CLIENT_KEY_HEADER]: clientKey }),
81+
},
82+
});
7683
if (!response.ok) {
7784
console.error(
7885
`[@dialectlabs/blinks] Failed to fetch blink list, response status: ${response.status}`,

0 commit comments

Comments
 (0)