Skip to content

Commit 2460b0b

Browse files
committed
fix: getDaoCells and its tests
1 parent 41953bf commit 2460b0b

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

packages/neuron-wallet/src/services/cells.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,22 @@ export default class CellsService {
5353
): Promise<PaginationResult<Cell>> => {
5454
const skip = (page - 1) * perPage
5555

56-
const query = getConnection()
56+
const outputsAndCount: [OutputEntity[], number] = await getConnection()
5757
.getRepository(OutputEntity)
5858
.createQueryBuilder('output')
5959
.leftJoinAndSelect('output.transaction', 'tx')
6060
.where(`output.daoData IS NOT NULL AND output.lockHash in (:...lockHashes)`, {
6161
lockHashes,
6262
})
63-
64-
const totalCount: number = await query.getCount()
65-
const outputs: OutputEntity[] = await query
6663
.orderBy(`CASE output.daoData WHEN '0x0000000000000000' THEN 1 ELSE 0 END`, 'ASC')
6764
.addOrderBy('tx.timestamp', 'ASC')
6865
.skip(skip)
69-
.take(perPage)
70-
.getMany()
66+
.limit(perPage)
67+
.getManyAndCount()
7168

7269
return {
73-
totalCount,
74-
items: outputs.map(o => o.toInterface()),
70+
totalCount: outputsAndCount[1],
71+
items: outputsAndCount[0].map(o => o.toInterface()),
7572
}
7673
}
7774

packages/neuron-wallet/tests/services/cells.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,18 @@ describe('CellsService', () => {
352352
})
353353

354354
it('get all in correct order', async () => {
355-
const cells = await CellsService.getDaoCells()
356-
console.warn(cells.map(c => c.capacity))
355+
const cells = await CellsService.getDaoCells(
356+
[bob.lockHash],
357+
1,
358+
10
359+
)
357360
const expectedCapacitySort = [
358361
'2000',
359362
'4000',
360363
'1000',
361364
'3000',
362365
].map(capacity => toShannon(capacity))
363-
expect(cells.map(c => c.capacity)).toEqual(expectedCapacitySort)
366+
expect(cells.items.map(c => c.capacity)).toEqual(expectedCapacitySort)
364367
})
365368
})
366369
})

0 commit comments

Comments
 (0)