Skip to content

Commit

Permalink
Merge branch 'main' into feature/add-bifrost-logo
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomepan authored Jan 18, 2025
2 parents 77d5542 + 2751a0d commit 52b8947
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 211 deletions.
25 changes: 17 additions & 8 deletions app/scripts/controllers/account-tracker-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,23 @@ describe('AccountTrackerController', () => {
});
});

it('should gracefully handle unknown polling tokens', async () => {
await withController(({ controller, blockTrackerFromHookStub }) => {
jest.spyOn(controller, 'updateAccounts').mockResolvedValue();

const pollingToken =
controller.startPollingByNetworkClientId('mainnet');

controller.stopPollingByPollingToken('unknown-token');
controller.stopPollingByPollingToken(pollingToken);

expect(blockTrackerFromHookStub.removeListener).toHaveBeenCalledWith(
'latest',
expect.any(Function),
);
});
});

it('should not unsubscribe from the block tracker if called with one of multiple active polling tokens for a given networkClient', async () => {
await withController(({ controller, blockTrackerFromHookStub }) => {
jest.spyOn(controller, 'updateAccounts').mockResolvedValue();
Expand All @@ -391,14 +408,6 @@ describe('AccountTrackerController', () => {
}).toThrow('pollingToken required');
});
});

it('should error if no matching pollingToken is found', async () => {
await withController(({ controller }) => {
expect(() => {
controller.stopPollingByPollingToken('potato');
}).toThrow('pollingToken not found');
});
});
});

describe('stopAll', () => {
Expand Down
5 changes: 0 additions & 5 deletions app/scripts/controllers/account-tracker-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,20 +403,15 @@ export default class AccountTrackerController extends BaseController<
if (!pollingToken) {
throw new Error('pollingToken required');
}
let found = false;
this.#pollingTokenSets.forEach((tokenSet, key) => {
if (tokenSet.has(pollingToken)) {
found = true;
tokenSet.delete(pollingToken);
if (tokenSet.size === 0) {
this.#pollingTokenSets.delete(key);
this.#unsubscribeWithNetworkClientId(key);
}
}
});
if (!found) {
throw new Error('pollingToken not found');
}
}

/**
Expand Down
Loading

0 comments on commit 52b8947

Please sign in to comment.