Skip to content

Commit

Permalink
Merge pull request #1280 from multiversx/development
Browse files Browse the repository at this point in the history
2.40.11
  • Loading branch information
arhtudormorar authored Oct 9, 2024
2 parents c093e34 + 690848d commit 25d130d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [[v2.40.11](https://github.com/multiversx/mx-sdk-dapp/pull/1280)] - 2024-10-09
- [Fixed axios interceptor concurrent calls](https://github.com/multiversx/mx-sdk-dapp/pull/1279)

## [[v2.40.10](https://github.com/multiversx/mx-sdk-dapp/pull/1277)] - 2024-10-04

- [Update WalletConnect Provider](https://github.com/multiversx/mx-sdk-dapp/pull/1276)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-dapp",
"version": "2.40.10",
"version": "2.40.11",
"description": "A library to hold the main logic for a dapp on the MultiversX blockchain",
"author": "MultiversX",
"license": "GPL-3.0-or-later",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, PropsWithChildren, useEffect } from 'react';
import React, { useRef, PropsWithChildren, useMemo } from 'react';
import axios from 'axios';
import { useAxiosInterceptorContext } from './AxiosInterceptorContextProvider';

Expand All @@ -15,7 +15,7 @@ export const AxiosInterceptor = ({

const requestIdRef = useRef(-1);

const setResponseInterceptors = () => {
requestIdRef.current = useMemo(() => {
axios.interceptors.response.use(
(response) => {
return response;
Expand All @@ -30,15 +30,16 @@ export const AxiosInterceptor = ({
return Promise.reject(error);
}
);
};

const setInterceptors = () => {
axios.interceptors.request.eject(requestIdRef.current);

requestIdRef.current = axios.interceptors.request.use(
return axios.interceptors.request.use(
async (config) => {
if (authenticatedDomains.includes(String(config?.baseURL))) {
config.headers.set('Authorization', `Bearer ${bearerToken}`);
if (
authenticatedDomains.includes(String(config?.baseURL)) &&
bearerToken
) {
config.headers.Authorization = `Bearer ${bearerToken}`;
}

return config;
Expand All @@ -47,15 +48,7 @@ export const AxiosInterceptor = ({
Promise.reject(error);
}
);
};

useEffect(setResponseInterceptors, []);

useEffect(() => {
if (bearerToken) {
setInterceptors();
}
}, [bearerToken]);
}, [bearerToken, authenticatedDomains]);

return <>{children}</>;
};

0 comments on commit 25d130d

Please sign in to comment.