Skip to content

Commit acbafd0

Browse files
committed
fix: minBlockNumber select error
1 parent 6be360e commit acbafd0

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

packages/neuron-wallet/src/services/indexer/queue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export default class Queue {
126126
.map(state => state.blockNumber)
127127
const uniqueBlockNumbers = [...new Set(blockNumbers)]
128128
const blockNumbersBigInt = uniqueBlockNumbers.map(num => BigInt(num))
129-
const minBlockNumber = blockNumbersBigInt.sort()[0]
129+
const minBlockNumber = Utils.min(blockNumbersBigInt)
130130
return minBlockNumber
131131
}
132132

packages/neuron-wallet/src/services/sync/utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,20 @@ export default class Utils {
4848
}
4949
return result
5050
}
51+
52+
public static min = (array: bigint[]): bigint | undefined => {
53+
let minValue = array[0]
54+
if (!minValue) {
55+
return undefined
56+
}
57+
58+
for (let i = 1; i < array.length; ++i) {
59+
const value = array[i]
60+
if (value < minValue) {
61+
minValue = value
62+
}
63+
}
64+
65+
return minValue
66+
}
5167
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Utils from '../../../src/services/sync/utils'
2+
3+
describe('Key tests', () => {
4+
describe('min', () => {
5+
it('with empty array', () => {
6+
const arr: bigint[] = []
7+
const minValue = Utils.min(arr)
8+
expect(minValue).toBe(undefined)
9+
})
10+
11+
it('only one value', () => {
12+
const value = BigInt(1)
13+
const arr = [value]
14+
const minValue = Utils.min(arr)
15+
expect(minValue).toEqual(value)
16+
})
17+
18+
it('two value', () => {
19+
const arr = [BigInt(38050), BigInt(4058)]
20+
const minValue = Utils.min(arr)
21+
expect(minValue).toEqual(BigInt(4058))
22+
})
23+
})
24+
})

0 commit comments

Comments
 (0)