diff --git a/packages/neuron-wallet/src/services/cells.ts b/packages/neuron-wallet/src/services/cells.ts index c70df83127..231efa00db 100644 --- a/packages/neuron-wallet/src/services/cells.ts +++ b/packages/neuron-wallet/src/services/cells.ts @@ -53,25 +53,22 @@ export default class CellsService { ): Promise> => { const skip = (page - 1) * perPage - const query = getConnection() + const outputsAndCount: [OutputEntity[], number] = await getConnection() .getRepository(OutputEntity) .createQueryBuilder('output') .leftJoinAndSelect('output.transaction', 'tx') .where(`output.daoData IS NOT NULL AND output.lockHash in (:...lockHashes)`, { lockHashes, }) - - const totalCount: number = await query.getCount() - const outputs: OutputEntity[] = await query .orderBy(`CASE output.daoData WHEN '0x0000000000000000' THEN 1 ELSE 0 END`, 'ASC') .addOrderBy('tx.timestamp', 'ASC') .skip(skip) - .take(perPage) - .getMany() + .limit(perPage) + .getManyAndCount() return { - totalCount, - items: outputs.map(o => o.toInterface()), + totalCount: outputsAndCount[1], + items: outputsAndCount[0].map(o => o.toInterface()), } } diff --git a/packages/neuron-wallet/tests/services/cells.test.ts b/packages/neuron-wallet/tests/services/cells.test.ts index 5d679de910..ca9c7138d8 100644 --- a/packages/neuron-wallet/tests/services/cells.test.ts +++ b/packages/neuron-wallet/tests/services/cells.test.ts @@ -352,15 +352,18 @@ describe('CellsService', () => { }) it('get all in correct order', async () => { - const cells = await CellsService.getDaoCells() - console.warn(cells.map(c => c.capacity)) + const cells = await CellsService.getDaoCells( + [bob.lockHash], + 1, + 10 + ) const expectedCapacitySort = [ '2000', '4000', '1000', '3000', ].map(capacity => toShannon(capacity)) - expect(cells.map(c => c.capacity)).toEqual(expectedCapacitySort) + expect(cells.items.map(c => c.capacity)).toEqual(expectedCapacitySort) }) }) })