Skip to content

Commit

Permalink
fix: allow changing api url (#676)
Browse files Browse the repository at this point in the history
* fix: allow changing api url

* chore: bump ci

* fix: add missing hook dependency
  • Loading branch information
Cafe137 authored Nov 25, 2024
1 parent fbb2ed8 commit 6294bb0
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/providers/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,15 @@ export function Provider({ children, ...propsSettings }: Props): ReactElement {
const propsProviderUrl =
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 [desktopApiKey, setDesktopApiKey] = useState<string>(initialValues.desktopApiKey)
const [rpcProviderUrl, setRpcProviderUrl] = useState(propsProviderUrl)
const [rpcProvider, setRpcProvider] = useState(new providers.JsonRpcProvider(propsProviderUrl))
const { config, isLoading, error } = useGetBeeConfig(desktopUrl)

const url = makeHttpUrl(
config?.['api-addr'] ?? sessionStorage.getItem('api_host') ?? propsSettings.beeApiUrl ?? apiUrl,
)

useEffect(() => {
const urlSearchParams = new URLSearchParams(window.location.search)
const newApiKey = urlSearchParams.get('v')
Expand All @@ -88,18 +86,19 @@ export function Provider({ children, ...propsSettings }: Props): ReactElement {
}, [])

useEffect(() => {
const url = makeHttpUrl(config?.['api-addr'] ?? apiUrl)
try {
setBeeApi(new Bee(url))
sessionStorage.setItem('api_host', url)
} catch (e) {
setBeeApi(null)
}
}, [url])
}, [config, apiUrl])

return (
<Context.Provider
value={{
apiUrl: url,
apiUrl,
beeApi,
setApiUrl,
lockedApiSettings: Boolean(propsSettings.lockedApiSettings),
Expand Down

0 comments on commit 6294bb0

Please sign in to comment.