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
f289dec6
Unverified
Commit
f289dec6
authored
May 30, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(multicall reducer): add test and fix update multicall results
parent
73d3df05
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
2 deletions
+86
-2
reducer.test.ts
src/state/multicall/reducer.test.ts
+85
-1
reducer.ts
src/state/multicall/reducer.ts
+1
-1
No files found.
src/state/multicall/reducer.test.ts
View file @
f289dec6
import
{
addMulticallListeners
,
removeMulticallListeners
}
from
'
./actions
'
import
{
addMulticallListeners
,
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
'
...
@@ -80,4 +80,88 @@ describe('multicall reducer', () => {
...
@@ -80,4 +80,88 @@ describe('multicall reducer', () => {
expect
(
store
.
getState
()).
toEqual
({
callResults
:
{},
callListeners
:
{
[
1
]:
{
'
0x-0x
'
:
{}
}
}
})
expect
(
store
.
getState
()).
toEqual
({
callResults
:
{},
callListeners
:
{
[
1
]:
{
'
0x-0x
'
:
{}
}
}
})
})
})
})
})
describe
(
'
updateMulticallResults
'
,
()
=>
{
it
(
'
updates data if not present
'
,
()
=>
{
store
.
dispatch
(
updateMulticallResults
({
chainId
:
1
,
blockNumber
:
1
,
results
:
{
abc
:
'
0x
'
}
})
)
expect
(
store
.
getState
()).
toEqual
({
callResults
:
{
[
1
]:
{
abc
:
{
blockNumber
:
1
,
data
:
'
0x
'
}
}
}
})
})
it
(
'
updates old data
'
,
()
=>
{
store
.
dispatch
(
updateMulticallResults
({
chainId
:
1
,
blockNumber
:
1
,
results
:
{
abc
:
'
0x
'
}
})
)
store
.
dispatch
(
updateMulticallResults
({
chainId
:
1
,
blockNumber
:
2
,
results
:
{
abc
:
'
0x2
'
}
})
)
expect
(
store
.
getState
()).
toEqual
({
callResults
:
{
[
1
]:
{
abc
:
{
blockNumber
:
2
,
data
:
'
0x2
'
}
}
}
})
})
it
(
'
ignores late updates
'
,
()
=>
{
store
.
dispatch
(
updateMulticallResults
({
chainId
:
1
,
blockNumber
:
2
,
results
:
{
abc
:
'
0x2
'
}
})
)
store
.
dispatch
(
updateMulticallResults
({
chainId
:
1
,
blockNumber
:
1
,
results
:
{
abc
:
'
0x1
'
}
})
)
expect
(
store
.
getState
()).
toEqual
({
callResults
:
{
[
1
]:
{
abc
:
{
blockNumber
:
2
,
data
:
'
0x2
'
}
}
}
})
})
})
})
})
src/state/multicall/reducer.ts
View file @
f289dec6
...
@@ -97,7 +97,7 @@ export default createReducer(initialState, builder =>
...
@@ -97,7 +97,7 @@ export default createReducer(initialState, builder =>
state
.
callResults
[
chainId
]
=
state
.
callResults
[
chainId
]
??
{}
state
.
callResults
[
chainId
]
=
state
.
callResults
[
chainId
]
??
{}
Object
.
keys
(
results
).
forEach
(
callKey
=>
{
Object
.
keys
(
results
).
forEach
(
callKey
=>
{
const
current
=
state
.
callResults
[
chainId
][
callKey
]
const
current
=
state
.
callResults
[
chainId
][
callKey
]
if
(
current
?.
blockNumber
??
0
>
blockNumber
)
return
if
(
(
current
?.
blockNumber
??
0
)
>
blockNumber
)
return
state
.
callResults
[
chainId
][
callKey
]
=
{
state
.
callResults
[
chainId
][
callKey
]
=
{
data
:
results
[
callKey
],
data
:
results
[
callKey
],
blockNumber
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