-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboard): check if page is served from a gateway and, if so, u…
…se arns.gatewayDomain, otherwise use arns.app
- Loading branch information
1 parent
f751031
commit 717ae7c
Showing
2 changed files
with
38 additions
and
1 deletion.
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,32 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
/** Checks where page is served and uses /ar-io/info endpoint to check if it is a gateway. | ||
* | ||
* @returns domain name if it is a gateway, otherwise null | ||
*/ | ||
const useHostGatewayDomain = () => { | ||
const queryResults = useQuery({ | ||
queryKey: ['hostGatewayDomain'], | ||
queryFn: async () => { | ||
const hostGateway = window.location.hostname; | ||
const parts = hostGateway.split('.'); | ||
const domain = parts.length > 1 ? parts.slice(1).join('.') : parts[0]; | ||
|
||
try { | ||
const response = await fetch(`https://${domain}/ar-io/info`); | ||
const data = await response.json(); | ||
if (data?.wallet) { | ||
return domain; | ||
} else { | ||
return null; | ||
} | ||
} catch (error) { | ||
return null; | ||
} | ||
}, | ||
staleTime: Infinity, | ||
}); | ||
|
||
return queryResults; | ||
}; | ||
export default useHostGatewayDomain; |
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