Skip to content

Commit

Permalink
Migrate to new controller packages
Browse files Browse the repository at this point in the history
`@metamask/controllers` is deprecated, and most of the controllers that
lived here are now located in their own package ([1]). This commit
replaces `@metamask/controllers` in `package.json` with references to
these packages and updates `import` lines to match.

[1]: MetaMask/core#831
  • Loading branch information
mcmire authored and Gudahtt committed Dec 8, 2022
1 parent 30e8bb8 commit 799214e
Show file tree
Hide file tree
Showing 59 changed files with 369 additions and 195 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -85,3 +85,6 @@ tests

# attributions
licenseInfos.json

# Allows access to preview versions of @metamask/* packages for testing
.npmrc
8 changes: 2 additions & 6 deletions app/components/Base/RemoteImage/index.js
Expand Up @@ -8,7 +8,7 @@ import { SvgUri } from 'react-native-svg';
import isUrl from 'is-url';
import ComponentErrorBoundary from '../../UI/ComponentErrorBoundary';
import useIpfsGateway from '../../hooks/useIpfsGateway';
import { util } from '@metamask/controllers';
import { getFormattedIpfsUrl } from '@metamask/assets-controllers';
import Identicon from '../../UI/Identicon';

const createStyles = () =>
Expand All @@ -29,11 +29,7 @@ const RemoteImage = (props) => {
try {
const url = new URL(props.source.uri);
if (url.protocol !== 'ipfs:') return false;
const ipfsUrl = util.getFormattedIpfsUrl(
ipfsGateway,
props.source.uri,
false,
);
const ipfsUrl = getFormattedIpfsUrl(ipfsGateway, props.source.uri, false);
return ipfsUrl;
} catch {
return false;
Expand Down
10 changes: 5 additions & 5 deletions app/components/Nav/Main/RootRPCMethodsUI.js
Expand Up @@ -44,7 +44,7 @@ import {
toggleApproveModal,
} from '../../../actions/modals';
import { swapsUtils } from '@metamask/swaps-controller';
import { util } from '@metamask/controllers';
import { query } from '@metamask/controller-utils';
import Analytics from '../../../core/Analytics/Analytics';
import { ANALYTICS_EVENT_OPTS } from '../../../util/analytics';
import BigNumber from 'bignumber.js';
Expand Down Expand Up @@ -138,25 +138,25 @@ const RootRPCMethodsUI = (props) => {
TransactionController.state.transactions.find(
({ id }) => id === approvalTransactionMetaId,
);
const ethBalance = await util.query(
const ethBalance = await query(
TransactionController.ethQuery,
'getBalance',
[props.selectedAddress],
);
const receipt = await util.query(
const receipt = await query(
TransactionController.ethQuery,
'getTransactionReceipt',
[transactionMeta.transactionHash],
);

const currentBlock = await util.query(
const currentBlock = await query(
TransactionController.ethQuery,
'getBlockByHash',
[receipt.blockHash, false],
);
let approvalReceipt;
if (approvalTransaction?.transactionHash) {
approvalReceipt = await util.query(
approvalReceipt = await query(
TransactionController.ethQuery,
'getTransactionReceipt',
[approvalTransaction.transactionHash],
Expand Down
4 changes: 2 additions & 2 deletions app/components/Nav/Main/index.js
Expand Up @@ -34,7 +34,7 @@ import {
import ProtectYourWalletModal from '../../UI/ProtectYourWalletModal';
import MainNavigator from './MainNavigator';
import SkipAccountSecurityModal from '../../UI/SkipAccountSecurityModal';
import { util } from '@metamask/controllers';
import { query } from '@metamask/controller-utils';
import SwapsLiveness from '../../UI/Swaps/SwapsLiveness';

import {
Expand Down Expand Up @@ -119,7 +119,7 @@ const Main = (props) => {
if (props.providerType !== 'rpc') {
try {
const { TransactionController } = Engine.context;
await util.query(TransactionController.ethQuery, 'blockNumber', []);
await query(TransactionController.ethQuery, 'blockNumber', []);
props.setInfuraAvailabilityNotBlocked();
} catch (e) {
if (e.message === AppConstants.ERRORS.INFURA_BLOCKED_MESSAGE) {
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/AccountList/index.js
@@ -1,5 +1,5 @@
import React, { PureComponent } from 'react';
import { KeyringTypes } from '@metamask/controllers';
import { KeyringTypes } from '@metamask/keyring-controller';
import Engine from '../../../core/Engine';
import PropTypes from 'prop-types';
import {
Expand Down Expand Up @@ -334,7 +334,7 @@ class AccountList extends PureComponent {
getAccounts() {
const { accounts, identities, selectedAddress, keyrings, getBalanceError } =
this.props;
// This is a temporary fix until we can read the state from @metamask/controllers
// This is a temporary fix until we can read the state from @metamask/keyring-controller
const allKeyrings =
keyrings && keyrings.length
? keyrings
Expand Down
5 changes: 2 additions & 3 deletions app/components/UI/ApproveTransactionReview/index.js
Expand Up @@ -18,7 +18,8 @@ import {
import Engine from '../../../core/Engine';
import { strings } from '../../../../locales/i18n';
import { setTransactionObject } from '../../../actions/transaction';
import { GAS_ESTIMATE_TYPES, util } from '@metamask/controllers';
import { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';
import { hexToBN } from '@metamask/controller-utils';
import { fromTokenMinimalUnit } from '../../../util/number';
import EthereumAddress from '../EthereumAddress';
import {
Expand Down Expand Up @@ -60,8 +61,6 @@ import { allowedToBuy } from '../FiatOrders';
import { MM_SDK_REMOTE_ORIGIN } from '../../../core/SDKConnect';
import createStyles from './styles';

const { hexToBN } = util;

const { ORIGIN_DEEPLINK, ORIGIN_QR_CODE } = AppConstants.DEEPLINKS;

/**
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/AssetSearch/index.tsx
Expand Up @@ -7,7 +7,7 @@ import Icon from 'react-native-vector-icons/FontAwesome';
import { toLowerCaseEquals } from '../../../util/general';
import { useSelector } from 'react-redux';
import { getTokenListArray } from '../../../reducers/tokens';
import { TokenListToken } from '@metamask/controllers';
import { TokenListToken } from '@metamask/assets-controllers';
import { useTheme } from '../../../util/theme';

const createStyles = (colors: any) =>
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/DrawerView/index.js
Expand Up @@ -67,7 +67,7 @@ import { collectiblesSelector } from '../../../reducers/collectibles';
import { getCurrentRoute } from '../../../reducers/navigation';
import { ScrollView } from 'react-native-gesture-handler';
import { isZero } from '../../../util/lodash';
import { KeyringTypes } from '@metamask/controllers';
import { KeyringTypes } from '@metamask/keyring-controller';
import { ThemeContext, mockTheme } from '../../../util/theme';
import NetworkInfo from '../NetworkInfo';
import sanitizeUrl from '../../../util/sanitizeUrl';
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/EditGasFeeLegacy/index.js
Expand Up @@ -8,7 +8,7 @@ import {
TouchableWithoutFeedback,
} from 'react-native';
import PropTypes from 'prop-types';
import { GAS_ESTIMATE_TYPES } from '@metamask/controllers';
import { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';
import BigNumber from 'bignumber.js';
import Text from '../../Base/Text';
import StyledButton from '../StyledButton';
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/EditGasFeeLegacyUpdate/index.tsx
Expand Up @@ -6,7 +6,7 @@ import {
ScrollView,
TouchableWithoutFeedback,
} from 'react-native';
import { GAS_ESTIMATE_TYPES } from '@metamask/controllers';
import { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';
import BigNumber from 'bignumber.js';
import Text from '../../Base/Text';
import StyledButton from '../StyledButton';
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/NetworkInfo/index.tsx
Expand Up @@ -13,7 +13,7 @@ import {
NETWORK_EDUCATION_MODAL_NETWORK_NAME_ID,
} from '../../../constants/test-ids';
import { fontStyles } from '../../../styles/common';
import { util as controllerUtils } from '@metamask/controllers';
import { isTokenDetectionSupportedForNetwork } from '@metamask/assets-controllers';
import { NETWORK_EDUCATION_MODAL_CLOSE_BUTTON } from '../../../../wdio/features/testIDs/Screens/NetworksScreen.testids.js';
const createStyles = (colors: {
background: { default: string };
Expand Down Expand Up @@ -131,7 +131,7 @@ const NetworkInfo = (props: NetworkInfoProps) => {
const { colors } = useTheme();
const styles = createStyles(colors);
const isTokenDetectionSupported =
controllerUtils.isTokenDetectionSupportedForNetwork(chainId);
isTokenDetectionSupportedForNetwork(chainId);

const isTokenDetectionEnabledForNetwork = useMemo(() => {
if (isTokenDetectionSupported && isTokenDetectionEnabled) {
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/NetworkMainAssetLogo/index.js
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { NetworksChainId } from '@metamask/controllers';
import { NetworksChainId } from '@metamask/controller-utils';
import { connect } from 'react-redux';
import TokenIcon from '../Swaps/components/TokenIcon';

Expand Down
Expand Up @@ -19,7 +19,7 @@ import TransactionDetails from '../../TransactionElement/TransactionDetails';
import BaseNotification from './../BaseNotification';
import Device from '../../../../util/device';
import ElevatedView from 'react-native-elevated-view';
import { CANCEL_RATE, SPEED_UP_RATE } from '@metamask/controllers';
import { CANCEL_RATE, SPEED_UP_RATE } from '@metamask/transaction-controller';
import BigNumber from 'bignumber.js';
import { collectibleContractsSelector } from '../../../../reducers/collectibles';
import { useTheme } from '../../../../util/theme';
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/PaymentRequest/index.js
Expand Up @@ -40,14 +40,14 @@ import {
} from '../../../util/payment-link-generator';
import Device from '../../../util/device';
import currencySymbols from '../../../util/currency-symbols.json';
import { NetworksChainId } from '@metamask/controllers';
import { NetworksChainId } from '@metamask/controller-utils';
import { getTicker } from '../../../util/transactions';
import { toLowerCaseEquals } from '../../../util/general';
import { getTokenListArray } from '../../../reducers/tokens';
import { utils as ethersUtils } from 'ethers';
import { ThemeContext, mockTheme } from '../../../util/theme';
import { isTestNet } from '../../../util/networks';
import { isTokenDetectionSupportedForNetwork } from '@metamask/controllers/dist/util';
import { isTokenDetectionSupportedForNetwork } from '@metamask/assets-controllers';

const KEYBOARD_OFFSET = 120;
const createStyles = (colors) =>
Expand Down
5 changes: 2 additions & 3 deletions app/components/UI/PersonalSign/index.js
Expand Up @@ -6,7 +6,7 @@ import { fontStyles } from '../../../styles/common';
import Engine from '../../../core/Engine';
import SignatureRequest from '../SignatureRequest';
import ExpandedMessage from '../SignatureRequest/ExpandedMessage';
import { util } from '@metamask/controllers';
import { hexToText } from '@metamask/controller-utils';
import NotificationManager from '../../../core/NotificationManager';
import { strings } from '../../../../locales/i18n';
import { WALLET_CONNECT_ORIGIN } from '../../../util/walletconnect';
Expand Down Expand Up @@ -191,8 +191,7 @@ class PersonalSign extends PureComponent {
const { truncateMessage } = this.state;
const styles = this.getStyles();

const textChild = util
.hexToText(messageParams.data)
const textChild = hexToText(messageParams.data)
.split('\n')
.map((line, i) => (
<Text
Expand Down
10 changes: 5 additions & 5 deletions app/components/UI/Swaps/QuotesView.js
Expand Up @@ -17,10 +17,10 @@ import { useNavigation, useRoute } from '@react-navigation/native';
import { swapsUtils } from '@metamask/swaps-controller';
import {
WalletDevice,
util,
GAS_ESTIMATE_TYPES,
TransactionStatus,
} from '@metamask/controllers/';
} from '@metamask/transaction-controller';
import { query } from '@metamask/controller-utils';
import { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';

import {
addHexPrefix,
Expand Down Expand Up @@ -758,12 +758,12 @@ function SwapsQuotesView({
newSwapsTransactions,
) => {
const { TransactionController } = Engine.context;
const blockNumber = await util.query(
const blockNumber = await query(
TransactionController.ethQuery,
'blockNumber',
[],
);
const currentBlock = await util.query(
const currentBlock = await query(
TransactionController.ethQuery,
'getBlockByNumber',
[blockNumber, false],
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/Swaps/components/GasEditModal.js
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { StyleSheet, TouchableOpacity } from 'react-native';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
import Modal from 'react-native-modal';
import { GAS_ESTIMATE_TYPES } from '@metamask/controllers';
import { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';
import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons';
import { connect } from 'react-redux';

Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/TransactionEditor/index.js
Expand Up @@ -28,7 +28,7 @@ import { safeToChecksumAddress } from '../../../util/address';
import { shallowEqual } from '../../../util/general';
import EditGasFee1559 from '../EditGasFee1559';
import EditGasFeeLegacy from '../EditGasFeeLegacy';
import { GAS_ESTIMATE_TYPES } from '@metamask/controllers';
import { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';
import AppConstants from '../../../core/AppConstants';
import {
estimateGas,
Expand Down
7 changes: 5 additions & 2 deletions app/components/UI/TransactionElement/index.js
Expand Up @@ -23,9 +23,12 @@ import ListItem from '../../Base/ListItem';
import StatusText from '../../Base/StatusText';
import DetailsModal from '../../Base/DetailsModal';
import { isMainNet } from '../../../util/networks';
import { WalletDevice, util } from '@metamask/controllers/';
import { weiHexToGweiDec } from '@metamask/controller-utils';
import {
WalletDevice,
isEIP1559Transaction,
} from '@metamask/transaction-controller';
import { ThemeContext, mockTheme } from '../../../util/theme';
const { weiHexToGweiDec, isEIP1559Transaction } = util;

const createStyles = (colors) =>
StyleSheet.create({
Expand Down
3 changes: 1 addition & 2 deletions app/components/UI/TransactionElement/utils.js
Expand Up @@ -30,8 +30,7 @@ import { swapsUtils } from '@metamask/swaps-controller';
import { isSwapsNativeAsset } from '../Swaps/utils';
import { toLowerCaseEquals } from '../../../util/general';
import Engine from '../../../core/Engine';
import { util } from '@metamask/controllers';
const { isEIP1559Transaction } = util;
import { isEIP1559Transaction } from '@metamask/transaction-controller';

const { getSwapsContractAddress } = swapsUtils;

Expand Down
Expand Up @@ -34,7 +34,7 @@ import { getNetworkNonce, isTestNet } from '../../../../util/networks';
import CustomNonceModal from '../../../UI/CustomNonceModal';
import { setNonce, setProposedNonce } from '../../../../actions/transaction';
import TransactionReviewEIP1559 from '../TransactionReviewEIP1559';
import { GAS_ESTIMATE_TYPES } from '@metamask/controllers';
import { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';
import CustomNonce from '../../../UI/CustomNonce';
import Logger from '../../../../util/Logger';
import { ThemeContext, mockTheme } from '../../../../util/theme';
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/Transactions/index.js
Expand Up @@ -29,7 +29,7 @@ import TransactionElement from '../TransactionElement';
import Engine from '../../../core/Engine';
import { showAlert } from '../../../actions/alert';
import NotificationManager from '../../../core/NotificationManager';
import { CANCEL_RATE, SPEED_UP_RATE } from '@metamask/controllers';
import { CANCEL_RATE, SPEED_UP_RATE } from '@metamask/transaction-controller';
import { renderFromWei } from '../../../util/number';
import Device from '../../../util/device';
import { RPC, NO_RPC_BLOCK_EXPLORER } from '../../../constants/network';
Expand Down
7 changes: 2 additions & 5 deletions app/components/UI/UpdateEIP1559Tx/index.tsx
Expand Up @@ -2,11 +2,8 @@
import React, { useState, useEffect, useCallback, useRef } from 'react';
import EditGasFee1559Update from '../EditGasFee1559Update';
import { connect } from 'react-redux';
import {
CANCEL_RATE,
SPEED_UP_RATE,
GAS_ESTIMATE_TYPES,
} from '@metamask/controllers';
import { CANCEL_RATE, SPEED_UP_RATE } from '@metamask/transaction-controller';
import { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';
import { hexToBN, fromWei, renderFromWei } from '../../../util/number';
import BigNumber from 'bignumber.js';
import { getTicker } from '../../../util/transactions';
Expand Down
4 changes: 2 additions & 2 deletions app/components/Views/AddAsset/index.js
Expand Up @@ -12,7 +12,7 @@ import AddCustomCollectible from '../../UI/AddCustomCollectible';
import { getNetworkNavbarOptions } from '../../UI/Navbar';
import CollectibleDetectionModal from '../../UI/CollectibleDetectionModal';
import { isMainNet } from '../../../util/networks';
import { util as controllerUtils } from '@metamask/controllers';
import { isTokenDetectionSupportedForNetwork } from '@metamask/assets-controllers';
import { ThemeContext, mockTheme } from '../../../util/theme';

const createStyles = (colors) =>
Expand Down Expand Up @@ -127,7 +127,7 @@ class AddAsset extends PureComponent {
} = this.props;
const { dismissNftInfo } = this.state;
const isTokenDetectionSupported =
controllerUtils.isTokenDetectionSupportedForNetwork(chainId);
isTokenDetectionSupportedForNetwork(chainId);
const colors = this.context.colors || mockTheme.colors;
const styles = createStyles(colors);

Expand Down
2 changes: 1 addition & 1 deletion app/components/Views/Approval/index.js
Expand Up @@ -25,7 +25,7 @@ import {
import { WALLET_CONNECT_ORIGIN } from '../../../util/walletconnect';
import Logger from '../../../util/Logger';
import AnalyticsV2 from '../../../util/analyticsV2';
import { GAS_ESTIMATE_TYPES } from '@metamask/controllers';
import { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';
import { KEYSTONE_TX_CANCELED } from '../../../constants/error';
import { ThemeContext, mockTheme } from '../../../util/theme';
import {
Expand Down
5 changes: 2 additions & 3 deletions app/components/Views/ApproveView/Approve/index.js
Expand Up @@ -17,7 +17,8 @@ import AddNickname from '../../../UI/ApproveTransactionReview/AddNickname';
import Modal from 'react-native-modal';
import { strings } from '../../../../../locales/i18n';
import { setTransactionObject } from '../../../../actions/transaction';
import { GAS_ESTIMATE_TYPES, util } from '@metamask/controllers';
import { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';
import { BNToHex, hexToBN } from '@metamask/controller-utils';
import { addHexPrefix, fromWei, renderFromWei } from '../../../../util/number';
import { getNormalizedTxState, getTicker } from '../../../../util/transactions';
import { getGasLimit } from '../../../../util/custom-gas';
Expand All @@ -40,8 +41,6 @@ import {
stopGasPolling,
} from '../../../../core/GasPolling/GasPolling';

const { BNToHex, hexToBN } = util;

const EDIT = 'edit';
const REVIEW = 'review';

Expand Down
2 changes: 1 addition & 1 deletion app/components/Views/AssetDetails/index.tsx
Expand Up @@ -22,7 +22,7 @@ import Engine from '../../../core/Engine';
import Logger from '../../../util/Logger';
import NotificationManager from '../../../core/NotificationManager';
import AppConstants from '../../../core/AppConstants';
import { Token as TokenType } from '@metamask/controllers';
import { Token as TokenType } from '@metamask/assets-controllers';
import {
balanceToFiat,
renderFromTokenMinimalUnit,
Expand Down
2 changes: 1 addition & 1 deletion app/components/Views/DetectedTokens/components/Token.tsx
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
import { Token as TokenType } from '@metamask/controllers';
import { Token as TokenType } from '@metamask/assets-controllers';
import EthereumAddress from '../../../UI/EthereumAddress';
import Icon from 'react-native-vector-icons/Feather';
import CheckBox from '@react-native-community/checkbox';
Expand Down

0 comments on commit 799214e

Please sign in to comment.