fix: ensure lists are present before running update (#7206)
* fix: ensure lists are present before running update * pr input from zzmp
This commit is contained in:
parent
3dab1da5ea
commit
49ae6ef6bd
@ -24,12 +24,12 @@ class TokenSafetyLookupTable {
|
||||
this.initialized = true
|
||||
|
||||
// Initialize extended tokens first
|
||||
lists.byUrl[UNI_EXTENDED_LIST].current?.tokens.forEach((token) => {
|
||||
lists.byUrl[UNI_EXTENDED_LIST]?.current?.tokens.forEach((token) => {
|
||||
this.dict[token.address.toLowerCase()] = TOKEN_LIST_TYPES.UNI_EXTENDED
|
||||
})
|
||||
|
||||
// Initialize default tokens second, so that any tokens on both default and extended will display as default (no warning)
|
||||
lists.byUrl[UNI_LIST].current?.tokens.forEach((token) => {
|
||||
lists.byUrl[UNI_LIST]?.current?.tokens.forEach((token) => {
|
||||
this.dict[token.address.toLowerCase()] = TOKEN_LIST_TYPES.UNI_DEFAULT
|
||||
})
|
||||
|
||||
@ -39,7 +39,7 @@ class TokenSafetyLookupTable {
|
||||
})
|
||||
|
||||
// Initialize blocked tokens from all urls included
|
||||
UNSUPPORTED_LIST_URLS.map((url) => lists.byUrl[url].current?.tokens)
|
||||
UNSUPPORTED_LIST_URLS.map((url) => lists.byUrl[url]?.current?.tokens)
|
||||
.filter((x): x is TokenInfo[] => !!x)
|
||||
.flat(1)
|
||||
.forEach((token) => {
|
||||
|
@ -5,6 +5,8 @@ import { useEffect } from 'react'
|
||||
import { useAppDispatch, useAppSelector } from 'state/hooks'
|
||||
import { updateSelectedWallet } from 'state/user/reducer'
|
||||
|
||||
import { useStateRehydrated } from './useStateRehydrated'
|
||||
|
||||
async function connect(connector: Connector) {
|
||||
try {
|
||||
if (connector.connectEagerly) {
|
||||
@ -21,7 +23,7 @@ export default function useEagerlyConnect() {
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const selectedWallet = useAppSelector((state) => state.user.selectedWallet)
|
||||
const rehydrated = useAppSelector((state) => state._persist.rehydrated)
|
||||
const rehydrated = useStateRehydrated()
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
|
5
src/hooks/useStateRehydrated.ts
Normal file
5
src/hooks/useStateRehydrated.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { useAppSelector } from 'state/hooks'
|
||||
|
||||
export function useStateRehydrated() {
|
||||
return useAppSelector((state) => state._persist.rehydrated)
|
||||
}
|
@ -2,6 +2,7 @@ import { getVersionUpgrade, VersionUpgrade } from '@uniswap/token-lists'
|
||||
import { useWeb3React } from '@web3-react/core'
|
||||
import { DEFAULT_LIST_OF_LISTS, UNSUPPORTED_LIST_URLS } from 'constants/lists'
|
||||
import TokenSafetyLookupTable from 'constants/tokenSafetyLookup'
|
||||
import { useStateRehydrated } from 'hooks/useStateRehydrated'
|
||||
import useInterval from 'lib/hooks/useInterval'
|
||||
import ms from 'ms'
|
||||
import { useCallback, useEffect } from 'react'
|
||||
@ -21,10 +22,11 @@ export default function Updater(): null {
|
||||
// get all loaded lists, and the active urls
|
||||
const lists = useAllLists()
|
||||
const listsState = useAppSelector((state) => state.lists)
|
||||
const rehydrated = useStateRehydrated()
|
||||
|
||||
useEffect(() => {
|
||||
TokenSafetyLookupTable.update(listsState)
|
||||
}, [listsState])
|
||||
if (rehydrated) TokenSafetyLookupTable.update(listsState)
|
||||
}, [listsState, rehydrated])
|
||||
|
||||
const fetchList = useFetchListCallback()
|
||||
const fetchAllListsCallback = useCallback(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user