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
29db0a50
Unverified
Commit
29db0a50
authored
Jun 10, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(multicall): reduce spam in error case
parent
9566fb88
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
3 deletions
+98
-3
reducer.test.ts
src/state/multicall/reducer.test.ts
+92
-1
reducer.ts
src/state/multicall/reducer.ts
+6
-2
No files found.
src/state/multicall/reducer.test.ts
View file @
29db0a50
import
{
addMulticallListeners
,
removeMulticallListeners
,
updateMulticallResults
}
from
'
./actions
'
import
{
addMulticallListeners
,
errorFetchingMulticallResults
,
fetchingMulticallResults
,
removeMulticallListeners
,
updateMulticallResults
}
from
'
./actions
'
import
reducer
,
{
MulticallState
}
from
'
./reducer
'
import
reducer
,
{
MulticallState
}
from
'
./reducer
'
import
{
Store
,
createStore
}
from
'
@reduxjs/toolkit
'
import
{
Store
,
createStore
}
from
'
@reduxjs/toolkit
'
...
@@ -169,4 +175,89 @@ describe('multicall reducer', () => {
...
@@ -169,4 +175,89 @@ describe('multicall reducer', () => {
})
})
})
})
})
})
describe
(
'
fetchingMulticallResults
'
,
()
=>
{
it
(
'
updates state to fetching
'
,
()
=>
{
store
.
dispatch
(
fetchingMulticallResults
({
chainId
:
1
,
fetchingBlockNumber
:
2
,
calls
:
[{
address
:
DAI_ADDRESS
,
callData
:
'
0x0
'
}]
})
)
expect
(
store
.
getState
()).
toEqual
({
callResults
:
{
[
1
]:
{
[
`
${
DAI_ADDRESS
}
-0x0`
]:
{
fetchingBlockNumber
:
2
}
}
}
})
})
})
describe
(
'
errorFetchingMulticallResults
'
,
()
=>
{
it
(
'
does nothing if not fetching
'
,
()
=>
{
store
.
dispatch
(
errorFetchingMulticallResults
({
chainId
:
1
,
fetchingBlockNumber
:
1
,
calls
:
[{
address
:
DAI_ADDRESS
,
callData
:
'
0x0
'
}]
})
)
expect
(
store
.
getState
()).
toEqual
({
callResults
:
{
[
1
]:
{}
}
})
})
it
(
'
updates block number if we were fetching
'
,
()
=>
{
store
.
dispatch
(
fetchingMulticallResults
({
chainId
:
1
,
fetchingBlockNumber
:
2
,
calls
:
[{
address
:
DAI_ADDRESS
,
callData
:
'
0x0
'
}]
})
)
store
.
dispatch
(
errorFetchingMulticallResults
({
chainId
:
1
,
fetchingBlockNumber
:
2
,
calls
:
[{
address
:
DAI_ADDRESS
,
callData
:
'
0x0
'
}]
})
)
expect
(
store
.
getState
()).
toEqual
({
callResults
:
{
[
1
]:
{
[
`
${
DAI_ADDRESS
}
-0x0`
]:
{
blockNumber
:
2
,
// null data indicates error
data
:
null
}
}
}
})
})
it
(
'
does nothing if not errored on latest block
'
,
()
=>
{
store
.
dispatch
(
fetchingMulticallResults
({
chainId
:
1
,
fetchingBlockNumber
:
3
,
calls
:
[{
address
:
DAI_ADDRESS
,
callData
:
'
0x0
'
}]
})
)
store
.
dispatch
(
errorFetchingMulticallResults
({
chainId
:
1
,
fetchingBlockNumber
:
2
,
calls
:
[{
address
:
DAI_ADDRESS
,
callData
:
'
0x0
'
}]
})
)
expect
(
store
.
getState
()).
toEqual
({
callResults
:
{
[
1
]:
{
[
`
${
DAI_ADDRESS
}
-0x0`
]:
{
fetchingBlockNumber
:
3
}
}
}
})
})
})
})
})
src/state/multicall/reducer.ts
View file @
29db0a50
...
@@ -89,8 +89,12 @@ export default createReducer(initialState, builder =>
...
@@ -89,8 +89,12 @@ export default createReducer(initialState, builder =>
calls
.
forEach
(
call
=>
{
calls
.
forEach
(
call
=>
{
const
callKey
=
toCallKey
(
call
)
const
callKey
=
toCallKey
(
call
)
const
current
=
state
.
callResults
[
chainId
][
callKey
]
const
current
=
state
.
callResults
[
chainId
][
callKey
]
if
(
current
&&
current
.
fetchingBlockNumber
!==
fetchingBlockNumber
)
return
if
(
!
current
)
return
// only should be dispatched if we are already fetching
delete
current
.
fetchingBlockNumber
if
(
current
.
fetchingBlockNumber
===
fetchingBlockNumber
)
{
delete
current
.
fetchingBlockNumber
current
.
data
=
null
current
.
blockNumber
=
fetchingBlockNumber
}
})
})
})
})
.
addCase
(
updateMulticallResults
,
(
state
,
{
payload
:
{
chainId
,
results
,
blockNumber
}
})
=>
{
.
addCase
(
updateMulticallResults
,
(
state
,
{
payload
:
{
chainId
,
results
,
blockNumber
}
})
=>
{
...
...
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