diff --git a/app/scripts/controllers/preferences-controller.ts b/app/scripts/controllers/preferences-controller.ts index a7ede69bb26c..536ec33b34eb 100644 --- a/app/scripts/controllers/preferences-controller.ts +++ b/app/scripts/controllers/preferences-controller.ts @@ -6,14 +6,13 @@ import { AccountsControllerSetSelectedAccountAction, AccountsControllerState, } from '@metamask/accounts-controller'; -import { Hex } from '@metamask/utils'; +import { Hex, Json } from '@metamask/utils'; import { BaseController, ControllerGetStateAction, ControllerStateChangeEvent, RestrictedControllerMessenger, } from '@metamask/base-controller'; -import { Json } from 'json-rpc-engine'; import { NetworkControllerGetStateAction } from '@metamask/network-controller'; import { ETHERSCAN_SUPPORTED_CHAIN_IDS, diff --git a/app/scripts/lib/createEvmMethodsToNonEvmAccountReqFilterMiddleware.test.ts b/app/scripts/lib/createEvmMethodsToNonEvmAccountReqFilterMiddleware.test.ts index a5e04f6b7834..063271a9984a 100644 --- a/app/scripts/lib/createEvmMethodsToNonEvmAccountReqFilterMiddleware.test.ts +++ b/app/scripts/lib/createEvmMethodsToNonEvmAccountReqFilterMiddleware.test.ts @@ -1,12 +1,12 @@ -import { jsonrpc2 } from '@metamask/utils'; +import { jsonrpc2, Json } from '@metamask/utils'; import { BtcAccountType, EthAccountType } from '@metamask/keyring-api'; -import { Json } from 'json-rpc-engine'; +import type { JsonRpcParams, JsonRpcRequest } from '@metamask/utils'; import createEvmMethodsToNonEvmAccountReqFilterMiddleware, { EvmMethodsToNonEvmAccountFilterMessenger, } from './createEvmMethodsToNonEvmAccountReqFilterMiddleware'; describe('createEvmMethodsToNonEvmAccountReqFilterMiddleware', () => { - const getMockRequest = (method: string, params?: Json) => ({ + const getMockRequest = (method: string, params: Json) => ({ jsonrpc: jsonrpc2, id: 1, method, @@ -20,71 +20,85 @@ describe('createEvmMethodsToNonEvmAccountReqFilterMiddleware', () => { { accountType: BtcAccountType.P2wpkh, method: 'eth_accounts', + params: undefined, calledNext: false, }, { accountType: BtcAccountType.P2wpkh, method: 'eth_sendRawTransaction', + params: undefined, calledNext: false, }, { accountType: BtcAccountType.P2wpkh, method: 'eth_sendTransaction', + params: undefined, calledNext: false, }, { accountType: BtcAccountType.P2wpkh, method: 'eth_signTypedData', + params: undefined, calledNext: false, }, { accountType: BtcAccountType.P2wpkh, method: 'eth_signTypedData_v1', + params: undefined, calledNext: false, }, { accountType: BtcAccountType.P2wpkh, method: 'eth_signTypedData_v3', + params: undefined, calledNext: false, }, { accountType: BtcAccountType.P2wpkh, method: 'eth_signTypedData_v4', + params: undefined, calledNext: false, }, { accountType: EthAccountType.Eoa, method: 'eth_accounts', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'eth_sendRawTransaction', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'eth_sendTransaction', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'eth_signTypedData', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'eth_signTypedData_v1', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'eth_signTypedData_v3', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'eth_signTypedData_v4', + params: undefined, calledNext: true, }, @@ -92,21 +106,25 @@ describe('createEvmMethodsToNonEvmAccountReqFilterMiddleware', () => { { accountType: BtcAccountType.P2wpkh, method: 'eth_blockNumber', + params: undefined, calledNext: true, }, { accountType: BtcAccountType.P2wpkh, method: 'eth_chainId', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'eth_blockNumber', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'eth_chainId', + params: undefined, calledNext: true, }, @@ -114,91 +132,109 @@ describe('createEvmMethodsToNonEvmAccountReqFilterMiddleware', () => { { accountType: BtcAccountType.P2wpkh, method: 'wallet_getSnaps', + params: undefined, calledNext: true, }, { accountType: BtcAccountType.P2wpkh, method: 'wallet_invokeSnap', + params: undefined, calledNext: true, }, { accountType: BtcAccountType.P2wpkh, method: 'wallet_requestSnaps', + params: undefined, calledNext: true, }, { accountType: BtcAccountType.P2wpkh, method: 'snap_getClientStatus', + params: undefined, calledNext: true, }, { accountType: BtcAccountType.P2wpkh, method: 'wallet_addEthereumChain', + params: undefined, calledNext: true, }, { accountType: BtcAccountType.P2wpkh, method: 'wallet_getPermissions', + params: undefined, calledNext: true, }, { accountType: BtcAccountType.P2wpkh, method: 'wallet_requestPermissions', + params: undefined, calledNext: true, }, { accountType: BtcAccountType.P2wpkh, method: 'wallet_revokePermissions', + params: undefined, calledNext: true, }, { accountType: BtcAccountType.P2wpkh, method: 'wallet_switchEthereumChain', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'wallet_getSnaps', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'wallet_invokeSnap', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'wallet_requestSnaps', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'snap_getClientStatus', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'wallet_addEthereumChain', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'wallet_getPermissions', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'wallet_requestPermissions', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'wallet_revokePermissions', + params: undefined, calledNext: true, }, { accountType: EthAccountType.Eoa, method: 'wallet_switchEthereumChain', + params: undefined, calledNext: true, }, @@ -250,7 +286,7 @@ describe('createEvmMethodsToNonEvmAccountReqFilterMiddleware', () => { }: { accountType: EthAccountType | BtcAccountType; method: string; - params?: Json; + params: Json; calledNext: number; }) => { const filterFn = createEvmMethodsToNonEvmAccountReqFilterMiddleware({ @@ -262,7 +298,7 @@ describe('createEvmMethodsToNonEvmAccountReqFilterMiddleware', () => { const mockEnd = jest.fn(); filterFn( - getMockRequest(method, params), + getMockRequest(method, params) as JsonRpcRequest, getMockResponse(), mockNext, mockEnd, diff --git a/app/scripts/lib/createEvmMethodsToNonEvmAccountReqFilterMiddleware.ts b/app/scripts/lib/createEvmMethodsToNonEvmAccountReqFilterMiddleware.ts index 3e1eca86997e..cc912b5113a7 100644 --- a/app/scripts/lib/createEvmMethodsToNonEvmAccountReqFilterMiddleware.ts +++ b/app/scripts/lib/createEvmMethodsToNonEvmAccountReqFilterMiddleware.ts @@ -1,7 +1,8 @@ import { isEvmAccountType } from '@metamask/keyring-api'; import { RestrictedControllerMessenger } from '@metamask/base-controller'; import { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller'; -import { JsonRpcMiddleware } from 'json-rpc-engine'; +import { JsonRpcMiddleware } from '@metamask/json-rpc-engine'; +import type { Json, JsonRpcParams } from '@metamask/utils'; import { RestrictedEthMethods } from '../../../shared/constants/permissions'; import { unrestrictedEthSigningMethods } from '../controllers/permissions'; @@ -32,7 +33,7 @@ export default function createEvmMethodsToNonEvmAccountReqFilterMiddleware({ messenger, }: { messenger: EvmMethodsToNonEvmAccountFilterMessenger; -}): JsonRpcMiddleware { +}): JsonRpcMiddleware { return function filterEvmRequestToNonEvmAccountsMiddleware( req, _res, @@ -74,7 +75,13 @@ export default function createEvmMethodsToNonEvmAccountReqFilterMiddleware({ // TODO: Convert this to superstruct schema const isWalletRequestPermission = req.method === 'wallet_requestPermissions'; - if (isWalletRequestPermission && req?.params && Array.isArray(req.params)) { + if ( + isWalletRequestPermission && + req?.params && + Array.isArray(req.params) && + req.params.length > 0 && + req.params[0] + ) { const permissionsMethodRequest = Object.keys(req.params[0]); const isEvmPermissionRequest = METHODS_TO_CHECK.some((method) => diff --git a/app/scripts/lib/createMetamaskMiddleware.js b/app/scripts/lib/createMetamaskMiddleware.js index d48ae32dc4a3..9ea07b0d28e5 100644 --- a/app/scripts/lib/createMetamaskMiddleware.js +++ b/app/scripts/lib/createMetamaskMiddleware.js @@ -1,4 +1,7 @@ -import { createScaffoldMiddleware, mergeMiddleware } from 'json-rpc-engine'; +import { + createScaffoldMiddleware, + mergeMiddleware, +} from '@metamask/json-rpc-engine'; import { createWalletMiddleware } from '@metamask/eth-json-rpc-middleware'; import { createPendingNonceMiddleware, diff --git a/app/scripts/lib/createRPCMethodTrackingMiddleware.js b/app/scripts/lib/createRPCMethodTrackingMiddleware.js index a5f12687f89e..a1c5a036f13f 100644 --- a/app/scripts/lib/createRPCMethodTrackingMiddleware.js +++ b/app/scripts/lib/createRPCMethodTrackingMiddleware.js @@ -18,6 +18,7 @@ import { PRIMARY_TYPES_PERMIT, } from '../../../shared/constants/signatures'; import { SIGNING_METHODS } from '../../../shared/constants/transaction'; +import { getErrorMessage } from '../../../shared/modules/error'; import { generateSignatureUniqueId, getBlockaidMetricsProps, @@ -419,15 +420,20 @@ export default function createRPCMethodTrackingMiddleware({ const location = res.error?.data?.location; let event; + + const errorMessage = getErrorMessage(res.error); + if (res.error?.code === errorCodes.provider.userRejectedRequest) { event = eventType.REJECTED; } else if ( res.error?.code === errorCodes.rpc.internal && - res.error?.message === 'Request rejected by user or snap.' + [errorMessage, res.error.message].includes( + 'Request rejected by user or snap.', + ) ) { // The signature was approved in MetaMask but rejected in the snap event = eventType.REJECTED; - eventProperties.status = res.error.message; + eventProperties.status = errorMessage; } else { event = eventType.APPROVED; } diff --git a/app/scripts/lib/middleware/pending.js b/app/scripts/lib/middleware/pending.js index 9e01d11ffcb2..0c9d3445a01e 100644 --- a/app/scripts/lib/middleware/pending.js +++ b/app/scripts/lib/middleware/pending.js @@ -1,4 +1,4 @@ -import { createAsyncMiddleware } from 'json-rpc-engine'; +import { createAsyncMiddleware } from '@metamask/json-rpc-engine'; import { formatTxMetaForRpcResult } from '../util'; export function createPendingNonceMiddleware({ getPendingNonce }) { diff --git a/app/scripts/lib/rpc-method-middleware/createMethodMiddleware.js b/app/scripts/lib/rpc-method-middleware/createMethodMiddleware.js index cee4e7763255..bbc06e7033f5 100644 --- a/app/scripts/lib/rpc-method-middleware/createMethodMiddleware.js +++ b/app/scripts/lib/rpc-method-middleware/createMethodMiddleware.js @@ -42,7 +42,7 @@ function makeMethodMiddlewareMaker(handlers) { * * @param {Record unknown | Promise>} hooks - Required "hooks" into our * controllers. - * @returns {import('json-rpc-engine').JsonRpcMiddleware} The method middleware function. + * @returns {import('@metamask/json-rpc-engine').JsonRpcMiddleware} The method middleware function. */ const makeMethodMiddleware = (hooks) => { assertExpectedHook(hooks, expectedHookNames); diff --git a/app/scripts/lib/rpc-method-middleware/createMethodMiddleware.test.js b/app/scripts/lib/rpc-method-middleware/createMethodMiddleware.test.js index 46aba9abe746..48ea5ae90d58 100644 --- a/app/scripts/lib/rpc-method-middleware/createMethodMiddleware.test.js +++ b/app/scripts/lib/rpc-method-middleware/createMethodMiddleware.test.js @@ -1,4 +1,4 @@ -import { JsonRpcEngine } from 'json-rpc-engine'; +import { JsonRpcEngine } from '@metamask/json-rpc-engine'; import { assertIsJsonRpcFailure, assertIsJsonRpcSuccess, @@ -140,6 +140,7 @@ describe.each([ assertIsJsonRpcFailure(response); expect(response.error.message).toBe('test error'); + expect(response.error.data.cause.message).toBe('test error'); }); it('should handle errors thrown by the implementation', async () => { @@ -156,6 +157,7 @@ describe.each([ assertIsJsonRpcFailure(response); expect(response.error.message).toBe('test error'); + expect(response.error.data.cause.message).toBe('test error'); }); it('should handle non-errors thrown by the implementation', async () => { diff --git a/app/scripts/lib/rpc-method-middleware/createUnsupportedMethodMiddleware.ts b/app/scripts/lib/rpc-method-middleware/createUnsupportedMethodMiddleware.ts index 12abc82d4b21..c96201041d36 100644 --- a/app/scripts/lib/rpc-method-middleware/createUnsupportedMethodMiddleware.ts +++ b/app/scripts/lib/rpc-method-middleware/createUnsupportedMethodMiddleware.ts @@ -1,5 +1,6 @@ +import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine'; +import type { JsonRpcParams } from '@metamask/utils'; import { rpcErrors } from '@metamask/rpc-errors'; -import type { JsonRpcMiddleware } from 'json-rpc-engine'; import { UNSUPPORTED_RPC_METHODS } from '../../../../shared/constants/network'; /** @@ -7,8 +8,8 @@ import { UNSUPPORTED_RPC_METHODS } from '../../../../shared/constants/network'; * appropriate error. */ export function createUnsupportedMethodMiddleware(): JsonRpcMiddleware< - unknown, - void + JsonRpcParams, + null > { return async function unsupportedMethodMiddleware(req, _res, next, end) { if ((UNSUPPORTED_RPC_METHODS as Set).has(req.method)) { diff --git a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts index 003cbd88281b..47c2f0c2e318 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts @@ -1,7 +1,7 @@ import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback, -} from 'json-rpc-engine'; +} from '@metamask/json-rpc-engine'; import type { JsonRpcRequest, JsonRpcParams, diff --git a/app/scripts/lib/rpc-method-middleware/handlers/get-provider-state.test.ts b/app/scripts/lib/rpc-method-middleware/handlers/get-provider-state.test.ts index f3d76a09f5fc..078bd7866a31 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/get-provider-state.test.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/get-provider-state.test.ts @@ -1,5 +1,5 @@ import { PendingJsonRpcResponse } from '@metamask/utils'; -import { JsonRpcEngineEndCallback } from 'json-rpc-engine'; +import { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine'; import getProviderState, { GetProviderState, ProviderStateHandlerResult, diff --git a/app/scripts/lib/rpc-method-middleware/handlers/get-provider-state.ts b/app/scripts/lib/rpc-method-middleware/handlers/get-provider-state.ts index c95b66e1a20d..514f8af6dfa7 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/get-provider-state.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/get-provider-state.ts @@ -1,7 +1,7 @@ import type { JsonRpcEngineNextCallback, JsonRpcEngineEndCallback, -} from 'json-rpc-engine'; +} from '@metamask/json-rpc-engine'; import type { PendingJsonRpcResponse, JsonRpcParams, diff --git a/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-authenticate.js b/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-authenticate.js index 48014a6d66fa..e30332651c8c 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-authenticate.js +++ b/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-authenticate.js @@ -21,8 +21,8 @@ export default mmiAuthenticate; */ /** - * @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 {import('@metamask/utils').JsonRpcRequest} req - The JSON-RPC request object. + * @param {import('@metamask/utils').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 diff --git a/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-check-if-token-is-present.js b/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-check-if-token-is-present.js index 1e05251a25c4..428997bff70c 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-check-if-token-is-present.js +++ b/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-check-if-token-is-present.js @@ -23,8 +23,8 @@ export default mmiAuthenticate; */ /** - * @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 {import('@metamask/utils').JsonRpcRequest} req - The JSON-RPC request object. + * @param {import('@metamask/utils').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 options0 diff --git a/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-open-add-hardware-wallet.js b/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-open-add-hardware-wallet.js index 61af6eb43fe8..7e685e1754a1 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-open-add-hardware-wallet.js +++ b/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-open-add-hardware-wallet.js @@ -16,8 +16,8 @@ export default mmiOpenAddHardwareWallet; */ /** - * @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 {import('@metamask/utils').JsonRpcRequest} req - The JSON-RPC request object. + * @param {import('@metamask/utils').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 diff --git a/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-portfolio.js b/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-portfolio.js index cbe96127682f..7f76d3239afb 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-portfolio.js +++ b/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-portfolio.js @@ -22,8 +22,8 @@ export default mmiPortfolio; */ /** - * @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 {import('@metamask/utils').JsonRpcRequest} req - The JSON-RPC request object. + * @param {import('@metamask/utils').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 diff --git a/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-set-account-and-network.js b/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-set-account-and-network.js index 6c3dc41da9d2..46754e144fab 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-set-account-and-network.js +++ b/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-set-account-and-network.js @@ -23,8 +23,8 @@ export default mmiSetAccountAndNetwork; */ /** - * @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 {import('@metamask/utils').JsonRpcRequest} req - The JSON-RPC request object. + * @param {import('@metamask/utils').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 diff --git a/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-supported.js b/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-supported.js index 5aa987ed880f..e72a1aebf830 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-supported.js +++ b/app/scripts/lib/rpc-method-middleware/handlers/institutional/mmi-supported.js @@ -19,8 +19,8 @@ export default mmiSupported; */ /** - * @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 {import('@metamask/utils').JsonRpcRequest} _req - The JSON-RPC request object. + * @param {import('@metamask/utils').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. */ diff --git a/app/scripts/lib/rpc-method-middleware/handlers/log-web3-shim-usage.test.ts b/app/scripts/lib/rpc-method-middleware/handlers/log-web3-shim-usage.test.ts index d81427af8c26..1b48b75b5e4d 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/log-web3-shim-usage.test.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/log-web3-shim-usage.test.ts @@ -1,4 +1,4 @@ -import type { JsonRpcEngineEndCallback } from 'json-rpc-engine'; +import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine'; import { PendingJsonRpcResponse } from '@metamask/utils'; import { MESSAGE_TYPE } from '../../../../../shared/constants/app'; import { HandlerRequestType as LogWeb3ShimUsageHandlerRequest } from './types'; diff --git a/app/scripts/lib/rpc-method-middleware/handlers/log-web3-shim-usage.ts b/app/scripts/lib/rpc-method-middleware/handlers/log-web3-shim-usage.ts index bff4215ea5aa..c91bd4fa4650 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/log-web3-shim-usage.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/log-web3-shim-usage.ts @@ -1,7 +1,7 @@ import type { JsonRpcEngineNextCallback, JsonRpcEngineEndCallback, -} from 'json-rpc-engine'; +} from '@metamask/json-rpc-engine'; import type { JsonRpcParams, PendingJsonRpcResponse } from '@metamask/utils'; import { MESSAGE_TYPE } from '../../../../../shared/constants/app'; import { diff --git a/app/scripts/lib/rpc-method-middleware/handlers/request-accounts.js b/app/scripts/lib/rpc-method-middleware/handlers/request-accounts.js index 04977fe465d9..68b52ea75549 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/request-accounts.js +++ b/app/scripts/lib/rpc-method-middleware/handlers/request-accounts.js @@ -48,8 +48,8 @@ const locks = new Set(); /** * - * @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 {import('@metamask/utils').JsonRpcRequest} _req - The JSON-RPC request object. + * @param {import('@metamask/utils').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 {RequestEthereumAccountsOptions} options - The RPC method hooks. diff --git a/app/scripts/lib/rpc-method-middleware/handlers/send-metadata.js b/app/scripts/lib/rpc-method-middleware/handlers/send-metadata.js index 35ec117a1f63..5dcfdf274fb6 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/send-metadata.js +++ b/app/scripts/lib/rpc-method-middleware/handlers/send-metadata.js @@ -25,8 +25,8 @@ export default sendMetadata; */ /** - * @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 {import('@metamask/utils').JsonRpcRequest} req - The JSON-RPC request object. + * @param {import('@metamask/utils').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 {SendMetadataOptions} options diff --git a/app/scripts/lib/rpc-method-middleware/handlers/watch-asset.js b/app/scripts/lib/rpc-method-middleware/handlers/watch-asset.js index fdfacb373c77..2f3475f7df71 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/watch-asset.js +++ b/app/scripts/lib/rpc-method-middleware/handlers/watch-asset.js @@ -23,8 +23,8 @@ export default watchAsset; */ /** - * @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 {import('@metamask/utils').JsonRpcRequest} req - The JSON-RPC request object. + * @param {import('@metamask/utils').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 diff --git a/app/scripts/lib/tx-verification/tx-verification-middleware.ts b/app/scripts/lib/tx-verification/tx-verification-middleware.ts index 5349feaf1cf9..7abdf73e3637 100644 --- a/app/scripts/lib/tx-verification/tx-verification-middleware.ts +++ b/app/scripts/lib/tx-verification/tx-verification-middleware.ts @@ -2,14 +2,17 @@ import { hashMessage } from '@ethersproject/hash'; import { verifyMessage } from '@ethersproject/wallet'; import type { NetworkController } from '@metamask/network-controller'; import { rpcErrors } from '@metamask/rpc-errors'; -import type { Json, JsonRpcParams, Hex } from '@metamask/utils'; -import { hasProperty, isObject } from '@metamask/utils'; import type { + Json, + JsonRpcParams, JsonRpcResponse, + Hex, +} from '@metamask/utils'; +import { hasProperty, isObject, JsonRpcRequest } from '@metamask/utils'; +import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback, -} from 'json-rpc-engine'; -import { JsonRpcRequest } from 'json-rpc-engine'; +} from '@metamask/json-rpc-engine'; import { EXPERIENCES_TO_VERIFY, getExperience, diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index f7832f5893ec..75a0da28157e 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -13,9 +13,9 @@ import { RatesController, fetchMultiExchangeRate, } from '@metamask/assets-controllers'; +import { JsonRpcEngine } from '@metamask/json-rpc-engine'; import { ObservableStore } from '@metamask/obs-store'; import { storeAsStream } from '@metamask/obs-store/dist/asStream'; -import { JsonRpcEngine } from 'json-rpc-engine'; import { createEngineStream } from 'json-rpc-middleware-stream'; import { providerAsMiddleware } from '@metamask/eth-json-rpc-middleware'; import { debounce, throttle, memoize, wrap } from 'lodash'; @@ -5492,11 +5492,7 @@ export default class MetamaskController extends EventEmitter { outStream, (err) => { // handle any middleware cleanup - engine._middleware.forEach((mid) => { - if (mid.destroy && typeof mid.destroy === 'function') { - mid.destroy(); - } - }); + engine.destroy(); connectionId && this.removeConnection(origin, connectionId); // For context and todos related to the error message match, see https://github.com/MetaMask/metamask-extension/issues/26337 if (err && !err.message?.match('Premature close')) { diff --git a/lavamoat/browserify/beta/policy.json b/lavamoat/browserify/beta/policy.json index 27b06f2ba5b8..0537447e2860 100644 --- a/lavamoat/browserify/beta/policy.json +++ b/lavamoat/browserify/beta/policy.json @@ -919,11 +919,18 @@ "setTimeout": true }, "packages": { + "@metamask/eth-json-rpc-middleware>@metamask/json-rpc-engine": true, "@metamask/eth-json-rpc-middleware>@metamask/rpc-errors": true, "@metamask/eth-json-rpc-middleware>klona": true, "@metamask/eth-json-rpc-middleware>safe-stable-stringify": true, "@metamask/eth-sig-util": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, + "@metamask/utils": true + } + }, + "@metamask/eth-json-rpc-middleware>@metamask/json-rpc-engine": { + "packages": { + "@metamask/eth-json-rpc-middleware>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true, "@metamask/utils": true } }, @@ -1345,6 +1352,13 @@ "jest-canvas-mock>moo-color>color-name": true } }, + "@metamask/json-rpc-engine": { + "packages": { + "@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true, + "@metamask/utils": true + } + }, "@metamask/keyring-api": { "globals": { "URL": true @@ -1544,10 +1558,10 @@ "@metamask/network-controller>@metamask/eth-json-rpc-infura": true, "@metamask/network-controller>@metamask/eth-json-rpc-middleware": true, "@metamask/network-controller>@metamask/eth-json-rpc-provider": true, + "@metamask/network-controller>@metamask/json-rpc-engine": true, "@metamask/network-controller>@metamask/rpc-errors": true, "@metamask/network-controller>@metamask/swappable-obj-proxy": true, "@metamask/network-controller>reselect": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "@metamask/utils": true, "browserify>assert": true, "browserify>util": true, @@ -1655,8 +1669,8 @@ "@metamask/eth-json-rpc-middleware>safe-stable-stringify": true, "@metamask/eth-sig-util": true, "@metamask/network-controller>@metamask/eth-json-rpc-middleware>@metamask/utils": true, + "@metamask/network-controller>@metamask/json-rpc-engine": true, "@metamask/network-controller>@metamask/rpc-errors": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "bn.js": true, "pify": true } @@ -1678,18 +1692,32 @@ }, "@metamask/network-controller>@metamask/eth-json-rpc-provider": { "packages": { + "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/json-rpc-engine": true, "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": true, "@metamask/safe-event-emitter": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "uuid": true } }, + "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/json-rpc-engine": { + "packages": { + "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true, + "@metamask/utils": true + } + }, "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": { "packages": { "@metamask/rpc-errors>fast-safe-stringify": true, "@metamask/utils": true } }, + "@metamask/network-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/network-controller>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true, + "@metamask/utils": true + } + }, "@metamask/network-controller>@metamask/rpc-errors": { "packages": { "@metamask/rpc-errors>fast-safe-stringify": true, @@ -1904,10 +1932,10 @@ "packages": { "@metamask/controller-utils": true, "@metamask/permission-controller>@metamask/base-controller": true, + "@metamask/permission-controller>@metamask/json-rpc-engine": true, "@metamask/permission-controller>@metamask/rpc-errors": true, "@metamask/permission-controller>@metamask/utils": true, "@metamask/permission-controller>nanoid": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "deep-freeze-strict": true, "immer": true } @@ -1920,6 +1948,28 @@ "immer": true } }, + "@metamask/permission-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/permission-controller>@metamask/json-rpc-engine>@metamask/utils": true, + "@metamask/permission-controller>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true + } + }, + "@metamask/permission-controller>@metamask/json-rpc-engine>@metamask/utils": { + "globals": { + "TextDecoder": true, + "TextEncoder": true + }, + "packages": { + "@metamask/utils>@metamask/superstruct": true, + "@metamask/utils>@scure/base": true, + "@metamask/utils>pony-cause": true, + "@noble/hashes": true, + "browserify>buffer": true, + "nock>debug": true, + "semver": true + } + }, "@metamask/permission-controller>@metamask/rpc-errors": { "packages": { "@metamask/permission-controller>@metamask/rpc-errors>@metamask/utils": true, @@ -2147,10 +2197,10 @@ "@metamask/queued-request-controller": { "packages": { "@metamask/queued-request-controller>@metamask/base-controller": true, + "@metamask/queued-request-controller>@metamask/json-rpc-engine": true, "@metamask/queued-request-controller>@metamask/rpc-errors": true, "@metamask/queued-request-controller>@metamask/utils": true, - "@metamask/selected-network-controller": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true + "@metamask/selected-network-controller": true } }, "@metamask/queued-request-controller>@metamask/base-controller": { @@ -2161,6 +2211,28 @@ "immer": true } }, + "@metamask/queued-request-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/queued-request-controller>@metamask/json-rpc-engine>@metamask/utils": true, + "@metamask/queued-request-controller>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true + } + }, + "@metamask/queued-request-controller>@metamask/json-rpc-engine>@metamask/utils": { + "globals": { + "TextDecoder": true, + "TextEncoder": true + }, + "packages": { + "@metamask/utils>@metamask/superstruct": true, + "@metamask/utils>@scure/base": true, + "@metamask/utils>pony-cause": true, + "@noble/hashes": true, + "browserify>buffer": true, + "nock>debug": true, + "semver": true + } + }, "@metamask/queued-request-controller>@metamask/rpc-errors": { "packages": { "@metamask/queued-request-controller>@metamask/rpc-errors>@metamask/utils": true, @@ -2586,13 +2658,7 @@ "@metamask/snaps-controllers>@metamask/json-rpc-engine": { "packages": { "@metamask/safe-event-emitter": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine>@metamask/rpc-errors": true, - "@metamask/utils": true - } - }, - "@metamask/snaps-controllers>@metamask/json-rpc-engine>@metamask/rpc-errors": { - "packages": { - "@metamask/rpc-errors>fast-safe-stringify": true, + "@metamask/snaps-controllers>@metamask/rpc-errors": true, "@metamask/utils": true } }, @@ -2701,8 +2767,8 @@ }, "packages": { "@metamask/controller-utils": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "@metamask/snaps-rpc-methods>@metamask/permission-controller>@metamask/base-controller": true, + "@metamask/snaps-rpc-methods>@metamask/permission-controller>@metamask/json-rpc-engine": true, "@metamask/snaps-rpc-methods>@metamask/permission-controller>nanoid": true, "@metamask/snaps-rpc-methods>@metamask/rpc-errors": true, "@metamask/utils": true, @@ -2718,6 +2784,13 @@ "immer": true } }, + "@metamask/snaps-rpc-methods>@metamask/permission-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/safe-event-emitter": true, + "@metamask/snaps-rpc-methods>@metamask/rpc-errors": true, + "@metamask/utils": true + } + }, "@metamask/snaps-rpc-methods>@metamask/permission-controller>nanoid": { "globals": { "crypto.getRandomValues": true @@ -2803,8 +2876,8 @@ }, "packages": { "@metamask/controller-utils": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "@metamask/snaps-utils>@metamask/base-controller": true, + "@metamask/snaps-utils>@metamask/permission-controller>@metamask/json-rpc-engine": true, "@metamask/snaps-utils>@metamask/permission-controller>nanoid": true, "@metamask/snaps-utils>@metamask/rpc-errors": true, "@metamask/utils": true, @@ -2812,6 +2885,13 @@ "immer": true } }, + "@metamask/snaps-utils>@metamask/permission-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/safe-event-emitter": true, + "@metamask/snaps-utils>@metamask/rpc-errors": true, + "@metamask/utils": true + } + }, "@metamask/snaps-utils>@metamask/permission-controller>nanoid": { "globals": { "crypto.getRandomValues": true @@ -4674,25 +4754,6 @@ "stream-http": true } }, - "json-rpc-engine": { - "packages": { - "json-rpc-engine>@metamask/safe-event-emitter": true, - "json-rpc-engine>eth-rpc-errors": true - } - }, - "json-rpc-engine>@metamask/safe-event-emitter": { - "globals": { - "setTimeout": true - }, - "packages": { - "webpack>events": true - } - }, - "json-rpc-engine>eth-rpc-errors": { - "packages": { - "@metamask/rpc-errors>fast-safe-stringify": true - } - }, "json-rpc-middleware-stream": { "globals": { "console.warn": true, diff --git a/lavamoat/browserify/flask/policy.json b/lavamoat/browserify/flask/policy.json index 27b06f2ba5b8..0537447e2860 100644 --- a/lavamoat/browserify/flask/policy.json +++ b/lavamoat/browserify/flask/policy.json @@ -919,11 +919,18 @@ "setTimeout": true }, "packages": { + "@metamask/eth-json-rpc-middleware>@metamask/json-rpc-engine": true, "@metamask/eth-json-rpc-middleware>@metamask/rpc-errors": true, "@metamask/eth-json-rpc-middleware>klona": true, "@metamask/eth-json-rpc-middleware>safe-stable-stringify": true, "@metamask/eth-sig-util": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, + "@metamask/utils": true + } + }, + "@metamask/eth-json-rpc-middleware>@metamask/json-rpc-engine": { + "packages": { + "@metamask/eth-json-rpc-middleware>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true, "@metamask/utils": true } }, @@ -1345,6 +1352,13 @@ "jest-canvas-mock>moo-color>color-name": true } }, + "@metamask/json-rpc-engine": { + "packages": { + "@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true, + "@metamask/utils": true + } + }, "@metamask/keyring-api": { "globals": { "URL": true @@ -1544,10 +1558,10 @@ "@metamask/network-controller>@metamask/eth-json-rpc-infura": true, "@metamask/network-controller>@metamask/eth-json-rpc-middleware": true, "@metamask/network-controller>@metamask/eth-json-rpc-provider": true, + "@metamask/network-controller>@metamask/json-rpc-engine": true, "@metamask/network-controller>@metamask/rpc-errors": true, "@metamask/network-controller>@metamask/swappable-obj-proxy": true, "@metamask/network-controller>reselect": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "@metamask/utils": true, "browserify>assert": true, "browserify>util": true, @@ -1655,8 +1669,8 @@ "@metamask/eth-json-rpc-middleware>safe-stable-stringify": true, "@metamask/eth-sig-util": true, "@metamask/network-controller>@metamask/eth-json-rpc-middleware>@metamask/utils": true, + "@metamask/network-controller>@metamask/json-rpc-engine": true, "@metamask/network-controller>@metamask/rpc-errors": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "bn.js": true, "pify": true } @@ -1678,18 +1692,32 @@ }, "@metamask/network-controller>@metamask/eth-json-rpc-provider": { "packages": { + "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/json-rpc-engine": true, "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": true, "@metamask/safe-event-emitter": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "uuid": true } }, + "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/json-rpc-engine": { + "packages": { + "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true, + "@metamask/utils": true + } + }, "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": { "packages": { "@metamask/rpc-errors>fast-safe-stringify": true, "@metamask/utils": true } }, + "@metamask/network-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/network-controller>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true, + "@metamask/utils": true + } + }, "@metamask/network-controller>@metamask/rpc-errors": { "packages": { "@metamask/rpc-errors>fast-safe-stringify": true, @@ -1904,10 +1932,10 @@ "packages": { "@metamask/controller-utils": true, "@metamask/permission-controller>@metamask/base-controller": true, + "@metamask/permission-controller>@metamask/json-rpc-engine": true, "@metamask/permission-controller>@metamask/rpc-errors": true, "@metamask/permission-controller>@metamask/utils": true, "@metamask/permission-controller>nanoid": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "deep-freeze-strict": true, "immer": true } @@ -1920,6 +1948,28 @@ "immer": true } }, + "@metamask/permission-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/permission-controller>@metamask/json-rpc-engine>@metamask/utils": true, + "@metamask/permission-controller>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true + } + }, + "@metamask/permission-controller>@metamask/json-rpc-engine>@metamask/utils": { + "globals": { + "TextDecoder": true, + "TextEncoder": true + }, + "packages": { + "@metamask/utils>@metamask/superstruct": true, + "@metamask/utils>@scure/base": true, + "@metamask/utils>pony-cause": true, + "@noble/hashes": true, + "browserify>buffer": true, + "nock>debug": true, + "semver": true + } + }, "@metamask/permission-controller>@metamask/rpc-errors": { "packages": { "@metamask/permission-controller>@metamask/rpc-errors>@metamask/utils": true, @@ -2147,10 +2197,10 @@ "@metamask/queued-request-controller": { "packages": { "@metamask/queued-request-controller>@metamask/base-controller": true, + "@metamask/queued-request-controller>@metamask/json-rpc-engine": true, "@metamask/queued-request-controller>@metamask/rpc-errors": true, "@metamask/queued-request-controller>@metamask/utils": true, - "@metamask/selected-network-controller": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true + "@metamask/selected-network-controller": true } }, "@metamask/queued-request-controller>@metamask/base-controller": { @@ -2161,6 +2211,28 @@ "immer": true } }, + "@metamask/queued-request-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/queued-request-controller>@metamask/json-rpc-engine>@metamask/utils": true, + "@metamask/queued-request-controller>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true + } + }, + "@metamask/queued-request-controller>@metamask/json-rpc-engine>@metamask/utils": { + "globals": { + "TextDecoder": true, + "TextEncoder": true + }, + "packages": { + "@metamask/utils>@metamask/superstruct": true, + "@metamask/utils>@scure/base": true, + "@metamask/utils>pony-cause": true, + "@noble/hashes": true, + "browserify>buffer": true, + "nock>debug": true, + "semver": true + } + }, "@metamask/queued-request-controller>@metamask/rpc-errors": { "packages": { "@metamask/queued-request-controller>@metamask/rpc-errors>@metamask/utils": true, @@ -2586,13 +2658,7 @@ "@metamask/snaps-controllers>@metamask/json-rpc-engine": { "packages": { "@metamask/safe-event-emitter": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine>@metamask/rpc-errors": true, - "@metamask/utils": true - } - }, - "@metamask/snaps-controllers>@metamask/json-rpc-engine>@metamask/rpc-errors": { - "packages": { - "@metamask/rpc-errors>fast-safe-stringify": true, + "@metamask/snaps-controllers>@metamask/rpc-errors": true, "@metamask/utils": true } }, @@ -2701,8 +2767,8 @@ }, "packages": { "@metamask/controller-utils": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "@metamask/snaps-rpc-methods>@metamask/permission-controller>@metamask/base-controller": true, + "@metamask/snaps-rpc-methods>@metamask/permission-controller>@metamask/json-rpc-engine": true, "@metamask/snaps-rpc-methods>@metamask/permission-controller>nanoid": true, "@metamask/snaps-rpc-methods>@metamask/rpc-errors": true, "@metamask/utils": true, @@ -2718,6 +2784,13 @@ "immer": true } }, + "@metamask/snaps-rpc-methods>@metamask/permission-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/safe-event-emitter": true, + "@metamask/snaps-rpc-methods>@metamask/rpc-errors": true, + "@metamask/utils": true + } + }, "@metamask/snaps-rpc-methods>@metamask/permission-controller>nanoid": { "globals": { "crypto.getRandomValues": true @@ -2803,8 +2876,8 @@ }, "packages": { "@metamask/controller-utils": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "@metamask/snaps-utils>@metamask/base-controller": true, + "@metamask/snaps-utils>@metamask/permission-controller>@metamask/json-rpc-engine": true, "@metamask/snaps-utils>@metamask/permission-controller>nanoid": true, "@metamask/snaps-utils>@metamask/rpc-errors": true, "@metamask/utils": true, @@ -2812,6 +2885,13 @@ "immer": true } }, + "@metamask/snaps-utils>@metamask/permission-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/safe-event-emitter": true, + "@metamask/snaps-utils>@metamask/rpc-errors": true, + "@metamask/utils": true + } + }, "@metamask/snaps-utils>@metamask/permission-controller>nanoid": { "globals": { "crypto.getRandomValues": true @@ -4674,25 +4754,6 @@ "stream-http": true } }, - "json-rpc-engine": { - "packages": { - "json-rpc-engine>@metamask/safe-event-emitter": true, - "json-rpc-engine>eth-rpc-errors": true - } - }, - "json-rpc-engine>@metamask/safe-event-emitter": { - "globals": { - "setTimeout": true - }, - "packages": { - "webpack>events": true - } - }, - "json-rpc-engine>eth-rpc-errors": { - "packages": { - "@metamask/rpc-errors>fast-safe-stringify": true - } - }, "json-rpc-middleware-stream": { "globals": { "console.warn": true, diff --git a/lavamoat/browserify/main/policy.json b/lavamoat/browserify/main/policy.json index 27b06f2ba5b8..0537447e2860 100644 --- a/lavamoat/browserify/main/policy.json +++ b/lavamoat/browserify/main/policy.json @@ -919,11 +919,18 @@ "setTimeout": true }, "packages": { + "@metamask/eth-json-rpc-middleware>@metamask/json-rpc-engine": true, "@metamask/eth-json-rpc-middleware>@metamask/rpc-errors": true, "@metamask/eth-json-rpc-middleware>klona": true, "@metamask/eth-json-rpc-middleware>safe-stable-stringify": true, "@metamask/eth-sig-util": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, + "@metamask/utils": true + } + }, + "@metamask/eth-json-rpc-middleware>@metamask/json-rpc-engine": { + "packages": { + "@metamask/eth-json-rpc-middleware>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true, "@metamask/utils": true } }, @@ -1345,6 +1352,13 @@ "jest-canvas-mock>moo-color>color-name": true } }, + "@metamask/json-rpc-engine": { + "packages": { + "@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true, + "@metamask/utils": true + } + }, "@metamask/keyring-api": { "globals": { "URL": true @@ -1544,10 +1558,10 @@ "@metamask/network-controller>@metamask/eth-json-rpc-infura": true, "@metamask/network-controller>@metamask/eth-json-rpc-middleware": true, "@metamask/network-controller>@metamask/eth-json-rpc-provider": true, + "@metamask/network-controller>@metamask/json-rpc-engine": true, "@metamask/network-controller>@metamask/rpc-errors": true, "@metamask/network-controller>@metamask/swappable-obj-proxy": true, "@metamask/network-controller>reselect": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "@metamask/utils": true, "browserify>assert": true, "browserify>util": true, @@ -1655,8 +1669,8 @@ "@metamask/eth-json-rpc-middleware>safe-stable-stringify": true, "@metamask/eth-sig-util": true, "@metamask/network-controller>@metamask/eth-json-rpc-middleware>@metamask/utils": true, + "@metamask/network-controller>@metamask/json-rpc-engine": true, "@metamask/network-controller>@metamask/rpc-errors": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "bn.js": true, "pify": true } @@ -1678,18 +1692,32 @@ }, "@metamask/network-controller>@metamask/eth-json-rpc-provider": { "packages": { + "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/json-rpc-engine": true, "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": true, "@metamask/safe-event-emitter": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "uuid": true } }, + "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/json-rpc-engine": { + "packages": { + "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true, + "@metamask/utils": true + } + }, "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": { "packages": { "@metamask/rpc-errors>fast-safe-stringify": true, "@metamask/utils": true } }, + "@metamask/network-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/network-controller>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true, + "@metamask/utils": true + } + }, "@metamask/network-controller>@metamask/rpc-errors": { "packages": { "@metamask/rpc-errors>fast-safe-stringify": true, @@ -1904,10 +1932,10 @@ "packages": { "@metamask/controller-utils": true, "@metamask/permission-controller>@metamask/base-controller": true, + "@metamask/permission-controller>@metamask/json-rpc-engine": true, "@metamask/permission-controller>@metamask/rpc-errors": true, "@metamask/permission-controller>@metamask/utils": true, "@metamask/permission-controller>nanoid": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "deep-freeze-strict": true, "immer": true } @@ -1920,6 +1948,28 @@ "immer": true } }, + "@metamask/permission-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/permission-controller>@metamask/json-rpc-engine>@metamask/utils": true, + "@metamask/permission-controller>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true + } + }, + "@metamask/permission-controller>@metamask/json-rpc-engine>@metamask/utils": { + "globals": { + "TextDecoder": true, + "TextEncoder": true + }, + "packages": { + "@metamask/utils>@metamask/superstruct": true, + "@metamask/utils>@scure/base": true, + "@metamask/utils>pony-cause": true, + "@noble/hashes": true, + "browserify>buffer": true, + "nock>debug": true, + "semver": true + } + }, "@metamask/permission-controller>@metamask/rpc-errors": { "packages": { "@metamask/permission-controller>@metamask/rpc-errors>@metamask/utils": true, @@ -2147,10 +2197,10 @@ "@metamask/queued-request-controller": { "packages": { "@metamask/queued-request-controller>@metamask/base-controller": true, + "@metamask/queued-request-controller>@metamask/json-rpc-engine": true, "@metamask/queued-request-controller>@metamask/rpc-errors": true, "@metamask/queued-request-controller>@metamask/utils": true, - "@metamask/selected-network-controller": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true + "@metamask/selected-network-controller": true } }, "@metamask/queued-request-controller>@metamask/base-controller": { @@ -2161,6 +2211,28 @@ "immer": true } }, + "@metamask/queued-request-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/queued-request-controller>@metamask/json-rpc-engine>@metamask/utils": true, + "@metamask/queued-request-controller>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true + } + }, + "@metamask/queued-request-controller>@metamask/json-rpc-engine>@metamask/utils": { + "globals": { + "TextDecoder": true, + "TextEncoder": true + }, + "packages": { + "@metamask/utils>@metamask/superstruct": true, + "@metamask/utils>@scure/base": true, + "@metamask/utils>pony-cause": true, + "@noble/hashes": true, + "browserify>buffer": true, + "nock>debug": true, + "semver": true + } + }, "@metamask/queued-request-controller>@metamask/rpc-errors": { "packages": { "@metamask/queued-request-controller>@metamask/rpc-errors>@metamask/utils": true, @@ -2586,13 +2658,7 @@ "@metamask/snaps-controllers>@metamask/json-rpc-engine": { "packages": { "@metamask/safe-event-emitter": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine>@metamask/rpc-errors": true, - "@metamask/utils": true - } - }, - "@metamask/snaps-controllers>@metamask/json-rpc-engine>@metamask/rpc-errors": { - "packages": { - "@metamask/rpc-errors>fast-safe-stringify": true, + "@metamask/snaps-controllers>@metamask/rpc-errors": true, "@metamask/utils": true } }, @@ -2701,8 +2767,8 @@ }, "packages": { "@metamask/controller-utils": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "@metamask/snaps-rpc-methods>@metamask/permission-controller>@metamask/base-controller": true, + "@metamask/snaps-rpc-methods>@metamask/permission-controller>@metamask/json-rpc-engine": true, "@metamask/snaps-rpc-methods>@metamask/permission-controller>nanoid": true, "@metamask/snaps-rpc-methods>@metamask/rpc-errors": true, "@metamask/utils": true, @@ -2718,6 +2784,13 @@ "immer": true } }, + "@metamask/snaps-rpc-methods>@metamask/permission-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/safe-event-emitter": true, + "@metamask/snaps-rpc-methods>@metamask/rpc-errors": true, + "@metamask/utils": true + } + }, "@metamask/snaps-rpc-methods>@metamask/permission-controller>nanoid": { "globals": { "crypto.getRandomValues": true @@ -2803,8 +2876,8 @@ }, "packages": { "@metamask/controller-utils": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "@metamask/snaps-utils>@metamask/base-controller": true, + "@metamask/snaps-utils>@metamask/permission-controller>@metamask/json-rpc-engine": true, "@metamask/snaps-utils>@metamask/permission-controller>nanoid": true, "@metamask/snaps-utils>@metamask/rpc-errors": true, "@metamask/utils": true, @@ -2812,6 +2885,13 @@ "immer": true } }, + "@metamask/snaps-utils>@metamask/permission-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/safe-event-emitter": true, + "@metamask/snaps-utils>@metamask/rpc-errors": true, + "@metamask/utils": true + } + }, "@metamask/snaps-utils>@metamask/permission-controller>nanoid": { "globals": { "crypto.getRandomValues": true @@ -4674,25 +4754,6 @@ "stream-http": true } }, - "json-rpc-engine": { - "packages": { - "json-rpc-engine>@metamask/safe-event-emitter": true, - "json-rpc-engine>eth-rpc-errors": true - } - }, - "json-rpc-engine>@metamask/safe-event-emitter": { - "globals": { - "setTimeout": true - }, - "packages": { - "webpack>events": true - } - }, - "json-rpc-engine>eth-rpc-errors": { - "packages": { - "@metamask/rpc-errors>fast-safe-stringify": true - } - }, "json-rpc-middleware-stream": { "globals": { "console.warn": true, diff --git a/lavamoat/browserify/mmi/policy.json b/lavamoat/browserify/mmi/policy.json index 7c19b1b4c76e..96e440ce71a6 100644 --- a/lavamoat/browserify/mmi/policy.json +++ b/lavamoat/browserify/mmi/policy.json @@ -1011,11 +1011,18 @@ "setTimeout": true }, "packages": { + "@metamask/eth-json-rpc-middleware>@metamask/json-rpc-engine": true, "@metamask/eth-json-rpc-middleware>@metamask/rpc-errors": true, "@metamask/eth-json-rpc-middleware>klona": true, "@metamask/eth-json-rpc-middleware>safe-stable-stringify": true, "@metamask/eth-sig-util": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, + "@metamask/utils": true + } + }, + "@metamask/eth-json-rpc-middleware>@metamask/json-rpc-engine": { + "packages": { + "@metamask/eth-json-rpc-middleware>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true, "@metamask/utils": true } }, @@ -1437,6 +1444,13 @@ "jest-canvas-mock>moo-color>color-name": true } }, + "@metamask/json-rpc-engine": { + "packages": { + "@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true, + "@metamask/utils": true + } + }, "@metamask/keyring-api": { "globals": { "URL": true @@ -1636,10 +1650,10 @@ "@metamask/network-controller>@metamask/eth-json-rpc-infura": true, "@metamask/network-controller>@metamask/eth-json-rpc-middleware": true, "@metamask/network-controller>@metamask/eth-json-rpc-provider": true, + "@metamask/network-controller>@metamask/json-rpc-engine": true, "@metamask/network-controller>@metamask/rpc-errors": true, "@metamask/network-controller>@metamask/swappable-obj-proxy": true, "@metamask/network-controller>reselect": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "@metamask/utils": true, "browserify>assert": true, "browserify>util": true, @@ -1747,8 +1761,8 @@ "@metamask/eth-json-rpc-middleware>safe-stable-stringify": true, "@metamask/eth-sig-util": true, "@metamask/network-controller>@metamask/eth-json-rpc-middleware>@metamask/utils": true, + "@metamask/network-controller>@metamask/json-rpc-engine": true, "@metamask/network-controller>@metamask/rpc-errors": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "bn.js": true, "pify": true } @@ -1770,18 +1784,32 @@ }, "@metamask/network-controller>@metamask/eth-json-rpc-provider": { "packages": { + "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/json-rpc-engine": true, "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": true, "@metamask/safe-event-emitter": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "uuid": true } }, + "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/json-rpc-engine": { + "packages": { + "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true, + "@metamask/utils": true + } + }, "@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": { "packages": { "@metamask/rpc-errors>fast-safe-stringify": true, "@metamask/utils": true } }, + "@metamask/network-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/network-controller>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true, + "@metamask/utils": true + } + }, "@metamask/network-controller>@metamask/rpc-errors": { "packages": { "@metamask/rpc-errors>fast-safe-stringify": true, @@ -1996,10 +2024,10 @@ "packages": { "@metamask/controller-utils": true, "@metamask/permission-controller>@metamask/base-controller": true, + "@metamask/permission-controller>@metamask/json-rpc-engine": true, "@metamask/permission-controller>@metamask/rpc-errors": true, "@metamask/permission-controller>@metamask/utils": true, "@metamask/permission-controller>nanoid": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "deep-freeze-strict": true, "immer": true } @@ -2012,6 +2040,28 @@ "immer": true } }, + "@metamask/permission-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/permission-controller>@metamask/json-rpc-engine>@metamask/utils": true, + "@metamask/permission-controller>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true + } + }, + "@metamask/permission-controller>@metamask/json-rpc-engine>@metamask/utils": { + "globals": { + "TextDecoder": true, + "TextEncoder": true + }, + "packages": { + "@metamask/utils>@metamask/superstruct": true, + "@metamask/utils>@scure/base": true, + "@metamask/utils>pony-cause": true, + "@noble/hashes": true, + "browserify>buffer": true, + "nock>debug": true, + "semver": true + } + }, "@metamask/permission-controller>@metamask/rpc-errors": { "packages": { "@metamask/permission-controller>@metamask/rpc-errors>@metamask/utils": true, @@ -2239,10 +2289,10 @@ "@metamask/queued-request-controller": { "packages": { "@metamask/queued-request-controller>@metamask/base-controller": true, + "@metamask/queued-request-controller>@metamask/json-rpc-engine": true, "@metamask/queued-request-controller>@metamask/rpc-errors": true, "@metamask/queued-request-controller>@metamask/utils": true, - "@metamask/selected-network-controller": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true + "@metamask/selected-network-controller": true } }, "@metamask/queued-request-controller>@metamask/base-controller": { @@ -2253,6 +2303,28 @@ "immer": true } }, + "@metamask/queued-request-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/queued-request-controller>@metamask/json-rpc-engine>@metamask/utils": true, + "@metamask/queued-request-controller>@metamask/rpc-errors": true, + "@metamask/safe-event-emitter": true + } + }, + "@metamask/queued-request-controller>@metamask/json-rpc-engine>@metamask/utils": { + "globals": { + "TextDecoder": true, + "TextEncoder": true + }, + "packages": { + "@metamask/utils>@metamask/superstruct": true, + "@metamask/utils>@scure/base": true, + "@metamask/utils>pony-cause": true, + "@noble/hashes": true, + "browserify>buffer": true, + "nock>debug": true, + "semver": true + } + }, "@metamask/queued-request-controller>@metamask/rpc-errors": { "packages": { "@metamask/queued-request-controller>@metamask/rpc-errors>@metamask/utils": true, @@ -2678,13 +2750,7 @@ "@metamask/snaps-controllers>@metamask/json-rpc-engine": { "packages": { "@metamask/safe-event-emitter": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine>@metamask/rpc-errors": true, - "@metamask/utils": true - } - }, - "@metamask/snaps-controllers>@metamask/json-rpc-engine>@metamask/rpc-errors": { - "packages": { - "@metamask/rpc-errors>fast-safe-stringify": true, + "@metamask/snaps-controllers>@metamask/rpc-errors": true, "@metamask/utils": true } }, @@ -2793,8 +2859,8 @@ }, "packages": { "@metamask/controller-utils": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "@metamask/snaps-rpc-methods>@metamask/permission-controller>@metamask/base-controller": true, + "@metamask/snaps-rpc-methods>@metamask/permission-controller>@metamask/json-rpc-engine": true, "@metamask/snaps-rpc-methods>@metamask/permission-controller>nanoid": true, "@metamask/snaps-rpc-methods>@metamask/rpc-errors": true, "@metamask/utils": true, @@ -2810,6 +2876,13 @@ "immer": true } }, + "@metamask/snaps-rpc-methods>@metamask/permission-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/safe-event-emitter": true, + "@metamask/snaps-rpc-methods>@metamask/rpc-errors": true, + "@metamask/utils": true + } + }, "@metamask/snaps-rpc-methods>@metamask/permission-controller>nanoid": { "globals": { "crypto.getRandomValues": true @@ -2895,8 +2968,8 @@ }, "packages": { "@metamask/controller-utils": true, - "@metamask/snaps-controllers>@metamask/json-rpc-engine": true, "@metamask/snaps-utils>@metamask/base-controller": true, + "@metamask/snaps-utils>@metamask/permission-controller>@metamask/json-rpc-engine": true, "@metamask/snaps-utils>@metamask/permission-controller>nanoid": true, "@metamask/snaps-utils>@metamask/rpc-errors": true, "@metamask/utils": true, @@ -2904,6 +2977,13 @@ "immer": true } }, + "@metamask/snaps-utils>@metamask/permission-controller>@metamask/json-rpc-engine": { + "packages": { + "@metamask/safe-event-emitter": true, + "@metamask/snaps-utils>@metamask/rpc-errors": true, + "@metamask/utils": true + } + }, "@metamask/snaps-utils>@metamask/permission-controller>nanoid": { "globals": { "crypto.getRandomValues": true @@ -4766,25 +4846,6 @@ "stream-http": true } }, - "json-rpc-engine": { - "packages": { - "json-rpc-engine>@metamask/safe-event-emitter": true, - "json-rpc-engine>eth-rpc-errors": true - } - }, - "json-rpc-engine>@metamask/safe-event-emitter": { - "globals": { - "setTimeout": true - }, - "packages": { - "webpack>events": true - } - }, - "json-rpc-engine>eth-rpc-errors": { - "packages": { - "@metamask/rpc-errors>fast-safe-stringify": true - } - }, "json-rpc-middleware-stream": { "globals": { "console.warn": true, diff --git a/package.json b/package.json index 873e3ad6324c..c524f88032e0 100644 --- a/package.json +++ b/package.json @@ -323,6 +323,7 @@ "@metamask/ethjs-query": "^0.7.1", "@metamask/gas-fee-controller": "^18.0.0", "@metamask/jazzicon": "^2.0.0", + "@metamask/json-rpc-engine": "^10.0.0", "@metamask/keyring-api": "^8.1.3", "@metamask/keyring-controller": "^17.2.2", "@metamask/logging-controller": "^6.0.0", @@ -401,7 +402,6 @@ "immer": "^9.0.6", "is-retry-allowed": "^2.2.0", "jest-junit": "^14.0.1", - "json-rpc-engine": "^6.1.0", "json-rpc-middleware-stream": "^5.0.1", "labeled-stream-splicer": "^2.0.2", "localforage": "^1.9.0", diff --git a/test/stub/provider.js b/test/stub/provider.js index e070d55fa6b0..f86762218adf 100644 --- a/test/stub/provider.js +++ b/test/stub/provider.js @@ -1,4 +1,7 @@ -import { JsonRpcEngine, createScaffoldMiddleware } from 'json-rpc-engine'; +import { + JsonRpcEngine, + createScaffoldMiddleware, +} from '@metamask/json-rpc-engine'; import { providerAsMiddleware } from '@metamask/eth-json-rpc-middleware'; import Ganache from 'ganache'; diff --git a/ui/store/actions.ts b/ui/store/actions.ts index 3433a798a9d9..a81dabb5e5c6 100644 --- a/ui/store/actions.ts +++ b/ui/store/actions.ts @@ -182,7 +182,7 @@ export function tryUnlockMetamask( dispatch(hideLoadingIndication()); }) .catch((err) => { - dispatch(unlockFailed(err.message)); + dispatch(unlockFailed(getErrorMessage(err))); dispatch(hideLoadingIndication()); return Promise.reject(err); }); @@ -4213,7 +4213,7 @@ export function setConnectedStatusPopoverHasBeenShown(): ThunkAction< return () => { callBackgroundMethod('setConnectedStatusPopoverHasBeenShown', [], (err) => { if (isErrorWithMessage(err)) { - throw new Error(err.message); + throw new Error(getErrorMessage(err)); } }); }; @@ -4223,7 +4223,7 @@ export function setRecoveryPhraseReminderHasBeenShown() { return () => { callBackgroundMethod('setRecoveryPhraseReminderHasBeenShown', [], (err) => { if (isErrorWithMessage(err)) { - throw new Error(err.message); + throw new Error(getErrorMessage(err)); } }); }; @@ -4238,7 +4238,7 @@ export function setRecoveryPhraseReminderLastShown( [lastShown], (err) => { if (isErrorWithMessage(err)) { - throw new Error(err.message); + throw new Error(getErrorMessage(err)); } }, ); @@ -4723,12 +4723,15 @@ export function fetchSmartTransactionFees( return smartTransactionFees; } catch (err) { logErrorWithMessage(err); - if (isErrorWithMessage(err) && err.message.startsWith('Fetch error:')) { - const errorObj = parseSmartTransactionsError(err.message); - dispatch({ - type: actionConstants.SET_SMART_TRANSACTIONS_ERROR, - payload: errorObj, - }); + if (isErrorWithMessage(err)) { + const errorMessage = getErrorMessage(err); + if (errorMessage.startsWith('Fetch error:')) { + const errorObj = parseSmartTransactionsError(errorMessage); + dispatch({ + type: actionConstants.SET_SMART_TRANSACTIONS_ERROR, + payload: errorObj, + }); + } } throw err; } @@ -4800,12 +4803,15 @@ export function signAndSendSmartTransaction({ return response.uuid; } catch (err) { logErrorWithMessage(err); - if (isErrorWithMessage(err) && err.message.startsWith('Fetch error:')) { - const errorObj = parseSmartTransactionsError(err.message); - dispatch({ - type: actionConstants.SET_SMART_TRANSACTIONS_ERROR, - payload: errorObj, - }); + if (isErrorWithMessage(err)) { + const errorMessage = getErrorMessage(err); + if (errorMessage.startsWith('Fetch error:')) { + const errorObj = parseSmartTransactionsError(errorMessage); + dispatch({ + type: actionConstants.SET_SMART_TRANSACTIONS_ERROR, + payload: errorObj, + }); + } } throw err; } @@ -4826,12 +4832,15 @@ export function updateSmartTransaction( ]); } catch (err) { logErrorWithMessage(err); - if (isErrorWithMessage(err) && err.message.startsWith('Fetch error:')) { - const errorObj = parseSmartTransactionsError(err.message); - dispatch({ - type: actionConstants.SET_SMART_TRANSACTIONS_ERROR, - payload: errorObj, - }); + if (isErrorWithMessage(err)) { + const errorMessage = getErrorMessage(err); + if (errorMessage.startsWith('Fetch error:')) { + const errorObj = parseSmartTransactionsError(errorMessage); + dispatch({ + type: actionConstants.SET_SMART_TRANSACTIONS_ERROR, + payload: errorObj, + }); + } } throw err; } @@ -4860,12 +4869,15 @@ export function cancelSmartTransaction( await submitRequestToBackground('cancelSmartTransaction', [uuid]); } catch (err) { logErrorWithMessage(err); - if (isErrorWithMessage(err) && err.message.startsWith('Fetch error:')) { - const errorObj = parseSmartTransactionsError(err.message); - dispatch({ - type: actionConstants.SET_SMART_TRANSACTIONS_ERROR, - payload: errorObj, - }); + if (isErrorWithMessage(err)) { + const errorMessage = getErrorMessage(err); + if (errorMessage.startsWith('Fetch error:')) { + const errorObj = parseSmartTransactionsError(errorMessage); + dispatch({ + type: actionConstants.SET_SMART_TRANSACTIONS_ERROR, + payload: errorObj, + }); + } } throw err; } diff --git a/yarn.lock b/yarn.lock index 9f6ea0aa2fc2..07f9e44961be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18490,15 +18490,6 @@ __metadata: languageName: node linkType: hard -"eth-rpc-errors@npm:^4.0.2": - version: 4.0.3 - resolution: "eth-rpc-errors@npm:4.0.3" - dependencies: - fast-safe-stringify: "npm:^2.0.6" - checksum: 10/47ce14170eabaee51ab1cc7e643bb3ef96ee6b15c6404806aedcd51750e00ae0b1a12c37785b180679b8d452b6dd44a0240bb018d01fa73efc85fcfa808b35a7 - languageName: node - linkType: hard - "ethereum-cryptography@npm:^0.1.3": version: 0.1.3 resolution: "ethereum-cryptography@npm:0.1.3" @@ -24190,16 +24181,6 @@ __metadata: languageName: node linkType: hard -"json-rpc-engine@npm:^6.1.0": - version: 6.1.0 - resolution: "json-rpc-engine@npm:6.1.0" - dependencies: - "@metamask/safe-event-emitter": "npm:^2.0.0" - eth-rpc-errors: "npm:^4.0.2" - checksum: 10/00d5b5228e90f126dd52176598db6e5611d295d3a3f7be21254c30c1b6555811260ef2ec2df035cd8e583e4b12096259da721e29f4ea2affb615f7dfc960a6a6 - languageName: node - linkType: hard - "json-rpc-middleware-stream@npm:^5.0.1": version: 5.0.1 resolution: "json-rpc-middleware-stream@npm:5.0.1" @@ -26141,6 +26122,7 @@ __metadata: "@metamask/forwarder": "npm:^1.1.0" "@metamask/gas-fee-controller": "npm:^18.0.0" "@metamask/jazzicon": "npm:^2.0.0" + "@metamask/json-rpc-engine": "npm:^10.0.0" "@metamask/keyring-api": "npm:^8.1.3" "@metamask/keyring-controller": "npm:^17.2.2" "@metamask/logging-controller": "npm:^6.0.0" @@ -26358,7 +26340,6 @@ __metadata: jest-environment-jsdom: "patch:jest-environment-jsdom@npm%3A29.7.0#~/.yarn/patches/jest-environment-jsdom-npm-29.7.0-0b72dd0e0b.patch" jest-junit: "npm:^14.0.1" jsdom: "npm:^16.7.0" - json-rpc-engine: "npm:^6.1.0" json-rpc-middleware-stream: "npm:^5.0.1" json-schema-to-ts: "npm:^3.0.1" koa: "npm:^2.7.0"