diff --git a/app/scripts/controllers/mmi-controller.js b/app/scripts/controllers/mmi-controller.js index d6e980e1be95..969b26427a13 100644 --- a/app/scripts/controllers/mmi-controller.js +++ b/app/scripts/controllers/mmi-controller.js @@ -1,7 +1,6 @@ import EventEmitter from 'events'; import log from 'loglevel'; import { captureException } from '@sentry/browser'; -import { isEqual } from 'lodash'; import { CUSTODIAN_TYPES } from '@metamask-institutional/custody-keyring'; import { updateCustodianTransactions, @@ -11,17 +10,10 @@ import { REFRESH_TOKEN_CHANGE_EVENT, INTERACTIVE_REPLACEMENT_TOKEN_CHANGE_EVENT, } from '@metamask-institutional/sdk'; -import { - handleMmiPortfolio, - setDashboardCookie, -} from '@metamask-institutional/portfolio-dashboard'; +import { handleMmiPortfolio } from '@metamask-institutional/portfolio-dashboard'; import { toChecksumHexAddress } from '../../../shared/modules/hexstring-utils'; import { CHAIN_IDS } from '../../../shared/constants/network'; -import { - BUILD_QUOTE_ROUTE, - CONNECT_HARDWARE_ROUTE, -} from '../../../ui/helpers/constants/routes'; -import { previousValueComparator } from '../lib/util'; +import { CONNECT_HARDWARE_ROUTE } from '../../../ui/helpers/constants/routes'; import { getPermissionBackgroundApiMethods } from './permissions'; export default class MMIController extends EventEmitter { @@ -63,17 +55,6 @@ export default class MMIController extends EventEmitter { }); } - this.preferencesController.store.subscribe( - previousValueComparator(async (prevState, currState) => { - const { identities: prevIdentities } = prevState; - const { identities: currIdentities } = currState; - if (isEqual(prevIdentities, currIdentities)) { - return; - } - await this.prepareMmiPortfolio(); - }, this.preferencesController.store.getState()), - ); - this.signatureController.hub.on( 'personal_sign:signed', async ({ signature, messageId }) => { @@ -584,20 +565,6 @@ export default class MMIController extends EventEmitter { }); } - async prepareMmiPortfolio() { - if (!process.env.IN_TEST) { - try { - const mmiDashboardData = await this.handleMmiDashboardData(); - const cookieSetUrls = - this.mmiConfigurationController.store.mmiConfiguration?.portfolio - ?.cookieSetUrls || []; - setDashboardCookie(mmiDashboardData, cookieSetUrls); - } catch (error) { - console.error(error); - } - } - } - async newUnsignedMessage(msgParams, req, version) { // The code path triggered by deferSetAsSigned: true is for custodial accounts const accountDetails = this.custodyController.getAccountDetails( @@ -673,12 +640,6 @@ export default class MMIController extends EventEmitter { return true; } - async handleMmiOpenSwaps(origin, address, chainId) { - await this.setAccountAndNetwork(origin, address, chainId); - this.platform.openExtensionInBrowser(BUILD_QUOTE_ROUTE); - return true; - } - async handleMmiOpenAddHardwareWallet() { await this.appStateController.getUnlockPromise(true); this.platform.openExtensionInBrowser(CONNECT_HARDWARE_ROUTE); diff --git a/app/scripts/lib/rpc-method-middleware/handlers/index.js b/app/scripts/lib/rpc-method-middleware/handlers/index.js index 126da76f9de4..a4c02fa71d66 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/index.js +++ b/app/scripts/lib/rpc-method-middleware/handlers/index.js @@ -11,7 +11,6 @@ import watchAsset from './watch-asset'; import mmiSupported from './institutional/mmi-supported'; import mmiAuthenticate from './institutional/mmi-authenticate'; import mmiPortfolio from './institutional/mmi-portfolio'; -import mmiOpenSwaps from './institutional/mmi-open-swaps'; import mmiCheckIfTokenIsPresent from './institutional/mmi-check-if-token-is-present'; import mmiSetAccountAndNetwork from './institutional/mmi-set-account-and-network'; import mmiOpenAddHardwareWallet from './institutional/mmi-open-add-hardware-wallet'; @@ -30,7 +29,6 @@ const handlers = [ mmiAuthenticate, mmiSupported, mmiPortfolio, - mmiOpenSwaps, mmiCheckIfTokenIsPresent, mmiSetAccountAndNetwork, mmiOpenAddHardwareWallet, diff --git a/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-open-swaps.js b/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-open-swaps.js deleted file mode 100644 index f0cdbd026c24..000000000000 --- a/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-open-swaps.js +++ /dev/null @@ -1,68 +0,0 @@ -import { ethErrors } from 'eth-rpc-errors'; -import { RPC_ALLOWED_ORIGINS } from '@metamask-institutional/rpc-allowlist'; -import { MESSAGE_TYPE } from '../../../../../../shared/constants/app'; - -const mmiOpenSwaps = { - methodNames: [MESSAGE_TYPE.MMI_OPEN_SWAPS], - implementation: mmiOpenSwapsHandler, - hookNames: { - handleMmiOpenSwaps: true, - }, -}; -export default mmiOpenSwaps; - -/** - * @typedef {object} MmiOpenSwapsOptions - * @property {Function} handleMmiOpenSwaps - The metmaskinsititutional_open_swaps method implementation. - */ - -/** - * @typedef {object} MmiOpenSwapsParam - * @property {string} service - The service to which we are authenticating, e.g. 'codefi-compliance' - * @property {object} token - The token used to authenticate - */ - -/** - * @param {import('json-rpc-engine').JsonRpcRequest} req - The JSON-RPC request object. - * @param {import('json-rpc-engine').JsonRpcResponse} res - The JSON-RPC response object. - * @param {Function} _next - The json-rpc-engine 'next' callback. - * @param {Function} end - The json-rpc-engine 'end' callback. - * @param {WatchAssetOptions} options - */ -async function mmiOpenSwapsHandler( - req, - res, - _next, - end, - { handleMmiOpenSwaps }, -) { - try { - let validUrl = false; - // if (!RPC_ALLOWED_ORIGINS[MESSAGE_TYPE.MMI_PORTFOLIO].includes(req.origin)) { - RPC_ALLOWED_ORIGINS[MESSAGE_TYPE.MMI_PORTFOLIO].forEach((regexp) => { - // eslint-disable-next-line require-unicode-regexp - if (regexp.test(req.origin)) { - validUrl = true; - } - }); - // eslint-disable-next-line no-negated-condition - if (!validUrl) { - throw new Error('Unauthorized'); - } - - if (!req.params?.[0] || typeof req.params[0] !== 'object') { - return end( - ethErrors.rpc.invalidParams({ - message: `Expected single, object parameter. Received:\n${JSON.stringify( - req.params, - )}`, - }), - ); - } - const { address, network } = req.params[0]; - res.result = await handleMmiOpenSwaps(req.origin, address, network); - return end(); - } catch (error) { - return end(error); - } -} diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 27ebd056f8f3..684c64249864 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -4347,9 +4347,6 @@ export default class MetamaskController extends EventEmitter { handleMmiDashboardData: this.mmiController.handleMmiDashboardData.bind( this.mmiController, ), - handleMmiOpenSwaps: this.mmiController.handleMmiOpenSwaps.bind( - this.mmiController, - ), handleMmiSetAccountAndNetwork: this.mmiController.setAccountAndNetwork.bind(this.mmiController), handleMmiOpenAddHardwareWallet: