From cbcb37b6acfcb2d8c61edd20fd5d7b160d46d2cf Mon Sep 17 00:00:00 2001 From: mehditorabiv Date: Thu, 5 Dec 2024 15:35:21 +0300 Subject: [PATCH 1/4] fix interceptors --- package-lock.json | 2 ++ src/services/api/index.ts | 30 ++++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index bd19b92..e1c8daa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24165,6 +24165,7 @@ "version": "18.3.1", "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", + "license": "MIT", "dependencies": { "loose-envify": "^1.1.0" }, @@ -24209,6 +24210,7 @@ "version": "18.3.1", "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", + "license": "MIT", "dependencies": { "loose-envify": "^1.1.0", "scheduler": "^0.23.2" diff --git a/src/services/api/index.ts b/src/services/api/index.ts index 3f00fd0..5c97390 100644 --- a/src/services/api/index.ts +++ b/src/services/api/index.ts @@ -1,5 +1,4 @@ import axios from 'axios'; -import { useNavigate } from 'react-router-dom'; import useSnackbarStore from '../../store/useSnackbarStore'; @@ -41,22 +40,29 @@ apiInstance.interceptors.request.use( apiInstance.interceptors.response.use( (response) => response, (error) => { - const navigate = useNavigate(); - const { showSnackbar } = useSnackbarStore(); - if (error.response?.status === 400) { - showSnackbar('Bad Request', { - severity: 'error', - }); - } + const { showSnackbar } = useSnackbarStore.getState(); if (error.response?.status === 401) { - // Show the snackbar message + localStorage.removeItem('OCI_TOKEN'); showSnackbar('Session expired. Please log in again.', { + severity: 'error', + duration: 5000, + position: { vertical: 'bottom', horizontal: 'right' }, + }); + window.location.href = '/auth/login'; + } else if (error.response?.status === 400) { + showSnackbar(`${error.response.data.message.message[0]}`, { severity: 'warning', + duration: 5000, + position: { vertical: 'bottom', horizontal: 'right' }, + }); + window.location.href = '/auth/login'; + } else { + showSnackbar('An unexpected error occurred.', { + severity: 'error', + duration: 5000, + position: { vertical: 'bottom', horizontal: 'right' }, }); - - // Redirect the user to the login page - navigate('/auth/login'); } return Promise.reject(error); From adfb351b0b15a3d69d5af5c996804dd0e0c1e11c Mon Sep 17 00:00:00 2001 From: mehditorabiv Date: Thu, 5 Dec 2024 15:46:04 +0300 Subject: [PATCH 2/4] update rainbowkit config --- src/App.tsx | 6 ++++-- src/main.tsx | 12 +++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 2b621ef..e9df9b7 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -10,7 +10,7 @@ import { } from '@rainbow-me/rainbowkit'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { Navigate, Route, Routes } from 'react-router-dom'; -import { arbitrum } from 'viem/chains'; +import { arbitrum, baseSepolia } from 'viem/chains'; import { useAccount } from 'wagmi'; import MobileScreensContainer from './components/layouts/MobileScreensContainer'; @@ -38,6 +38,8 @@ const queryClient = new QueryClient({ const App: React.FC = () => { const isSmallScreen = useMediaQuery(theme.breakpoints.down('md')); + const isProduction = import.meta.env.VITE_IS_MAINNET === 'true'; + const { authStatus, authenticationAdapter } = useSiweAuth(); const { chainId } = useAccount(); @@ -54,7 +56,7 @@ const App: React.FC = () => { status={authStatus} > ({ ...obj, [chain.id]: http() }), {} From 574c9b134e6fec8c862c1a3ed9db2593d0ed672b Mon Sep 17 00:00:00 2001 From: mehditorabiv Date: Thu, 5 Dec 2024 16:01:02 +0300 Subject: [PATCH 3/4] remove log --- src/main.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.tsx b/src/main.tsx index 8dc8f1b..45c6e7d 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -18,7 +18,6 @@ if (!import.meta.env.VITE_PROJECT_ID) { const projectID = import.meta.env.VITE_PROJECT_ID; const isProduction = import.meta.env.VITE_IS_MAINNET === 'true'; -console.log({ isProduction }); export const SUPPORTED_CHAINS: Chain[] = isProduction ? [arbitrum] From 11601437a64c6a9019520d679baabc6307a4b094 Mon Sep 17 00:00:00 2001 From: mehditorabiv Date: Thu, 5 Dec 2024 16:02:34 +0300 Subject: [PATCH 4/4] fix --- src/App.tsx | 2 +- src/services/api/index.ts | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index e9df9b7..ee14eff 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -56,7 +56,7 @@ const App: React.FC = () => { status={authStatus} >