@metamask/providers
Version:
A JavaScript Ethereum provider that connects to the wallet over a stream
1 lines • 2.8 kB
Source Map (JSON)
{"version":3,"file":"createRpcWarningMiddleware.mjs","sourceRoot":"","sources":["../../src/middleware/createRpcWarningMiddleware.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,yBAAqB;AAC/C,OAAO,QAAQ,wBAAoB;AAGnC;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CACxC,GAAgB;IAEhB,MAAM,YAAY,GAAG;QACnB,qBAAqB,EAAE,KAAK;QAC5B,oCAAoC,EAAE,KAAK;QAC3C,+BAA+B,EAAE,KAAK;KACvC,CAAC;IAEF,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;QACzB,IAAI,CAAC,YAAY,CAAC,qBAAqB,IAAI,GAAG,CAAC,MAAM,KAAK,aAAa,EAAE,CAAC;YACxE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;YACtD,YAAY,CAAC,qBAAqB,GAAG,IAAI,CAAC;QAC5C,CAAC;aAAM,IACL,CAAC,YAAY,CAAC,oCAAoC;YAClD,GAAG,CAAC,MAAM,KAAK,4BAA4B,EAC3C,CAAC;YACD,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;YACrE,YAAY,CAAC,oCAAoC,GAAG,IAAI,CAAC;QAC3D,CAAC;aAAM,IACL,CAAC,YAAY,CAAC,+BAA+B;YAC7C,GAAG,CAAC,MAAM,KAAK,mBAAmB;YAClC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,QAAQ,CACvB,GAAwC,CAAC,MAAM,EAAE,IAAI,IAAI,EAAE,CAC7D,EACD,CAAC;YACD,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;YAChE,YAAY,CAAC,+BAA+B,GAAG,IAAI,CAAC;QACtD,CAAC;QACD,IAAI,EAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nimport { ERC1155, ERC721 } from '../constants';\nimport messages from '../messages';\nimport type { ConsoleLike } from '../utils';\n\n/**\n * Create JSON-RPC middleware that logs warnings for deprecated RPC methods.\n *\n * @param log - The logging API to use.\n * @returns The JSON-RPC middleware.\n */\nexport function createRpcWarningMiddleware(\n log: ConsoleLike,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n const sentWarnings = {\n ethDecryptDeprecation: false,\n ethGetEncryptionPublicKeyDeprecation: false,\n walletWatchAssetNFTExperimental: false,\n };\n\n return (req, _res, next) => {\n if (!sentWarnings.ethDecryptDeprecation && req.method === 'eth_decrypt') {\n log.warn(messages.warnings.rpc.ethDecryptDeprecation);\n sentWarnings.ethDecryptDeprecation = true;\n } else if (\n !sentWarnings.ethGetEncryptionPublicKeyDeprecation &&\n req.method === 'eth_getEncryptionPublicKey'\n ) {\n log.warn(messages.warnings.rpc.ethGetEncryptionPublicKeyDeprecation);\n sentWarnings.ethGetEncryptionPublicKeyDeprecation = true;\n } else if (\n !sentWarnings.walletWatchAssetNFTExperimental &&\n req.method === 'wallet_watchAsset' &&\n [ERC721, ERC1155].includes(\n (req as JsonRpcRequest<{ type: string }>).params?.type || '',\n )\n ) {\n log.warn(messages.warnings.rpc.walletWatchAssetNFTExperimental);\n sentWarnings.walletWatchAssetNFTExperimental = true;\n }\n next();\n };\n}\n"]}