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
5a1a469f
Unverified
Commit
5a1a469f
authored
Jun 03, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf(multicall): remove the validation that caused app to feel sluggish
parent
4c28f348
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
25 deletions
+20
-25
actions.test.ts
src/state/multicall/actions.test.ts
+14
-8
actions.ts
src/state/multicall/actions.ts
+4
-14
reducer.test.ts
src/state/multicall/reducer.test.ts
+2
-3
No files found.
src/state/multicall/actions.test.ts
View file @
5a1a469f
...
@@ -2,21 +2,27 @@ import { parseCallKey, toCallKey } from './actions'
...
@@ -2,21 +2,27 @@ import { parseCallKey, toCallKey } from './actions'
describe
(
'
actions
'
,
()
=>
{
describe
(
'
actions
'
,
()
=>
{
describe
(
'
#parseCallKey
'
,
()
=>
{
describe
(
'
#parseCallKey
'
,
()
=>
{
it
(
'
throws
for invalid address
'
,
()
=>
{
it
(
'
does not throw
for invalid address
'
,
()
=>
{
expect
(
()
=>
parseCallKey
(
'
0x-0x
'
)).
toThrow
(
'
Invalid address: 0x
'
)
expect
(
parseCallKey
(
'
0x-0x
'
)).
toEqual
({
address
:
'
0x
'
,
callData
:
'
0x
'
}
)
})
})
it
(
'
throws for invalid calldata
'
,
()
=>
{
it
(
'
does not throw for invalid calldata
'
,
()
=>
{
expect
(()
=>
parseCallKey
(
'
0x6b175474e89094c44da98b954eedeac495271d0f-abc
'
)).
toThrow
(
'
Invalid hex: abc
'
)
expect
(
parseCallKey
(
'
0x6b175474e89094c44da98b954eedeac495271d0f-abc
'
)).
toEqual
({
address
:
'
0x6b175474e89094c44da98b954eedeac495271d0f
'
,
callData
:
'
abc
'
})
})
})
it
(
'
throws for invalid format
'
,
()
=>
{
it
(
'
throws for invalid format
'
,
()
=>
{
expect
(()
=>
parseCallKey
(
'
abc
'
)).
toThrow
(
'
Invalid call key: abc
'
)
expect
(()
=>
parseCallKey
(
'
abc
'
)).
toThrow
(
'
Invalid call key: abc
'
)
})
})
it
(
'
throws for uppercase hex
'
,
()
=>
{
it
(
'
throws for uppercase calldata
'
,
()
=>
{
expect
(()
=>
parseCallKey
(
'
0x6b175474e89094c44da98b954eedeac495271d0f-0xabcD
'
)).
toThrow
(
'
Invalid hex: 0xabcD
'
)
expect
(
parseCallKey
(
'
0x6b175474e89094c44da98b954eedeac495271d0f-0xabcD
'
)).
toEqual
({
address
:
'
0x6b175474e89094c44da98b954eedeac495271d0f
'
,
callData
:
'
0xabcD
'
})
})
})
it
(
'
parses pieces into address
'
,
()
=>
{
it
(
'
parses pieces into address
'
,
()
=>
{
expect
(
parseCallKey
(
'
0x6b175474e89094c44da98b954eedeac495271d0f-0xabcd
'
)).
toEqual
({
expect
(
parseCallKey
(
'
0x6b175474e89094c44da98b954eedeac495271d0f-0xabcd
'
)).
toEqual
({
address
:
'
0x6
B175474E89094C44Da98b954EedeAC495271d0F
'
,
address
:
'
0x6
b175474e89094c44da98b954eedeac495271d0f
'
,
callData
:
'
0xabcd
'
callData
:
'
0xabcd
'
})
})
})
})
...
@@ -44,7 +50,7 @@ describe('actions', () => {
...
@@ -44,7 +50,7 @@ describe('actions', () => {
})
})
it
(
'
concatenates address to data
'
,
()
=>
{
it
(
'
concatenates address to data
'
,
()
=>
{
expect
(
toCallKey
({
address
:
'
0x6b175474e89094c44da98b954eedeac495271d0f
'
,
callData
:
'
0xabcd
'
})).
toEqual
(
expect
(
toCallKey
({
address
:
'
0x6b175474e89094c44da98b954eedeac495271d0f
'
,
callData
:
'
0xabcd
'
})).
toEqual
(
'
0x6
B175474E89094C44Da98b954EedeAC495271d0F
-0xabcd
'
'
0x6
b175474e89094c44da98b954eedeac495271d0f
-0xabcd
'
)
)
})
})
})
})
...
...
src/state/multicall/actions.ts
View file @
5a1a469f
import
{
createAction
}
from
'
@reduxjs/toolkit
'
import
{
createAction
}
from
'
@reduxjs/toolkit
'
import
{
isAddress
}
from
'
../../utils
'
export
interface
Call
{
export
interface
Call
{
address
:
string
address
:
string
callData
:
string
callData
:
string
}
}
const
ADDRESS_REGEX
=
/^0x
[
a-fA-F0-9
]{40}
$/
const
LOWER_HEX_REGEX
=
/^0x
[
a-f0-9
]
*$/
const
LOWER_HEX_REGEX
=
/^0x
[
a-f0-9
]
*$/
export
function
toCallKey
(
call
:
Call
):
string
{
export
function
toCallKey
(
call
:
Call
):
string
{
const
addr
=
isAddress
(
call
.
address
)
if
(
!
ADDRESS_REGEX
.
test
(
call
.
address
))
{
if
(
!
addr
)
{
throw
new
Error
(
`Invalid address:
${
call
.
address
}
`
)
throw
new
Error
(
`Invalid address:
${
call
.
address
}
`
)
}
}
if
(
!
LOWER_HEX_REGEX
.
test
(
call
.
callData
))
{
if
(
!
LOWER_HEX_REGEX
.
test
(
call
.
callData
))
{
throw
new
Error
(
`Invalid hex:
${
call
.
callData
}
`
)
throw
new
Error
(
`Invalid hex:
${
call
.
callData
}
`
)
}
}
return
`
${
addr
}
-
${
call
.
callData
}
`
return
`
${
call
.
address
}
-
${
call
.
callData
}
`
}
}
export
function
parseCallKey
(
callKey
:
string
):
Call
{
export
function
parseCallKey
(
callKey
:
string
):
Call
{
...
@@ -23,17 +22,8 @@ export function parseCallKey(callKey: string): Call {
...
@@ -23,17 +22,8 @@ export function parseCallKey(callKey: string): Call {
if
(
pcs
.
length
!==
2
)
{
if
(
pcs
.
length
!==
2
)
{
throw
new
Error
(
`Invalid call key:
${
callKey
}
`
)
throw
new
Error
(
`Invalid call key:
${
callKey
}
`
)
}
}
const
addr
=
isAddress
(
pcs
[
0
])
if
(
!
addr
)
{
throw
new
Error
(
`Invalid address:
${
pcs
[
0
]}
`
)
}
if
(
!
LOWER_HEX_REGEX
.
test
(
pcs
[
1
]))
{
throw
new
Error
(
`Invalid hex:
${
pcs
[
1
]}
`
)
}
return
{
return
{
address
:
addr
,
address
:
pcs
[
0
]
,
callData
:
pcs
[
1
]
callData
:
pcs
[
1
]
}
}
}
}
...
...
src/state/multicall/reducer.test.ts
View file @
5a1a469f
...
@@ -3,7 +3,6 @@ import reducer, { MulticallState } from './reducer'
...
@@ -3,7 +3,6 @@ import reducer, { MulticallState } from './reducer'
import
{
Store
,
createStore
}
from
'
@reduxjs/toolkit
'
import
{
Store
,
createStore
}
from
'
@reduxjs/toolkit
'
const
DAI_ADDRESS
=
'
0x6b175474e89094c44da98b954eedeac495271d0f
'
const
DAI_ADDRESS
=
'
0x6b175474e89094c44da98b954eedeac495271d0f
'
const
CHECKSUMMED_DAI_ADDRESS
=
'
0x6B175474E89094C44Da98b954EedeAC495271d0F
'
describe
(
'
multicall reducer
'
,
()
=>
{
describe
(
'
multicall reducer
'
,
()
=>
{
let
store
:
Store
<
MulticallState
>
let
store
:
Store
<
MulticallState
>
...
@@ -32,7 +31,7 @@ describe('multicall reducer', () => {
...
@@ -32,7 +31,7 @@ describe('multicall reducer', () => {
expect
(
store
.
getState
()).
toEqual
({
expect
(
store
.
getState
()).
toEqual
({
callListeners
:
{
callListeners
:
{
[
1
]:
{
[
1
]:
{
[
`
${
CHECKSUMMED_
DAI_ADDRESS
}
-0x`
]:
{
[
`
${
DAI_ADDRESS
}
-0x`
]:
{
[
1
]:
1
[
1
]:
1
}
}
}
}
...
@@ -82,7 +81,7 @@ describe('multicall reducer', () => {
...
@@ -82,7 +81,7 @@ describe('multicall reducer', () => {
)
)
expect
(
store
.
getState
()).
toEqual
({
expect
(
store
.
getState
()).
toEqual
({
callResults
:
{},
callResults
:
{},
callListeners
:
{
[
1
]:
{
[
`
${
CHECKSUMMED_
DAI_ADDRESS
}
-0x`
]:
{}
}
}
callListeners
:
{
[
1
]:
{
[
`
${
DAI_ADDRESS
}
-0x`
]:
{}
}
}
})
})
})
})
})
})
...
...
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