diff --git a/packages/extension-chrome/__tests__/services/ownership/fullOwnership.test.ts b/packages/extension-chrome/__tests__/services/ownership/fullOwnership.test.ts index 713f6ef5..3516ace0 100644 --- a/packages/extension-chrome/__tests__/services/ownership/fullOwnership.test.ts +++ b/packages/extension-chrome/__tests__/services/ownership/fullOwnership.test.ts @@ -111,7 +111,7 @@ describe('FullOwnership', () => { }); }); - it('should get live cells', async () => { + it('should get live cells with default change', async () => { await ownershipService.getLiveCells({}); expect(backend.getLiveCellsByLocks).toBeCalledWith({ cursor: '', @@ -119,6 +119,22 @@ describe('FullOwnership', () => { }); }); + it('should get external live cells with change set to external', async () => { + await ownershipService.getLiveCells({ change: 'external' }); + expect(backend.getLiveCellsByLocks).toBeCalledWith({ + cursor: '', + locks: [scriptInfos[1].lock], + }); + }); + + it('should get internal live cells with change set to internal', async () => { + await ownershipService.getLiveCells({ change: 'internal' }); + expect(backend.getLiveCellsByLocks).toBeCalledWith({ + cursor: '', + locks: [scriptInfos[3].lock], + }); + }); + it('should signData by keystore service with proper params', async () => { await ownershipService.signData({ data: '0x1234', lock: scriptInfos[0].lock, url: MOCK_PLATFORM_URL }); expect(keystoreService.signMessage).toBeCalledWith({ diff --git a/packages/extension-chrome/src/services/ownership/fullOwnership.ts b/packages/extension-chrome/src/services/ownership/fullOwnership.ts index 9b6caa84..45a457d1 100644 --- a/packages/extension-chrome/src/services/ownership/fullOwnership.ts +++ b/packages/extension-chrome/src/services/ownership/fullOwnership.ts @@ -42,7 +42,7 @@ export function createFullOwnershipService({ } return { - getLiveCells: async ({ cursor: encodedCursor } = {}) => { + getLiveCells: async ({ cursor: encodedCursor, change } = {}) => { const db = await getDb(); const backend = await backendProvider.resolve(); @@ -50,14 +50,19 @@ export function createFullOwnershipService({ const queryCursor: CellCursor = encodedCursor ? decodeCursor(encodedCursor) : { indexerCursor: '', localId: 0 }; - const onChainLocks = infos - .filter( - (info) => - info.status === 'OnChain' && - // only fetch cells after or containing this lock - info.id >= queryCursor.localId, - ) - .map((info) => info.lock); + let onChainInfos = infos.filter( + (info) => + info.status === 'OnChain' && + // only fetch cells after or containing this lock + info.id >= queryCursor.localId, + ); + + // by default, will return both `external` and `internal` cells. If `change` is specified, will only return cells of the specified type. + if (change) { + onChainInfos = onChainInfos.filter(filterByChange(change)); + } + + const onChainLocks = onChainInfos.map((info) => info.lock); const { objects, cursor, lastLock } = await backend.getLiveCellsByLocks({ locks: onChainLocks,