Skip to content

Commit

Permalink
Merge tag 'v29.0.1'
Browse files Browse the repository at this point in the history
jyap808 committed Jul 1, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 5226aae + a21d5a4 commit 18c4307
Showing 73 changed files with 1,981 additions and 1,232 deletions.
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [29.0.1]
### Added
- Add SupportedTokenDetectionNetworks enum and util for token detection support. ([#811](https://github.com/MetaMask/controllers/pull/811))

### Fixed
- Fix bug introduced in v29.0.0 where `createNewVaultAndRestore` would crash with a validation failure. ([#819](https://github.com/MetaMask/controllers/pull/819))


## [29.0.0]
### Added
- Reintroduce NotificationController for in-app notifications ([#709](https://github.com/MetaMask/controllers/pull/709))
- Add optional token service timeout parameter([#793](https://github.com/MetaMask/controllers/pull/793))

### Changed
- **BREAKING**: Bump eth-keyring-controller to 7.0.1 ([#802](https://github.com/MetaMask/controllers/pull/802))
- Mnemonics in keyrings of type `HD Key Tree` are always serialized as arrays of numbers. `exportSeedPhrase` now returns a buffer rather than a string, consumers will need to adapt to this new return type accordingly.

## [28.0.0]
### Added
- Add GrantPermissions action to PermissionsController ([#780](https://github.com/MetaMask/controllers/pull/780))
@@ -549,7 +566,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed
- Remove shapeshift controller (#209)

[Unreleased]: https://github.com/MetaMask/controllers/compare/v28.0.0...HEAD
[Unreleased]: https://github.com/MetaMask/controllers/compare/v29.0.1...HEAD
[29.0.1]: https://github.com/MetaMask/controllers/compare/v29.0.0...v29.0.1
[29.0.0]: https://github.com/MetaMask/controllers/compare/v28.0.0...v29.0.0
[28.0.0]: https://github.com/MetaMask/controllers/compare/v27.1.1...v28.0.0
[27.1.1]: https://github.com/MetaMask/controllers/compare/v27.1.0...v27.1.1
[27.1.0]: https://github.com/MetaMask/controllers/compare/v27.0.0...v27.1.0
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -16,14 +16,14 @@ module.exports = {
},
moduleFileExtensions: ['js', 'json', 'ts', 'node'],
preset: 'ts-jest',
// TODO: Enable resetMocks and restoreMocks
// TODO: Enable resetMocks
// "resetMocks" resets all mocks, including mocked modules, to jest.fn(),
// between each test case.
// resetMocks: true,
// "restoreMocks" restores all mocks created using jest.spyOn to their
// original implementations, between each test. It does not affect mocked
// modules.
// restoreMocks: true,
restoreMocks: true,
setupFiles: ['./tests/setupTests.ts'],
testEnvironment: 'jsdom',
testRegex: ['\\.test\\.(ts|js)$'],
39 changes: 20 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sparrow-controllers",
"version": "28.0.0",
"version": "29.0.1",
"description": "Collection of platform-agnostic modules for creating secure data models for cryptocurrency wallets",
"keywords": [
"Sparrow",
@@ -21,18 +21,18 @@
"dist/"
],
"scripts": {
"setup": "yarn install && yarn allow-scripts",
"prepublishOnly": "yarn build",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' --ignore-path .gitignore",
"build": "rimraf dist && tsc --project tsconfig.build.json",
"build:link": "yarn build && cd dist && yarn link && rm -rf node_modules && cd ..",
"build:watch": "yarn build --watch",
"doc": "typedoc && touch docs/.nojekyll",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' --ignore-path .gitignore",
"prepublishOnly": "yarn build",
"setup": "yarn install && yarn allow-scripts",
"test": "jest",
"test:watch": "jest --watch",
"build": "rimraf dist && tsc --project tsconfig.build.json",
"build:watch": "yarn build --watch",
"build:link": "yarn build && cd dist && yarn link && rm -rf node_modules && cd ..",
"doc": "typedoc && touch docs/.nojekyll"
"test:watch": "jest --watch"
},
"dependencies": {
"@ethereumjs/common": "^2.3.1",
@@ -47,7 +47,7 @@
"deep-freeze-strict": "^1.1.1",
"eth-ens-namehash": "^2.0.8",
"eth-json-rpc-infura": "^5.1.0",
"eth-keyring-controller": "^6.2.1",
"eth-keyring-controller": "^7.0.2",
"eth-method-registry": "1.1.0",
"eth-phishing-detect": "^1.1.16",
"eth-query": "^2.1.2",
@@ -86,28 +86,29 @@
"@types/punycode": "^2.1.0",
"@types/sinon": "^9.0.10",
"@types/web3": "^1.0.6",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.24.0",
"eslint-config-prettier": "^8.1.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.5",
"eslint-plugin-jsdoc": "^36.1.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-prettier": "^3.4.1",
"ethjs-provider-http": "^0.1.6",
"jest": "^26.4.2",
"jest-environment-jsdom": "^25.0.0",
"jest-when": "^3.4.2",
"nock": "^13.0.7",
"prettier": "^2.2.1",
"prettier-plugin-packagejson": "^2.2.11",
"prettier": "^2.6.2",
"prettier-plugin-packagejson": "^2.2.17",
"rimraf": "^3.0.2",
"sinon": "^9.2.4",
"ts-jest": "^26.5.2",
"typedoc": "^0.20.32",
"typescript": "~4.2.2"
"typedoc": "^0.22.15",
"typedoc-plugin-missing-exports": "^0.22.6",
"typescript": "~4.6.3"
},
"engines": {
"node": ">=12.0.0"
12 changes: 8 additions & 4 deletions src/BaseController.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stub } from 'sinon';
import sinon from 'sinon';
import { BaseController, BaseConfig, BaseState } from './BaseController';

const STATE = { name: 'foo' };
@@ -12,6 +12,10 @@ class TestController extends BaseController<BaseConfig, BaseState> {
}

describe('BaseController', () => {
afterEach(() => {
sinon.restore();
});

it('should set initial state', () => {
const controller = new TestController(undefined, STATE);
expect(controller.state).toStrictEqual(STATE);
@@ -45,8 +49,8 @@ describe('BaseController', () => {

it('should notify all listeners', () => {
const controller = new TestController(undefined, STATE);
const listenerOne = stub();
const listenerTwo = stub();
const listenerOne = sinon.stub();
const listenerTwo = sinon.stub();
controller.subscribe(listenerOne);
controller.subscribe(listenerTwo);
controller.notify();
@@ -58,7 +62,7 @@ describe('BaseController', () => {

it('should not notify unsubscribed listeners', () => {
const controller = new TestController();
const listener = stub();
const listener = sinon.stub();
controller.subscribe(listener);
controller.unsubscribe(listener);
controller.unsubscribe(() => null);
11 changes: 7 additions & 4 deletions src/BaseControllerV2.test.ts
Original file line number Diff line number Diff line change
@@ -83,6 +83,10 @@ class CountController extends BaseController<
}

describe('BaseController', () => {
afterEach(() => {
sinon.restore();
});

it('should set initial state', () => {
const controller = new CountController({
messenger: getCountMessenger(),
@@ -779,13 +783,12 @@ describe('getPersistentState', () => {
const visitorController = new VisitorController(
visitorControllerMessenger,
);
const visitorOverflowControllerMessenger = controllerMessenger.getRestricted(
{
const visitorOverflowControllerMessenger =
controllerMessenger.getRestricted({
name: visitorOverflowName,
allowedActions: ['VisitorController:clear'],
allowedEvents: ['VisitorController:stateChange'],
},
);
});
const visitorOverflowController = new VisitorOverflowController(
visitorOverflowControllerMessenger,
);
19 changes: 10 additions & 9 deletions src/BaseControllerV2.ts
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ export type Json =
export class BaseController<
N extends string,
S extends Record<string, Json>,
messenger extends RestrictedControllerMessenger<N, any, any, string, string>
messenger extends RestrictedControllerMessenger<N, any, any, string, string>,
> {
private internalState: S;

@@ -92,11 +92,10 @@ export class BaseController<

/**
* The existence of the `subscribe` property is how the ComposableController detects whether a
* controller extends the old BaseController or the new one. We set it to `never` here to ensure
* this property is never used for new BaseController-based controllers, to ensure the
* ComposableController never mistakes them for an older style controller.
* controller extends the old BaseController or the new one. We set it to `undefined` here to
* ensure the ComposableController never mistakes them for an older style controller.
*/
public readonly subscribe: never;
public readonly subscribe: undefined;

/**
* Creates a BaseController instance.
@@ -158,10 +157,12 @@ export class BaseController<
// We run into ts2589, "infinite type depth", if we don't cast
// produceWithPatches here.
// The final, omitted member of the returned tuple are the inverse patches.
const [nextState, patches] = ((produceWithPatches as unknown) as (
state: S,
cb: typeof callback,
) => [S, Patch[], Patch[]])(this.internalState, callback);
const [nextState, patches] = (
produceWithPatches as unknown as (
state: S,
cb: typeof callback,
) => [S, Patch[], Patch[]]
)(this.internalState, callback);

this.internalState = nextState;
this.messagingSystem.publish(
16 changes: 10 additions & 6 deletions src/ComposableController.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stub } from 'sinon';
import sinon from 'sinon';
import type { Patch } from 'immer';
import { TokensController } from './assets/TokensController';
import { CollectiblesController } from './assets/CollectiblesController';
@@ -74,7 +74,7 @@ class BarController extends BaseController<never, BarControllerState> {
bar: 'bar',
};

name = 'BarController';
override name = 'BarController';

constructor() {
super();
@@ -87,6 +87,10 @@ class BarController extends BaseController<never, BarControllerState> {
}

describe('ComposableController', () => {
afterEach(() => {
sinon.restore();
});

describe('BaseController', () => {
it('should compose controller state', () => {
const preferencesController = new PreferencesController();
@@ -268,7 +272,7 @@ describe('ComposableController', () => {
it('should notify listeners of nested state change', () => {
const addressBookController = new AddressBookController();
const controller = new ComposableController([addressBookController]);
const listener = stub();
const listener = sinon.stub();
controller.subscribe(listener);
addressBookController.set(
'0x32Be343B94f860124dC4fEe278FDCBD38C102D88',
@@ -381,7 +385,7 @@ describe('ComposableController', () => {
composableControllerMessenger,
);

const listener = stub();
const listener = sinon.stub();
composableController.subscribe(listener);
fooController.updateFoo('bar');

@@ -486,7 +490,7 @@ describe('ComposableController', () => {
composableControllerMessenger,
);

const listener = stub();
const listener = sinon.stub();
composableController.subscribe(listener);
barController.updateBar('foo');

@@ -528,7 +532,7 @@ describe('ComposableController', () => {
composableControllerMessenger,
);

const listener = stub();
const listener = sinon.stub();
composableController.subscribe(listener);
fooController.updateFoo('bar');

2 changes: 1 addition & 1 deletion src/ComposableController.ts
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ export class ComposableController extends BaseController<never, any> {
/**
* Name of this controller used during composition
*/
name = 'ComposableController';
override name = 'ComposableController';

/**
* Creates a ComposableController instance.
14 changes: 6 additions & 8 deletions src/ControllerMessenger.test.ts
Original file line number Diff line number Diff line change
@@ -956,11 +956,10 @@ describe('RestrictedControllerMessenger', () => {
handler: (increment: number) => void;
};
const controllerMessenger = new ControllerMessenger<CountAction, never>();
const externalRestrictedControllerMessenger = controllerMessenger.getRestricted(
{
const externalRestrictedControllerMessenger =
controllerMessenger.getRestricted({
name: 'CountController',
},
);
});
const restrictedControllerMessenger = controllerMessenger.getRestricted({
name: 'OtherController',
allowedActions: ['CountController:count'],
@@ -984,11 +983,10 @@ describe('RestrictedControllerMessenger', () => {
payload: [string];
};
const controllerMessenger = new ControllerMessenger<never, MessageEvent>();
const externalRestrictedControllerMessenger = controllerMessenger.getRestricted(
{
const externalRestrictedControllerMessenger =
controllerMessenger.getRestricted({
name: 'MessageController',
},
);
});
const restrictedControllerMessenger = controllerMessenger.getRestricted({
name: 'OtherController',
allowedEvents: ['MessageController:message'],
6 changes: 3 additions & 3 deletions src/ControllerMessenger.ts
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ export class RestrictedControllerMessenger<
Action extends ActionConstraint,
Event extends EventConstraint,
AllowedAction extends string,
AllowedEvent extends string
AllowedEvent extends string,
> {
private controllerMessenger: ControllerMessenger<
ActionConstraint,
@@ -352,7 +352,7 @@ export class RestrictedControllerMessenger<
*/
export class ControllerMessenger<
Action extends ActionConstraint,
Event extends EventConstraint
Event extends EventConstraint,
> {
private actions = new Map<Action['type'], unknown>();

@@ -595,7 +595,7 @@ export class ControllerMessenger<
getRestricted<
N extends string,
AllowedAction extends string,
AllowedEvent extends string
AllowedEvent extends string,
>({
name,
allowedActions,
Loading

0 comments on commit 18c4307

Please sign in to comment.