Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: limit query opts, add hiro header #4877

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/app/common/api/fetch-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { analytics } from '@shared/utils/analytics';

const leatherHeaders: HeadersInit = {
'x-leather-version': VERSION,
'x-hiro-product': 'leather',
};

function isErrorCode(statusCode: number) {
Expand All @@ -30,6 +31,13 @@ export async function wrappedFetch(input: RequestInfo, init: RequestInit = {}) {
return resp;
}

axios.interceptors.request.use(request => {
if (request.url?.includes('hiro.so'))
Object.entries(leatherHeaders).forEach(([key, value]) => request.headers.set(key, value));

return request;
});

axios.interceptors.response.use(response => {
if (isErrorCode(response.status)) trackApiError(response.config.url ?? '', response.status);
return response;
Expand Down
2 changes: 2 additions & 0 deletions src/app/query/stacks/contract/contract.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ export function useGetContractInterface(transactionRequest: ContractCallPayload
transactionRequest?.contractAddress,
],
queryFn: fetchContractInterface,
staleTime: 30 * 60 * 1000,
refetchOnWindowFocus: false,
});
}
9 changes: 9 additions & 0 deletions src/app/query/stacks/transactions/transactions-by-id.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import { useStacksClientUnanchored } from '@app/store/common/api-clients.hooks';

import { useHiroApiRateLimiter } from '../rate-limiter';

const options = {
staleTime: 30 * 1000,
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: true,
} as const;

export function useTransactionsById(txids: string[]) {
const client = useStacksClientUnanchored();
const limiter = useHiroApiRateLimiter();
Expand All @@ -19,6 +26,7 @@ export function useTransactionsById(txids: string[]) {
return {
queryKey: ['transaction-by-id', txid],
queryFn: () => transactionByIdFetcher(txid),
...options,
};
}),
});
Expand All @@ -37,5 +45,6 @@ export function useTransactionById(txid: string) {
return useQuery({
queryKey: ['transaction-by-id', txid],
queryFn: () => transactionByIdFetcher(txid),
...options,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import { useCurrentNetworkState } from '@app/store/networks/networks.hooks';
import { useHiroApiRateLimiter } from '../rate-limiter';

const queryOptions: UseQueryOptions = {
refetchInterval: 10_000,
refetchOnMount: 'always',
refetchOnReconnect: 'always',
refetchOnWindowFocus: 'always',
staleTime: 60 * 1000,
refetchInterval: 30_000,
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: true,
};

export function useGetAccountTransactionsWithTransfersQuery() {
Expand Down
Loading