-
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.
Merge pull request #104 from ar-io/prescribed-names
feat(observe): use current prescribed names in obesre defaults
- Loading branch information
Showing
2 changed files
with
50 additions
and
6 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,32 @@ | ||
import { useGlobalState } from '@src/store'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
const DEFAULT_NAMES = ['dapp_ardrive', 'arns']; | ||
|
||
const usePrescribedNames = () => { | ||
const arIOReadSDK = useGlobalState((state) => state.arIOReadSDK); | ||
|
||
const currentEpoch = useGlobalState((state) => state.currentEpoch); | ||
|
||
const queryResults = useQuery({ | ||
queryKey: ['prescribedNames', currentEpoch?.epochIndex || -1], | ||
queryFn: () => { | ||
if (arIOReadSDK && currentEpoch) { | ||
return arIOReadSDK.getPrescribedNames(currentEpoch).catch((e) => { | ||
// log error | ||
console.error('Failed to fetch prescribed names', { | ||
message: e.message, | ||
}); | ||
// fallback to defaults | ||
return DEFAULT_NAMES; | ||
}); | ||
} | ||
// log error | ||
throw new Error('arIOReadSDK or currentEpoch not available'); | ||
}, | ||
}); | ||
|
||
return queryResults; | ||
}; | ||
|
||
export default usePrescribedNames; |
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