@uniswap/token-lists#getVersionUpgrade TypeScript Examples
The following examples show how to use
@uniswap/token-lists#getVersionUpgrade.
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
}
Example #3
Source File: updater.ts From cuiswap with GNU General Public License v3.0 | 4 votes |
export default function Updater(): null {
const dispatch = useDispatch<AppDispatch>()
const lists = useSelector<AppState, AppState['lists']['byUrl']>(state => state.lists.byUrl)
// we should always fetch the default token list, so add it
useEffect(() => {
if (!lists[DEFAULT_TOKEN_LIST_URL]) dispatch(addList(DEFAULT_TOKEN_LIST_URL))
}, [dispatch, lists])
// on initial mount, refetch all the lists in storage
useEffect(() => {
Object.keys(lists).forEach(listUrl => dispatch(fetchTokenList(listUrl) as any))
// we only do this once
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dispatch])
// 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) {
dispatch(fetchTokenList(listUrl) as any)
}
})
}, [dispatch, 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:
case VersionUpgrade.MAJOR:
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))
dispatch(
addPopup({
key: listUrl,
content: {
listUpdate: {
listUrl,
oldList: list.current,
newList: list.pendingUpdate,
auto: true
}
}
})
)
} 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
// this will be turned on later
// case VersionUpgrade.MAJOR:
// dispatch(
// addPopup({
// key: listUrl,
// content: {
// listUpdate: {
// listUrl,
// auto: false,
// oldList: list.current,
// newList: list.pendingUpdate
// }
// }
// })
// )
}
}
})
}, [dispatch, lists])
return null
}
Example #4
Source File: updater.ts From interface-v2 with GNU General Public License v3.0 | 4 votes |
export default function Updater(): null {
const { library } = useActiveWeb3React();
const dispatch = useDispatch<AppDispatch>();
const lists = useSelector<AppState, AppState['lists']['byUrl']>(
(state) => state.lists.byUrl,
);
const isWindowVisible = useIsWindowVisible();
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));
dispatch(
addPopup({
key: listUrl,
content: {
listUpdate: {
listUrl,
oldList: list.current,
newList: list.pendingUpdate,
auto: true,
},
},
}),
);
} 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:
dispatch(
addPopup({
key: listUrl,
content: {
listUpdate: {
listUrl,
auto: false,
oldList: list.current,
newList: list.pendingUpdate,
},
},
removeAfterMs: null,
}),
);
}
}
});
}, [dispatch, lists]);
return null;
}
Example #5
Source File: updater.ts From cheeseswap-interface with GNU General Public License v3.0 | 4 votes |
export default function Updater(): null {
const { library } = useActiveWeb3React()
const dispatch = useDispatch<AppDispatch>()
const lists = useSelector<AppState, AppState['lists']['byUrl']>(state => state.lists.byUrl)
const isWindowVisible = useIsWindowVisible()
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))
dispatch(
addPopup({
key: listUrl,
content: {
listUpdate: {
listUrl,
oldList: list.current,
newList: list.pendingUpdate,
auto: true
}
}
})
)
} 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:
dispatch(
addPopup({
key: listUrl,
content: {
listUpdate: {
listUrl,
auto: false,
oldList: list.current,
newList: list.pendingUpdate
}
},
removeAfterMs: null
})
)
}
}
})
}, [dispatch, lists])
return null
}
Example #6
Source File: updater.ts From goose-frontend-amm with GNU General Public License v3.0 | 4 votes |
export default function Updater(): null {
const { library } = useActiveWeb3React()
const dispatch = useDispatch<AppDispatch>()
const lists = useSelector<AppState, AppState['lists']['byUrl']>((state) => state.lists.byUrl)
const isWindowVisible = useIsWindowVisible()
const fetchList = useFetchListCallback()
const fetchAllListsCallback = useCallback(() => {
if (!isWindowVisible) return
Object.keys(lists).forEach((url) =>
fetchList(url).catch((error) => console.error('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.error('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))
dispatch(
addPopup({
key: listUrl,
content: {
listUpdate: {
listUrl,
oldList: list.current,
newList: list.pendingUpdate,
auto: true,
},
},
})
)
} 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:
dispatch(
addPopup({
key: listUrl,
content: {
listUpdate: {
listUrl,
auto: false,
oldList: list.current,
newList: list.pendingUpdate,
},
},
removeAfterMs: null,
})
)
}
}
})
}, [dispatch, lists])
return null
}