Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to new controller packages #16547

Merged
merged 23 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cbebe2f
Migrate to new controller packages
mcmire Nov 14, 2022
1469493
Support GitHub registry for draft PRs (#16549)
Gudahtt Nov 17, 2022
cfd2db9
Add additional allowed host to lockfile linter
Gudahtt Nov 17, 2022
2b63147
Merge branch 'develop' into migrate-to-new-controller-packages
mcmire Nov 17, 2022
cd9ea6e
Update LavaMoat policies
Gudahtt Nov 17, 2022
18e75db
Merge branch 'develop' into migrate-to-new-controller-packages
Gudahtt Nov 17, 2022
a08babb
Add policy exception for nanoid
Gudahtt Nov 17, 2022
f5e3960
Add additional nanoid overrides
Gudahtt Nov 17, 2022
e0bf6c4
Merge branch 'develop' into migrate-to-new-controller-packages
Gudahtt Nov 17, 2022
15b5841
Update LavaMoat policies again
Gudahtt Nov 17, 2022
ea58338
Merge branch 'develop' into migrate-to-new-controller-packages
mcmire Nov 18, 2022
0f96d68
Merge branch 'develop' into migrate-to-new-controller-packages
mcmire Nov 18, 2022
7f9747c
Merge branch 'develop' into migrate-to-new-controller-packages
mcmire Nov 21, 2022
4392e94
Bump controller packages
mcmire Nov 21, 2022
8a6a716
Update lavamoat
mcmire Nov 21, 2022
a2d7932
Bump controller packages
mcmire Nov 21, 2022
96ffd3a
Update packages to v1.0.0
Gudahtt Nov 22, 2022
bd0cf50
Expand gitignore comment
Gudahtt Nov 22, 2022
2f7761c
Merge remote-tracking branch 'origin/develop' into migrate-to-new-con…
Gudahtt Nov 22, 2022
762795a
Merge branch 'develop' into migrate-to-new-controller-packages
mcmire Nov 22, 2022
ca210aa
Merge branch 'develop' into migrate-to-new-controller-packages
mcmire Nov 22, 2022
ab9bb42
Merge remote-tracking branch 'origin/develop' into migrate-to-new-con…
Gudahtt Nov 24, 2022
ec2be79
Unpin controller dependencies, using ^ range instead
Gudahtt Nov 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ executors:
docker:
- image: koalaman/shellcheck-alpine@sha256:dfaf08fab58c158549d3be64fb101c626abc5f16f341b569092577ae207db199

orbs:
gh: circleci/[email protected]

workflows:
test_and_release:
jobs:
Expand Down Expand Up @@ -206,6 +209,27 @@ jobs:
- checkout
- restore_cache:
key: dependency-cache-v1-{{ checksum "yarn.lock" }}
- gh/install
- run:
name: Set IS_DRAFT environment variable
command: |
PR_NUMBER="${CIRCLE_PULL_REQUEST##*/}"
if [ -n "$PR_NUMBER" ]
then
echo "IS_DRAFT=$(gh pr view --json isDraft --jq '.isDraft' "$PR_NUMBER")" >> "$BASH_ENV"
source "$BASH_ENV"
else
echo "Not a PR; skipping"
fi
- run:
name: Setup registry config for using package previews on draft PRs
command: |
if [[ $IS_DRAFT == 'true' ]]
then
printf '%s\n\n%s' '@metamask:registry=https://npm.pkg.github.com' "//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGE_READ_TOKEN}" > .npmrc
else
echo "Not draft; skipping GitHub registry setup"
fi
- run:
name: Install deps
command: |
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ notes.txt
tsout/

# Test results
test-results/
test-results/

# This file is used to authenticate with the GitHub Package registry, to
# enable the use of @metamask preview builds.
.npmrc
Copy link
Contributor Author

@mcmire mcmire Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a temporary change and I can bring this out into a separate PR. For now, I've explained how this is used in the PR description. We want to gitignore it because if it's used for testing we don't want people's access tokens to end up in the repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I guess if we have the CircleCI config in this branch, we can have this here too since they're related.

4 changes: 2 additions & 2 deletions app/scripts/controllers/detect-tokens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import sinon from 'sinon';
import nock from 'nock';
import { ObservableStore } from '@metamask/obs-store';
import BigNumber from 'bignumber.js';
import { ControllerMessenger } from '@metamask/base-controller';
import {
ControllerMessenger,
TokenListController,
TokensController,
AssetsContractController,
} from '@metamask/controllers';
} from '@metamask/assets-controllers';
import { NETWORK_TYPES } from '../../../shared/constants/network';
import { toChecksumHexAddress } from '../../../shared/modules/hexstring-utils';
import DetectTokensController from './detect-tokens';
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/controllers/permissions/caveat-mutators.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CaveatMutatorOperation } from '@metamask/controllers';
import { CaveatMutatorOperation } from '@metamask/permission-controller';
import { CaveatTypes } from '../../../../shared/constants/permissions';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CaveatMutatorOperation } from '@metamask/controllers';
import { CaveatMutatorOperation } from '@metamask/permission-controller';
import { CaveatTypes } from '../../../../shared/constants/permissions';
import { CaveatMutatorFactories } from './caveat-mutators';

Expand Down
5 changes: 4 additions & 1 deletion app/scripts/controllers/permissions/specifications.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { constructPermission, PermissionType } from '@metamask/controllers';
import {
constructPermission,
PermissionType,
} from '@metamask/permission-controller';
///: BEGIN:ONLY_INCLUDE_IN(flask)
import { endowmentCaveatSpecifications as snapsEndowmentCaveatSpecifications } from '@metamask/snaps-controllers';
import { caveatSpecifications as snapsCaveatsSpecifications } from '@metamask/rpc-methods';
Expand Down
6 changes: 2 additions & 4 deletions app/scripts/controllers/preferences.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { strict as assert } from 'assert';
import sinon from 'sinon';
import {
ControllerMessenger,
TokenListController,
} from '@metamask/controllers';
import { ControllerMessenger } from '@metamask/base-controller';
import { TokenListController } from '@metamask/assets-controllers';
import { CHAIN_IDS } from '../../../shared/constants/network';
import PreferencesController from './preferences';
import NetworkController from './network';
Expand Down
8 changes: 4 additions & 4 deletions app/scripts/lib/ComposableObservableStore.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ObservableStore } from '@metamask/obs-store';
import { getPersistentState } from '@metamask/controllers';
import { getPersistentState } from '@metamask/base-controller';

/**
* @typedef {import('@metamask/controllers').ControllerMessenger} ControllerMessenger
* @typedef {import('@metamask/base-controller').ControllerMessenger} ControllerMessenger
*/

/**
Expand All @@ -13,7 +13,7 @@ export default class ComposableObservableStore extends ObservableStore {
/**
* Describes which stores are being composed. The key is the name of the
* store, and the value is either an ObserableStore, or a controller that
* extends one of the two base controllers in the `@metamask/controllers`
* extends one of the two base controllers in the `@metamask/base-controller`
* package.
*
* @type {Record<string, object>}
Expand Down Expand Up @@ -46,7 +46,7 @@ export default class ComposableObservableStore extends ObservableStore {
* @param {Record<string, object>} config - Describes which stores are being
* composed. The key is the name of the store, and the value is either an
* ObserableStore, or a controller that extends one of the two base
* controllers in the `@metamask/controllers` package.
* controllers in the `@metamask/base-controller` package.
*/
updateStructure(config) {
this.config = config;
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/lib/ComposableObservableStore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
BaseController,
BaseControllerV2,
ControllerMessenger,
} from '@metamask/controllers';
} from '@metamask/base-controller';
import ComposableObservableStore from './ComposableObservableStore';

class OldExampleController extends BaseController {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///: BEGIN:ONLY_INCLUDE_IN(flask)
import { handlers as permittedSnapMethods } from '@metamask/rpc-methods/dist/permitted';
///: END:ONLY_INCLUDE_IN
import { permissionRpcMethods } from '@metamask/controllers';
import { permissionRpcMethods } from '@metamask/permission-controller';
import { selectHooks } from '@metamask/rpc-methods/dist/utils';
import { ethErrors } from 'eth-rpc-errors';
import { flatten } from 'lodash';
Expand Down
6 changes: 2 additions & 4 deletions app/scripts/metamask-controller.actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { strict as assert } from 'assert';
import sinon from 'sinon';
import proxyquire from 'proxyquire';

import {
ApprovalRequestNotFoundError,
PermissionsRequestNotFoundError,
} from '@metamask/controllers';
import { ApprovalRequestNotFoundError } from '@metamask/approval-controller';
import { PermissionsRequestNotFoundError } from '@metamask/permission-controller';
import { ORIGIN_METAMASK } from '../../shared/constants/app';

const Ganache = require('../../test/e2e/ganache');
Expand Down
34 changes: 19 additions & 15 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,33 @@ import { MetaMaskKeyring as QRHardwareKeyring } from '@keystonehq/metamask-airga
import EthQuery from 'eth-query';
import nanoid from 'nanoid';
import { captureException } from '@sentry/browser';
import { AddressBookController } from '@metamask/address-book-controller';
import {
AddressBookController,
ApprovalController,
ControllerMessenger,
ApprovalRequestNotFoundError,
} from '@metamask/approval-controller';
import { ControllerMessenger } from '@metamask/base-controller';
import {
CurrencyRateController,
PhishingController,
AnnouncementController,
GasFeeController,
TokenListController,
TokensController,
TokenRatesController,
NftController,
AssetsContractController,
NftDetectionController,
} from '@metamask/assets-controllers';
import { PhishingController } from '@metamask/phishing-controller';
import { AnnouncementController } from '@metamask/announcement-controller';
import { GasFeeController } from '@metamask/gas-fee-controller';
import {
PermissionController,
SubjectMetadataController,
PermissionsRequestNotFoundError,
ApprovalRequestNotFoundError,
///: BEGIN:ONLY_INCLUDE_IN(flask)
RateLimitController,
NotificationController,
///: END:ONLY_INCLUDE_IN
} from '@metamask/controllers';
} from '@metamask/permission-controller';
import { SubjectMetadataController } from '@metamask/subject-metadata-controller';
///: BEGIN:ONLY_INCLUDE_IN(flask)
import { RateLimitController } from '@metamask/rate-limit-controller';
import { NotificationController } from '@metamask/notification-controller';
///: END:ONLY_INCLUDE_IN
import SmartTransactionsController from '@metamask/smart-transactions-controller';
///: BEGIN:ONLY_INCLUDE_IN(flask)
import {
Expand Down Expand Up @@ -165,7 +169,7 @@ export const METAMASK_CONTROLLER_EVENTS = {
// Fired after state changes that impact the extension badge (unapproved msg count)
// The process of updating the badge happens in app/scripts/background.js.
UPDATE_BADGE: 'updateBadge',
// TODO: Add this and similar enums to @metamask/controllers and export them
// TODO: Add this and similar enums to the `controllers` repo and export them
APPROVAL_STATE_CHANGE: 'ApprovalController:stateChange',
};

Expand Down Expand Up @@ -1273,8 +1277,8 @@ export default class MetamaskController extends EventEmitter {
* changes.
*
* Some of the subscriptions in this method are ControllerMessenger selector
* event subscriptions. See the relevant @metamask/controllers documentation
* for more information.
* event subscriptions. See the relevant documentation for
* `@metamask/base-controller` for more information.
*
* Note that account-related notifications emitted when the extension
* becomes unlocked are handled in MetaMaskController._onUnlock.
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/migrations/037.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cloneDeep } from 'lodash';
import { util } from '@metamask/controllers';
import { normalizeEnsName } from '@metamask/controller-utils';

const version = 37;

Expand Down Expand Up @@ -38,7 +38,7 @@ function transformState(state) {
for (const address in ab) {
if (ab[address].chainId === id) {
ab[address].isEns = false;
if (util.normalizeEnsName(ab[address].name)) {
if (normalizeEnsName(ab[address].name)) {
ab[address].isEns = true;
}
newAddressBook[id][address] = ab[address];
Expand Down
Loading