hooks/Tokens#useAllInactiveTokens TypeScript Examples
The following examples show how to use
hooks/Tokens#useAllInactiveTokens.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: updater.ts From glide-frontend with GNU General Public License v3.0 | 5 votes |
export default function Updater(): null {
const { library } = useWeb3Provider()
const dispatch = useDispatch<AppDispatch>()
const isWindowVisible = useIsWindowVisible()
// get all loaded lists, and the active urls
const lists = useAllLists()
const activeListUrls = useActiveListUrls()
// initiate loading
useAllInactiveTokens()
const fetchList = useFetchListCallback()
const fetchAllListsCallback = useCallback(() => {
if (!isWindowVisible) return
Object.keys(lists).forEach((url) =>
fetchList(url).catch((error) => console.debug('interval list fetching error', error)),
)
}, [fetchList, isWindowVisible, lists])
// fetch all lists every 10 minutes, but only after we initialize library
useInterval(fetchAllListsCallback, library ? 1000 * 60 * 10 : null)
// whenever a list is not loaded and not loading, try again to load it
useEffect(() => {
Object.keys(lists).forEach((listUrl) => {
const list = lists[listUrl]
if (!list.current && !list.loadingRequestId && !list.error) {
fetchList(listUrl).catch((error) => console.debug('list added fetching error', error))
}
})
}, [dispatch, fetchList, library, lists])
// if any lists from unsupported lists are loaded, check them too (in case new updates since last visit)
useEffect(() => {
Object.keys(UNSUPPORTED_LIST_URLS).forEach((listUrl) => {
const list = lists[listUrl]
if (!list || (!list.current && !list.loadingRequestId && !list.error)) {
fetchList(listUrl).catch((error) => console.debug('list added fetching error', error))
}
})
}, [dispatch, fetchList, library, lists])
// automatically update lists if versions are minor/patch
useEffect(() => {
Object.keys(lists).forEach((listUrl) => {
const list = lists[listUrl]
if (list.current && list.pendingUpdate) {
const bump = getVersionUpgrade(list.current.version, list.pendingUpdate.version)
// eslint-disable-next-line default-case
switch (bump) {
case VersionUpgrade.NONE:
throw new Error('unexpected no version bump')
// update any active or inactive lists
case VersionUpgrade.PATCH:
case VersionUpgrade.MINOR:
case VersionUpgrade.MAJOR:
dispatch(acceptListUpdate(listUrl))
}
}
})
}, [dispatch, lists, activeListUrls])
return null
}
Example #2
Source File: updater.ts From forward.swaps with GNU General Public License v3.0 | 5 votes |
export default function Updater(): null {
const { library } = useActiveWeb3React()
const dispatch = useDispatch<AppDispatch>()
const isWindowVisible = useIsWindowVisible()
// get all loaded lists, and the active urls
const lists = useAllLists()
const activeListUrls = useActiveListUrls()
// initiate loading
useAllInactiveTokens()
const fetchList = useFetchListCallback()
const fetchAllListsCallback = useCallback(() => {
if (!isWindowVisible) return
Object.keys(lists).forEach(url =>
fetchList(url).catch(error => console.debug('interval list fetching error', error))
)
}, [fetchList, isWindowVisible, lists])
// fetch all lists every 10 minutes, but only after we initialize library
useInterval(fetchAllListsCallback, library ? 1000 * 60 * 10 : null)
// whenever a list is not loaded and not loading, try again to load it
useEffect(() => {
Object.keys(lists).forEach(listUrl => {
const list = lists[listUrl]
if (!list.current && !list.loadingRequestId && !list.error) {
fetchList(listUrl).catch(error => console.debug('list added fetching error', error))
}
})
}, [dispatch, fetchList, library, lists])
// automatically update lists if versions are minor/patch
useEffect(() => {
Object.keys(lists).forEach(listUrl => {
const list = lists[listUrl]
if (list.current && list.pendingUpdate) {
const bump = getVersionUpgrade(list.current.version, list.pendingUpdate.version)
switch (bump) {
case VersionUpgrade.NONE:
throw new Error('unexpected no version bump')
case VersionUpgrade.PATCH:
case VersionUpgrade.MINOR:
const min = minVersionBump(list.current.tokens, list.pendingUpdate.tokens)
// automatically update minor/patch as long as bump matches the min update
if (bump >= min) {
dispatch(acceptListUpdate(listUrl))
} else {
console.error(
`List at url ${listUrl} could not automatically update because the version bump was only PATCH/MINOR while the update had breaking changes and should have been MAJOR`
)
}
break
case VersionUpgrade.MAJOR:
// accept update if list is active or list in background
if (activeListUrls?.includes(listUrl) || UNSUPPORTED_LIST_URLS.includes(listUrl)) {
dispatch(acceptListUpdate(listUrl))
}
}
}
})
}, [dispatch, lists, activeListUrls])
return null
}