From 26408e9727592ca476c152913db0afcb02fe14b0 Mon Sep 17 00:00:00 2001 From: DanutIlie <42973343+DanutIlie@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:27:06 +0300 Subject: [PATCH 1/4] Fix axios interceptors concurrency (#1279) * fixed axios interceptor concurrent calls --- CHANGELOG.md | 2 ++ .../components/AxiosInterceptor.tsx | 25 +++++++------------ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9cc1c25f..736dbf1d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- [Fixed axios interceptor concurrent calls](https://github.com/multiversx/mx-sdk-dapp/pull/1278) + ## [[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) diff --git a/src/wrappers/AxiosInterceptorContext/components/AxiosInterceptor.tsx b/src/wrappers/AxiosInterceptorContext/components/AxiosInterceptor.tsx index fc48df3cf..469c35cc7 100644 --- a/src/wrappers/AxiosInterceptorContext/components/AxiosInterceptor.tsx +++ b/src/wrappers/AxiosInterceptorContext/components/AxiosInterceptor.tsx @@ -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'; @@ -15,7 +15,7 @@ export const AxiosInterceptor = ({ const requestIdRef = useRef(-1); - const setResponseInterceptors = () => { + requestIdRef.current = useMemo(() => { axios.interceptors.response.use( (response) => { return response; @@ -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; @@ -47,15 +48,7 @@ export const AxiosInterceptor = ({ Promise.reject(error); } ); - }; - - useEffect(setResponseInterceptors, []); - - useEffect(() => { - if (bearerToken) { - setInterceptors(); - } - }, [bearerToken]); + }, [bearerToken, authenticatedDomains]); return <>{children}; }; From eb9c14489d6869c34941b61d7ae003b84c8549ea Mon Sep 17 00:00:00 2001 From: Tudor Morar Date: Wed, 9 Oct 2024 15:27:50 +0300 Subject: [PATCH 2/4] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 736dbf1d6..afa428d08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ 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/1279)] - 2024-10-09 - [Fixed axios interceptor concurrent calls](https://github.com/multiversx/mx-sdk-dapp/pull/1278) ## [[v2.40.10](https://github.com/multiversx/mx-sdk-dapp/pull/1277)] - 2024-10-04 From c4188cf66dacbeb3cf80bb96a269d1bfcc9bc926 Mon Sep 17 00:00:00 2001 From: Tudor Morar Date: Wed, 9 Oct 2024 15:28:06 +0300 Subject: [PATCH 3/4] Update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3add9424a..4e848eeaf 100644 --- a/package.json +++ b/package.json @@ -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", From 690848da8f89f4bda30c386701fecc24f3ee9a3a Mon Sep 17 00:00:00 2001 From: Miro Date: Wed, 9 Oct 2024 15:59:45 +0300 Subject: [PATCH 4/4] Fixed CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index afa428d08..c6c0c2fd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,8 @@ 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/1279)] - 2024-10-09 -- [Fixed axios interceptor concurrent calls](https://github.com/multiversx/mx-sdk-dapp/pull/1278) +## [[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