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/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/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') + }) }) 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() }