forked from aboutmydreams/aiis.read
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Optimize chain config #137
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
67658a5
feat: 优化 chain config 相关代码
huangbinjie 77263dc
chore: update value type
huangbinjie 2700f37
chore: remove getChainConfig from store
huangbinjie 76fbf33
Merge remote-tracking branch 'origin/main' into optimize-chain-config
huangbinjie 5034400
fix: type error
huangbinjie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,39 +1,33 @@ | ||
import { XFANS_NETWORK_ARB, XFANS_NETWORK_BERA } from '../constants'; | ||
interface ChainConfigType { | ||
export enum Chain { | ||
Arb = 'arb', | ||
Bera = 'bera', | ||
} | ||
|
||
export const chainNameMap = { | ||
[Chain.Arb]: 'Arb Sepolia', | ||
[Chain.Bera]: 'Bera Artio', | ||
}; | ||
|
||
export interface ChainConfigType { | ||
vite_socket_base_url: string; | ||
vite_room_base_url: string; | ||
vite_contract_base_url: string; | ||
vite_base_url: string; | ||
} | ||
|
||
const _chainConfig: Record<string, ChainConfigType> = { | ||
arb: { | ||
vite_socket_base_url: import.meta.env.VITE_ARB_SOCKET_BASE_URL!, | ||
vite_room_base_url: import.meta.env.VITE_ARB_ROOM_BASE_URL!, | ||
vite_contract_base_url: import.meta.env.VITE_ARB_CONTRACT_BASE_URL!, | ||
vite_base_url: import.meta.env.VITE_ARB_BASE_URL!, | ||
const chainConfig: Record<Chain, ChainConfigType> = { | ||
[Chain.Arb]: { | ||
vite_socket_base_url: import.meta.env.VITE_ARB_SOCKET_BASE_URL, | ||
vite_room_base_url: import.meta.env.VITE_ARB_ROOM_BASE_URL, | ||
vite_contract_base_url: import.meta.env.VITE_ARB_CONTRACT_BASE_URL, | ||
vite_base_url: import.meta.env.VITE_ARB_BASE_URL, | ||
}, | ||
bera: { | ||
vite_socket_base_url: import.meta.env.VITE_BERA_SOCKET_BASE_URL!, | ||
vite_room_base_url: import.meta.env.VITE_BERA_ROOM_BASE_URL!, | ||
vite_contract_base_url: import.meta.env.VITE_BERA_CONTRACT_BASE_URL!, | ||
vite_base_url: import.meta.env.VITE_BERA_BASE_URL!, | ||
[Chain.Bera]: { | ||
vite_socket_base_url: import.meta.env.VITE_BERA_SOCKET_BASE_URL, | ||
vite_room_base_url: import.meta.env.VITE_BERA_ROOM_BASE_URL, | ||
vite_contract_base_url: import.meta.env.VITE_BERA_CONTRACT_BASE_URL, | ||
vite_base_url: import.meta.env.VITE_BERA_BASE_URL, | ||
}, | ||
}; | ||
|
||
console.log('_chainConfig', _chainConfig); | ||
const ChainConfig = () => { | ||
if (getCurrentChain() == '') console.error('chain info undefined!'); | ||
return _chainConfig[getCurrentChain()]; | ||
}; | ||
|
||
export const getCurrentChain = () => localStorage.getItem('current_chain') ?? 'arb'; | ||
export const setCurrentChain = (chain: string) => { | ||
localStorage.setItem('current_chain', chain); | ||
}; | ||
|
||
export const getCurrentChainName = () => { | ||
return getCurrentChain() == 'arb' ? XFANS_NETWORK_ARB : XFANS_NETWORK_BERA; | ||
}; | ||
|
||
export default ChainConfig; | ||
export default chainConfig; |
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
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 |
---|---|---|
|
@@ -7,10 +7,10 @@ import axios, { | |
} from 'axios'; | ||
|
||
import * as toaster from '../components/Toaster'; | ||
import chainConfig from '../config/chainConfig'; | ||
import useGlobalStore from '../store/useGlobalStore'; | ||
|
||
import { checkStatus } from './checkStatus'; | ||
import ChainConfig, { getCurrentChain } from '../config/chainConfig'; | ||
|
||
// 请求响应参数(不包含data) | ||
export interface Result { | ||
|
@@ -33,7 +33,7 @@ export enum ResultEnum { | |
|
||
const config = { | ||
// 默认地址请求地址,可在 .env.** 文件中修改 | ||
baseURL: ChainConfig().vite_base_url, | ||
baseURL: chainConfig[useGlobalStore.getState().chain].vite_base_url, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 话说这里之前就有bug把。。切换网络了,这里不会变的,我这里突然想到但是没修还 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个我来想办法解决下,先合了 |
||
// 设置超时时间 | ||
timeout: ResultEnum.TIMEOUT as number, | ||
// 跨域时候允许携带凭证 | ||
|
@@ -42,7 +42,7 @@ const config = { | |
|
||
const contractConfig = { | ||
// 默认地址请求地址,可在 .env.** 文件中修改 | ||
baseURL: ChainConfig().vite_contract_base_url, | ||
baseURL: chainConfig[useGlobalStore.getState().chain].vite_contract_base_url, | ||
// 设置超时时间 | ||
timeout: ResultEnum.TIMEOUT as number, | ||
// 跨域时候允许携带凭证 | ||
|
@@ -51,7 +51,7 @@ const contractConfig = { | |
|
||
const chatConfig = { | ||
// 默认地址请求地址,可在 .env.** 文件中修改 | ||
baseURL: ChainConfig().vite_room_base_url, | ||
baseURL: chainConfig[useGlobalStore.getState().chain].vite_room_base_url, | ||
// 设置超时时间 | ||
timeout: ResultEnum.TIMEOUT as number, | ||
// 跨域时候允许携带凭证 | ||
|
@@ -77,8 +77,8 @@ class RequestHttp { | |
config.headers.set('Authorization', 'Bearer ' + token); | ||
} | ||
if (chainInfo) { | ||
const chainInfo = getCurrentChain(); | ||
config.url = config?.url?.replace(/(\/xfans\/api\/)/, `/xfans/api/${chainInfo}/`); | ||
const currentChain = useGlobalStore.getState().chain; | ||
config.url = config?.url?.replace(/(\/xfans\/api\/)/, `/xfans/api/${currentChain}/`); | ||
} | ||
return config; | ||
}, | ||
|
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
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有什么问题