From 2ada1fb27e837567220fdd3aa4714fa3e5da0d43 Mon Sep 17 00:00:00 2001 From: tomiir Date: Thu, 21 Mar 2024 12:36:18 +0000 Subject: [PATCH 1/3] chore: reset cursor when opening transaction history views --- packages/core/src/controllers/TransactionsController.ts | 5 +++++ packages/scaffold/src/partials/w3m-activity-list/index.ts | 1 + .../scaffold/src/views/w3m-onramp-activity-view/index.ts | 1 + 3 files changed, 7 insertions(+) diff --git a/packages/core/src/controllers/TransactionsController.ts b/packages/core/src/controllers/TransactionsController.ts index 095041948c..ec27d8c4e4 100644 --- a/packages/core/src/controllers/TransactionsController.ts +++ b/packages/core/src/controllers/TransactionsController.ts @@ -86,6 +86,7 @@ export const TransactionsController = { SnackController.showError('Failed to fetch transactions') state.loading = false state.empty = true + state.next = undefined } }, @@ -125,6 +126,10 @@ export const TransactionsController = { }) }, + clearCursor() { + state.next = undefined + }, + resetTransactions() { state.transactions = [] state.transactionsByYear = {} diff --git a/packages/scaffold/src/partials/w3m-activity-list/index.ts b/packages/scaffold/src/partials/w3m-activity-list/index.ts index 9455b0e7cc..76e44e28f2 100644 --- a/packages/scaffold/src/partials/w3m-activity-list/index.ts +++ b/packages/scaffold/src/partials/w3m-activity-list/index.ts @@ -42,6 +42,7 @@ export class W3mActivityList extends LitElement { // -- Lifecycle ----------------------------------------- // public constructor() { super() + TransactionsController.clearCursor() this.unsubscribe.push( ...[ AccountController.subscribe(val => { diff --git a/packages/scaffold/src/views/w3m-onramp-activity-view/index.ts b/packages/scaffold/src/views/w3m-onramp-activity-view/index.ts index da214f83d0..f4c99cbb1a 100644 --- a/packages/scaffold/src/views/w3m-onramp-activity-view/index.ts +++ b/packages/scaffold/src/views/w3m-onramp-activity-view/index.ts @@ -49,6 +49,7 @@ export class W3mOnRampActivityView extends LitElement { }) ] ) + TransactionsController.clearCursor() this.fetchTransactions() } From e6aa2db60fa098f513f631bdbef7e0835f4963e4 Mon Sep 17 00:00:00 2001 From: tomiir Date: Tue, 26 Mar 2024 09:52:36 -0300 Subject: [PATCH 2/3] chore: add cursor test. Fix connector and account tests --- packages/core/package.json | 2 +- .../core/src/controllers/AccountController.ts | 3 ++- .../controllers/AccountController.test.ts | 16 +++++++++-- .../controllers/ConnectorController.test.ts | 9 +++++-- .../TransactionsController.test.ts | 27 +++++++++++++++++++ 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 9e1551490c..83faa28ed8 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -13,7 +13,7 @@ "build:core": "tsc --build", "watch": "tsc --watch", "typecheck": "tsc --noEmit", - "test": "vitest run --dir tests --coverage.enabled --reporter=junit --coverage.reporter=json-summary --coverage.reporter=html", + "test": "vitest run --dir tests --coverage.enabled --coverage.reporter=json-summary --coverage.reporter=html", "lint": "eslint . --ext .js,.jsx,.ts,.tsx" }, "dependencies": { diff --git a/packages/core/src/controllers/AccountController.ts b/packages/core/src/controllers/AccountController.ts index c32819e57a..c08195cb73 100644 --- a/packages/core/src/controllers/AccountController.ts +++ b/packages/core/src/controllers/AccountController.ts @@ -99,6 +99,7 @@ export const AccountController = { resetAccount() { state.isConnected = false + state.currentTab = 0 state.caipAddress = undefined state.address = undefined state.balance = undefined @@ -107,6 +108,6 @@ export const AccountController = { state.profileImage = undefined state.addressExplorerUrl = undefined state.smartAccountDeployed = undefined - state.currentTab = 0 + state.tokenBalance = [] } } diff --git a/packages/core/tests/controllers/AccountController.test.ts b/packages/core/tests/controllers/AccountController.test.ts index 94768cf7d4..9f57384fff 100644 --- a/packages/core/tests/controllers/AccountController.test.ts +++ b/packages/core/tests/controllers/AccountController.test.ts @@ -11,7 +11,7 @@ const profileImage = 'https://ipfs.com/0x123.png' // -- Tests -------------------------------------------------------------------- describe('AccountController', () => { it('should have valid default state', () => { - expect(AccountController.state).toEqual({ isConnected: false }) + expect(AccountController.state).toEqual({ isConnected: false, tokenBalance: [], currentTab: 0 }) }) it('should update state correctly on setIsConnected()', () => { @@ -43,6 +43,18 @@ describe('AccountController', () => { it('should update state correctly on resetAccount()', () => { AccountController.resetAccount() - expect(AccountController.state).toEqual({ isConnected: false }) + expect(AccountController.state).toEqual({ + isConnected: false, + currentTab: 0, + caipAddress: undefined, + address: undefined, + balance: undefined, + balanceSymbol: undefined, + profileName: undefined, + profileImage: undefined, + addressExplorerUrl: undefined, + smartAccountDeployed: undefined, + tokenBalance: [] + }) }) }) diff --git a/packages/core/tests/controllers/ConnectorController.test.ts b/packages/core/tests/controllers/ConnectorController.test.ts index 1d33736a33..20b0aa7a56 100644 --- a/packages/core/tests/controllers/ConnectorController.test.ts +++ b/packages/core/tests/controllers/ConnectorController.test.ts @@ -9,7 +9,10 @@ const metamaskConnector = { type: 'INJECTED', info: { rdns: 'io.metamask.com' } } as const - +const zerionConnector = { + id: 'ecc4036f814562b41a5268adc86270fba1365471402006302e70169465b7ac18', + type: 'INJECTED' +} as const // -- Tests -------------------------------------------------------------------- describe('ConnectorController', () => { it('should have valid default state', () => { @@ -37,8 +40,10 @@ describe('ConnectorController', () => { }) it('should return the correct connector on getConnector', () => { - expect(ConnectorController.getConnector('walletConnect', '')).toBe(walletConnectConnector) + ConnectorController.addConnector(zerionConnector) + expect(ConnectorController.getConnector('walletConnect', '')).toBe(undefined) expect(ConnectorController.getConnector('', 'io.metamask.com')).toBe(metamaskConnector) + expect(ConnectorController.getConnector(zerionConnector.id, '')).toBeUndefined() expect(ConnectorController.getConnector('unknown', '')).toBeUndefined() }) }) diff --git a/packages/core/tests/controllers/TransactionsController.test.ts b/packages/core/tests/controllers/TransactionsController.test.ts index 75c2833b4b..7f397c8986 100644 --- a/packages/core/tests/controllers/TransactionsController.test.ts +++ b/packages/core/tests/controllers/TransactionsController.test.ts @@ -238,4 +238,31 @@ describe('TransactionsController', () => { } }) }) + + it('should clear cursor correctly', async () => { + // Mock fetch transactions + const fetchTransactions = vi + .spyOn(BlockchainApiController, 'fetchTransactions') + .mockResolvedValue({ + data: [], + next: 'cursor' + }) + + // Fetch transactions + await TransactionsController.fetchTransactions('0x123') + expect(TransactionsController.state.next).toBe('cursor') + + TransactionsController.clearCursor() + expect(TransactionsController.state.next).toBeUndefined() + + // Fetch transactions again + await TransactionsController.fetchTransactions('0x123') + expect(fetchTransactions).toHaveBeenCalledWith({ + account: '0x123', + projectId, + cursor: undefined, + onramp: undefined + }) + expect(TransactionsController.state.next).toBe('cursor') + }) }) From 4820c860a3b7acfcaed22e9f130685f708737466 Mon Sep 17 00:00:00 2001 From: tomiir Date: Wed, 27 Mar 2024 09:24:31 -0300 Subject: [PATCH 3/3] chore: readd junit --- packages/core/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/package.json b/packages/core/package.json index 83faa28ed8..9e1551490c 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -13,7 +13,7 @@ "build:core": "tsc --build", "watch": "tsc --watch", "typecheck": "tsc --noEmit", - "test": "vitest run --dir tests --coverage.enabled --coverage.reporter=json-summary --coverage.reporter=html", + "test": "vitest run --dir tests --coverage.enabled --reporter=junit --coverage.reporter=json-summary --coverage.reporter=html", "lint": "eslint . --ext .js,.jsx,.ts,.tsx" }, "dependencies": {