Skip to content

Commit 5a1a469

Browse files
committed
perf(multicall): remove the validation that caused app to feel sluggish
1 parent 4c28f34 commit 5a1a469

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

src/state/multicall/actions.test.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@ import { parseCallKey, toCallKey } from './actions'
22

33
describe('actions', () => {
44
describe('#parseCallKey', () => {
5-
it('throws for invalid address', () => {
6-
expect(() => parseCallKey('0x-0x')).toThrow('Invalid address: 0x')
5+
it('does not throw for invalid address', () => {
6+
expect(parseCallKey('0x-0x')).toEqual({ address: '0x', callData: '0x' })
77
})
8-
it('throws for invalid calldata', () => {
9-
expect(() => parseCallKey('0x6b175474e89094c44da98b954eedeac495271d0f-abc')).toThrow('Invalid hex: abc')
8+
it('does not throw for invalid calldata', () => {
9+
expect(parseCallKey('0x6b175474e89094c44da98b954eedeac495271d0f-abc')).toEqual({
10+
address: '0x6b175474e89094c44da98b954eedeac495271d0f',
11+
callData: 'abc'
12+
})
1013
})
1114
it('throws for invalid format', () => {
1215
expect(() => parseCallKey('abc')).toThrow('Invalid call key: abc')
1316
})
14-
it('throws for uppercase hex', () => {
15-
expect(() => parseCallKey('0x6b175474e89094c44da98b954eedeac495271d0f-0xabcD')).toThrow('Invalid hex: 0xabcD')
17+
it('throws for uppercase calldata', () => {
18+
expect(parseCallKey('0x6b175474e89094c44da98b954eedeac495271d0f-0xabcD')).toEqual({
19+
address: '0x6b175474e89094c44da98b954eedeac495271d0f',
20+
callData: '0xabcD'
21+
})
1622
})
1723
it('parses pieces into address', () => {
1824
expect(parseCallKey('0x6b175474e89094c44da98b954eedeac495271d0f-0xabcd')).toEqual({
19-
address: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
25+
address: '0x6b175474e89094c44da98b954eedeac495271d0f',
2026
callData: '0xabcd'
2127
})
2228
})
@@ -44,7 +50,7 @@ describe('actions', () => {
4450
})
4551
it('concatenates address to data', () => {
4652
expect(toCallKey({ address: '0x6b175474e89094c44da98b954eedeac495271d0f', callData: '0xabcd' })).toEqual(
47-
'0x6B175474E89094C44Da98b954EedeAC495271d0F-0xabcd'
53+
'0x6b175474e89094c44da98b954eedeac495271d0f-0xabcd'
4854
)
4955
})
5056
})

src/state/multicall/actions.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,29 @@
11
import { createAction } from '@reduxjs/toolkit'
2-
import { isAddress } from '../../utils'
32

43
export interface Call {
54
address: string
65
callData: string
76
}
87

8+
const ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/
99
const LOWER_HEX_REGEX = /^0x[a-f0-9]*$/
1010
export function toCallKey(call: Call): string {
11-
const addr = isAddress(call.address)
12-
if (!addr) {
11+
if (!ADDRESS_REGEX.test(call.address)) {
1312
throw new Error(`Invalid address: ${call.address}`)
1413
}
1514
if (!LOWER_HEX_REGEX.test(call.callData)) {
1615
throw new Error(`Invalid hex: ${call.callData}`)
1716
}
18-
return `${addr}-${call.callData}`
17+
return `${call.address}-${call.callData}`
1918
}
2019

2120
export function parseCallKey(callKey: string): Call {
2221
const pcs = callKey.split('-')
2322
if (pcs.length !== 2) {
2423
throw new Error(`Invalid call key: ${callKey}`)
2524
}
26-
const addr = isAddress(pcs[0])
27-
if (!addr) {
28-
throw new Error(`Invalid address: ${pcs[0]}`)
29-
}
30-
31-
if (!LOWER_HEX_REGEX.test(pcs[1])) {
32-
throw new Error(`Invalid hex: ${pcs[1]}`)
33-
}
34-
3525
return {
36-
address: addr,
26+
address: pcs[0],
3727
callData: pcs[1]
3828
}
3929
}

src/state/multicall/reducer.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import reducer, { MulticallState } from './reducer'
33
import { Store, createStore } from '@reduxjs/toolkit'
44

55
const DAI_ADDRESS = '0x6b175474e89094c44da98b954eedeac495271d0f'
6-
const CHECKSUMMED_DAI_ADDRESS = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
76

87
describe('multicall reducer', () => {
98
let store: Store<MulticallState>
@@ -32,7 +31,7 @@ describe('multicall reducer', () => {
3231
expect(store.getState()).toEqual({
3332
callListeners: {
3433
[1]: {
35-
[`${CHECKSUMMED_DAI_ADDRESS}-0x`]: {
34+
[`${DAI_ADDRESS}-0x`]: {
3635
[1]: 1
3736
}
3837
}
@@ -82,7 +81,7 @@ describe('multicall reducer', () => {
8281
)
8382
expect(store.getState()).toEqual({
8483
callResults: {},
85-
callListeners: { [1]: { [`${CHECKSUMMED_DAI_ADDRESS}-0x`]: {} } }
84+
callListeners: { [1]: { [`${DAI_ADDRESS}-0x`]: {} } }
8685
})
8786
})
8887
})

0 commit comments

Comments
 (0)