1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00
metamask-extension/app/scripts/lib/createMetamaskMiddleware.js
Mark Stacey 87ce653c86
Move MetaMask middleware out of network controller (#16863)
The "MetaMask middleware" is the set of middleware for handling methods that
we don't send to the network. This includes signing, encryption, `getAccounts`,
and methods that rely on pending transaction state.

Previously this middleware was setup as part of the network client, despite
having nothing to do with the network. They have been moved into the main RPC
pipeline established in `metamask-controller.js` instead.

This is a pure refactor, and should have no functional changes. The middleware
are still run in exactly the same order with the same arguments.
2023-01-06 13:44:50 -03:30

43 lines
1.2 KiB
JavaScript

import { createScaffoldMiddleware, mergeMiddleware } from 'json-rpc-engine';
import { createWalletMiddleware } from 'eth-json-rpc-middleware';
import {
createPendingNonceMiddleware,
createPendingTxMiddleware,
} from './middleware/pending';
export default function createMetamaskMiddleware({
version,
getAccounts,
processTransaction,
processEthSignMessage,
processTypedMessage,
processTypedMessageV3,
processTypedMessageV4,
processPersonalMessage,
processDecryptMessage,
processEncryptionPublicKey,
getPendingNonce,
getPendingTransactionByHash,
}) {
const metamaskMiddleware = mergeMiddleware([
createScaffoldMiddleware({
eth_syncing: false,
web3_clientVersion: `MetaMask/v${version}`,
}),
createWalletMiddleware({
getAccounts,
processTransaction,
processEthSignMessage,
processTypedMessage,
processTypedMessageV3,
processTypedMessageV4,
processPersonalMessage,
processDecryptMessage,
processEncryptionPublicKey,
}),
createPendingNonceMiddleware({ getPendingNonce }),
createPendingTxMiddleware({ getPendingTransactionByHash }),
]);
return metamaskMiddleware;
}