fix: allow changing api url (#676)
* fix: allow changing api url * chore: bump ci * fix: add missing hook dependency
This commit is contained in:
@@ -65,17 +65,15 @@ export function Provider({ children, ...propsSettings }: Props): ReactElement {
|
|||||||
const propsProviderUrl =
|
const propsProviderUrl =
|
||||||
localStorage.getItem(LocalStorageKeys.providerUrl) || propsSettings.defaultRpcUrl || DEFAULT_RPC_URL
|
localStorage.getItem(LocalStorageKeys.providerUrl) || propsSettings.defaultRpcUrl || DEFAULT_RPC_URL
|
||||||
|
|
||||||
const [apiUrl, setApiUrl] = useState<string>(initialValues.apiUrl)
|
const [apiUrl, setApiUrl] = useState<string>(
|
||||||
|
sessionStorage.getItem('api_host') ?? propsSettings.beeApiUrl ?? initialValues.apiUrl,
|
||||||
|
)
|
||||||
const [beeApi, setBeeApi] = useState<Bee | null>(null)
|
const [beeApi, setBeeApi] = useState<Bee | null>(null)
|
||||||
const [desktopApiKey, setDesktopApiKey] = useState<string>(initialValues.desktopApiKey)
|
const [desktopApiKey, setDesktopApiKey] = useState<string>(initialValues.desktopApiKey)
|
||||||
const [rpcProviderUrl, setRpcProviderUrl] = useState(propsProviderUrl)
|
const [rpcProviderUrl, setRpcProviderUrl] = useState(propsProviderUrl)
|
||||||
const [rpcProvider, setRpcProvider] = useState(new providers.JsonRpcProvider(propsProviderUrl))
|
const [rpcProvider, setRpcProvider] = useState(new providers.JsonRpcProvider(propsProviderUrl))
|
||||||
const { config, isLoading, error } = useGetBeeConfig(desktopUrl)
|
const { config, isLoading, error } = useGetBeeConfig(desktopUrl)
|
||||||
|
|
||||||
const url = makeHttpUrl(
|
|
||||||
config?.['api-addr'] ?? sessionStorage.getItem('api_host') ?? propsSettings.beeApiUrl ?? apiUrl,
|
|
||||||
)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const urlSearchParams = new URLSearchParams(window.location.search)
|
const urlSearchParams = new URLSearchParams(window.location.search)
|
||||||
const newApiKey = urlSearchParams.get('v')
|
const newApiKey = urlSearchParams.get('v')
|
||||||
@@ -88,18 +86,19 @@ export function Provider({ children, ...propsSettings }: Props): ReactElement {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const url = makeHttpUrl(config?.['api-addr'] ?? apiUrl)
|
||||||
try {
|
try {
|
||||||
setBeeApi(new Bee(url))
|
setBeeApi(new Bee(url))
|
||||||
sessionStorage.setItem('api_host', url)
|
sessionStorage.setItem('api_host', url)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setBeeApi(null)
|
setBeeApi(null)
|
||||||
}
|
}
|
||||||
}, [url])
|
}, [config, apiUrl])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Context.Provider
|
<Context.Provider
|
||||||
value={{
|
value={{
|
||||||
apiUrl: url,
|
apiUrl,
|
||||||
beeApi,
|
beeApi,
|
||||||
setApiUrl,
|
setApiUrl,
|
||||||
lockedApiSettings: Boolean(propsSettings.lockedApiSettings),
|
lockedApiSettings: Boolean(propsSettings.lockedApiSettings),
|
||||||
|
|||||||
Reference in New Issue
Block a user