Skip to content

Commit

Permalink
Add optional Headers param to fetchChain (#4793)
Browse files Browse the repository at this point in the history
### TL;DR

Added an optional Headers parameter to the `fetchChain` function.

### What changed?

- Introduced a new optional `headers` parameter to the `fetchChain` function in `apps/dashboard/src/utils/fetchChain.ts`.
- Updated the fetch request to include the provided headers.
- Created a new changeset file to document this patch-level change.

### How to test?

1. Call the `fetchChain` function without providing headers to ensure backward compatibility.
2. Call the `fetchChain` function with custom headers and verify they are included in the request.
3. Confirm that the function still correctly fetches chain metadata from the API.

### Why make this change?

This change allows for greater flexibility when making API requests to fetch chain metadata. By allowing custom headers, it enables use cases such as authentication, caching control, or other custom requirements when interacting with the API.
  • Loading branch information
jnsdls committed Sep 24, 2024
1 parent 0aea48e commit c0d81dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-rings-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

add optional Headers param to `fetchChain`
4 changes: 4 additions & 0 deletions apps/dashboard/src/utils/fetchChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import type { ChainMetadata } from "thirdweb/chains";

export async function fetchChain(
chainIdOrSlug: string | number,
headers = new Headers(),
): Promise<ChainMetadata | null> {
// always fetch from prod for chains for now
// TODO: re-visit this
const res = await fetch(
`https://api.thirdweb.com/v1/chains/${chainIdOrSlug}`,
{
headers,
},
);
if (res.ok) {
try {
Expand Down

0 comments on commit c0d81dc

Please sign in to comment.