Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
bc92af6c
Unverified
Commit
bc92af6c
authored
Feb 14, 2023
by
cartcrom
Committed by
GitHub
Feb 14, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: use latest version of tokenlists over cache (#5975)
fix: use constants in fetch interval callback to prevent updates
parent
9a257e0c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
16 deletions
+14
-16
useFetchListCallback.ts
src/hooks/useFetchListCallback.ts
+5
-10
updater.ts
src/state/lists/updater.ts
+9
-6
No files found.
src/hooks/useFetchListCallback.ts
View file @
bc92af6c
...
@@ -9,30 +9,25 @@ import { useAppDispatch } from 'state/hooks'
...
@@ -9,30 +9,25 @@ import { useAppDispatch } from 'state/hooks'
import
{
fetchTokenList
}
from
'
../state/lists/actions
'
import
{
fetchTokenList
}
from
'
../state/lists/actions
'
export
function
useFetchListCallback
():
(
export
function
useFetchListCallback
():
(
listUrl
:
string
,
skipValidation
?:
boolean
)
=>
Promise
<
TokenList
>
{
listUrl
:
string
,
sendDispatch
?:
boolean
,
skipValidation
?:
boolean
)
=>
Promise
<
TokenList
>
{
const
dispatch
=
useAppDispatch
()
const
dispatch
=
useAppDispatch
()
// note: prevent dispatch if using for list search or unsupported list
return
useCallback
(
return
useCallback
(
async
(
listUrl
:
string
,
s
endDispatch
=
true
,
s
kipValidation
?:
boolean
)
=>
{
async
(
listUrl
:
string
,
skipValidation
?:
boolean
)
=>
{
const
requestId
=
nanoid
()
const
requestId
=
nanoid
()
sendDispatch
&&
dispatch
(
fetchTokenList
.
pending
({
requestId
,
url
:
listUrl
}))
dispatch
(
fetchTokenList
.
pending
({
requestId
,
url
:
listUrl
}))
return
getTokenList
(
return
getTokenList
(
listUrl
,
listUrl
,
(
ensName
:
string
)
=>
resolveENSContentHash
(
ensName
,
RPC_PROVIDERS
[
SupportedChainId
.
MAINNET
]),
(
ensName
:
string
)
=>
resolveENSContentHash
(
ensName
,
RPC_PROVIDERS
[
SupportedChainId
.
MAINNET
]),
skipValidation
skipValidation
)
)
.
then
((
tokenList
)
=>
{
.
then
((
tokenList
)
=>
{
sendDispatch
&&
dispatch
(
fetchTokenList
.
fulfilled
({
url
:
listUrl
,
tokenList
,
requestId
}))
dispatch
(
fetchTokenList
.
fulfilled
({
url
:
listUrl
,
tokenList
,
requestId
}))
return
tokenList
return
tokenList
})
})
.
catch
((
error
)
=>
{
.
catch
((
error
)
=>
{
console
.
debug
(
`Failed to get list at url
${
listUrl
}
`
,
error
)
console
.
debug
(
`Failed to get list at url
${
listUrl
}
`
,
error
)
sendDispatch
&&
dispatch
(
fetchTokenList
.
rejected
({
url
:
listUrl
,
requestId
,
errorMessage
:
error
.
message
}))
dispatch
(
fetchTokenList
.
rejected
({
url
:
listUrl
,
requestId
,
errorMessage
:
error
.
message
}))
throw
error
throw
error
})
})
},
},
...
...
src/state/lists/updater.ts
View file @
bc92af6c
import
{
getVersionUpgrade
,
minVersionBump
,
VersionUpgrade
}
from
'
@uniswap/token-lists
'
import
{
getVersionUpgrade
,
minVersionBump
,
VersionUpgrade
}
from
'
@uniswap/token-lists
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
UNSUPPORTED_LIST_URLS
}
from
'
constants/lists
'
import
{
DEFAULT_LIST_OF_LISTS
,
UNSUPPORTED_LIST_URLS
}
from
'
constants/lists
'
import
useInterval
from
'
lib/hooks/useInterval
'
import
useInterval
from
'
lib/hooks/useInterval
'
import
ms
from
'
ms.macro
'
import
{
useCallback
,
useEffect
}
from
'
react
'
import
{
useCallback
,
useEffect
}
from
'
react
'
import
{
useAppDispatch
}
from
'
state/hooks
'
import
{
useAppDispatch
}
from
'
state/hooks
'
import
{
useAllLists
}
from
'
state/lists/hooks
'
import
{
useAllLists
}
from
'
state/lists/hooks
'
...
@@ -20,15 +21,15 @@ export default function Updater(): null {
...
@@ -20,15 +21,15 @@ export default function Updater(): null {
const
fetchList
=
useFetchListCallback
()
const
fetchList
=
useFetchListCallback
()
const
fetchAllListsCallback
=
useCallback
(()
=>
{
const
fetchAllListsCallback
=
useCallback
(()
=>
{
if
(
!
isWindowVisible
)
return
if
(
!
isWindowVisible
)
return
Object
.
keys
(
lists
)
.
forEach
((
url
)
=>
{
DEFAULT_LIST_OF_LISTS
.
forEach
((
url
)
=>
{
// Skip validation on unsupported lists
// Skip validation on unsupported lists
const
isUnsupportedList
=
UNSUPPORTED_LIST_URLS
.
includes
(
url
)
const
isUnsupportedList
=
UNSUPPORTED_LIST_URLS
.
includes
(
url
)
fetchList
(
url
,
false
,
isUnsupportedList
).
catch
((
error
)
=>
console
.
debug
(
'
interval list fetching error
'
,
error
))
fetchList
(
url
,
isUnsupportedList
).
catch
((
error
)
=>
console
.
debug
(
'
interval list fetching error
'
,
error
))
})
})
},
[
fetchList
,
isWindowVisible
,
lists
])
},
[
fetchList
,
isWindowVisible
])
// fetch all lists every 10 minutes, but only after we initialize provider
// fetch all lists every 10 minutes, but only after we initialize provider
useInterval
(
fetchAllListsCallback
,
provider
?
1000
*
60
*
10
:
null
)
useInterval
(
fetchAllListsCallback
,
provider
?
ms
`10m`
:
null
)
// whenever a list is not loaded and not loading, try again to load it
// whenever a list is not loaded and not loading, try again to load it
useEffect
(()
=>
{
useEffect
(()
=>
{
...
@@ -45,7 +46,9 @@ export default function Updater(): null {
...
@@ -45,7 +46,9 @@ export default function Updater(): null {
UNSUPPORTED_LIST_URLS
.
forEach
((
listUrl
)
=>
{
UNSUPPORTED_LIST_URLS
.
forEach
((
listUrl
)
=>
{
const
list
=
lists
[
listUrl
]
const
list
=
lists
[
listUrl
]
if
(
!
list
||
(
!
list
.
current
&&
!
list
.
loadingRequestId
&&
!
list
.
error
))
{
if
(
!
list
||
(
!
list
.
current
&&
!
list
.
loadingRequestId
&&
!
list
.
error
))
{
fetchList
(
listUrl
,
undefined
,
true
).
catch
((
error
)
=>
console
.
debug
(
'
list added fetching error
'
,
error
))
fetchList
(
listUrl
,
/* isUnsupportedList= */
true
).
catch
((
error
)
=>
console
.
debug
(
'
list added fetching error
'
,
error
)
)
}
}
})
})
},
[
dispatch
,
fetchList
,
lists
])
},
[
dispatch
,
fetchList
,
lists
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment