Skip to content

Commit

Permalink
feat: upgrade api layer
Browse files Browse the repository at this point in the history
  • Loading branch information
He1DAr committed Nov 18, 2024
1 parent 6ee9484 commit 6025c52
Show file tree
Hide file tree
Showing 55 changed files with 748 additions and 992 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@reduxjs/toolkit": "1.9.7",
"@sentry/nextjs": "8.26.0",
"@stacks/auth": "6.15.0",
"@stacks/blockchain-api-client": "7.12.0",
"@stacks/blockchain-api-client": "8.2.2",
"@stacks/common": "6.15.1-pr.0bcf867e.0+0bcf867e",
"@stacks/connect": "7.7.1",
"@stacks/connect-react": "22.4.2",
Expand Down
147 changes: 58 additions & 89 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/api/getApiClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createClient } from '@stacks/blockchain-api-client';

import packageJson from '../../package.json';
import { RELEASE_TAG_NAME } from '../common/constants/env';

export const getApiClient = (baseUrl: string) => {
const apiClient = createClient({
baseUrl,
});

apiClient.use({
onRequest({ request }) {
request.headers.set('x-hiro-product', 'explorer');
request.headers.set('x-hiro-version', RELEASE_TAG_NAME || packageJson.version);
return request;
},
});

return apiClient;
};
3 changes: 3 additions & 0 deletions src/api/getErrorMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function getErrorMessage(error: any) {
return error?.message || 'Something went wrong! Please try again later.';
}
7 changes: 7 additions & 0 deletions src/api/useApiClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { useGlobalContext } from '../common/context/useGlobalContext';
import { getApiClient } from './getApiClient';

export function useApiClient() {
const baseUrl = useGlobalContext().activeNetworkKey;
return getApiClient(baseUrl);
}
20 changes: 20 additions & 0 deletions src/api/useGetQueryFn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useApiClient } from './useApiClient';

export function useGetQueryFn(path: string) {
const apiClient = useApiClient();
return apiClient.GET('/extended/v2/blocks/{height_or_hash}/transactions', {
params: {
path: { height_or_hash: 2000 },
query: { limit: 20, offset: 100 },
},
});
}

export function useGetTransactionsQueryFn() {
return useApiClient().GET('/extended/v2/blocks/{height_or_hash}/transactions', {
params: {
path: { height_or_hash: 2000 },
query: { limit: 20, offset: 100 },
},
});
}
Loading

0 comments on commit 6025c52

Please sign in to comment.