-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
260 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VITE_SERVER_URL=http://localhost:3000 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import axios from 'axios'; | ||
import { setupInterceptors } from './interceptors'; | ||
|
||
const AxiosClient = axios.create({ | ||
baseURL: | ||
!import.meta.env.VITE_USE_MOCK && import.meta.env.VITE_SERVER_URL | ||
? import.meta.env.VITE_SERVER_URL | ||
: 'http://localhost:3000', | ||
headers: { | ||
Accept: 'application/json', | ||
}, | ||
}); | ||
|
||
setupInterceptors(AxiosClient); | ||
|
||
export default AxiosClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { AxiosError, AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios'; | ||
|
||
interface IRequestAxios extends InternalAxiosRequestConfig { | ||
skipLoading?: boolean; | ||
} | ||
|
||
const onRequestConfig = (config: IRequestAxios) => { | ||
// if (!config.headers['Authorization']) { | ||
// const token = localStorage.getItem('accessToken'); | ||
// if (token) { | ||
// config.headers['Authorization'] = `Bearer ${token}`; | ||
// } | ||
// } | ||
if (!config.headers['Content-Type']) { | ||
config.headers['Content-Type'] = 'application/json'; | ||
} | ||
config.timeout = 30000; | ||
return config; | ||
}; | ||
|
||
const onRequestError = (error: AxiosError): Promise<AxiosError> => { | ||
return Promise.reject(error); | ||
}; | ||
|
||
const onResponse = (res: AxiosResponse): AxiosResponse => { | ||
return res; | ||
}; | ||
|
||
const onResponseError = async ( | ||
err: AxiosError, | ||
// axiosInstance: AxiosInstance, | ||
): Promise<AxiosError | undefined> => { | ||
// const originalConfig = err.config as InternalAxiosRequestConfig; | ||
|
||
console.log(err); | ||
// if (err.response?.status === 401) { | ||
// const currentRefreshToken = localStorage.getItem('refreshToken'); | ||
// removeAllToken(); | ||
// if (!currentRefreshToken) { | ||
// if (window.location.pathname == '/login') { | ||
// return Promise.reject(err?.response?.data); | ||
// } | ||
// return; | ||
// } | ||
// const token = await userApi.refreshToken(currentRefreshToken!); | ||
// localStorage.setItem('accessToken', token.accessToken); | ||
// localStorage.setItem('refreshToken', token.refreshToken); | ||
// originalConfig.headers.Authorization = `Bearer ${token.accessToken}`; | ||
|
||
// return axiosInstance(originalConfig); | ||
// } | ||
return Promise.reject(err?.response?.data); | ||
}; | ||
|
||
export const setupInterceptors = (axiosInstance: AxiosInstance) => { | ||
axiosInstance.interceptors.request.use(onRequestConfig, onRequestError); | ||
axiosInstance.interceptors.response.use(onResponse, (err: AxiosError) => | ||
onResponseError(err /*axiosInstance*/), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Keystore } from '@/store/keystore/type'; | ||
import AxiosClient from '../client'; | ||
import { CreateWalletKeystoreRequest } from './type'; | ||
|
||
export const createWalletKeystore = async ( | ||
data: CreateWalletKeystoreRequest, | ||
) /*: Promise<CreateWalletKeystoreResponse>*/ => { | ||
const response = await AxiosClient.post('/wallet/create/keystore', data); | ||
return response.data as Keystore; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
interface CreateWalletKeystoreRequest { | ||
password: string; | ||
} | ||
|
||
export type { CreateWalletKeystoreRequest }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.