mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 10:30:04 +01:00
b3963daaab
We're bumping from `^6` to `^8`. All imports are now named, and they have been updated. This is a breaking change, in that support for `eth_signTransaction` is added in `^8.0.0`. We do not support this method in our UI, so our middleware stack has been instrumented to reject. In addition, there are some non-breaking behavioral changes in this version that reviewers should be aware of, see the [7.0.0 release](https://github.com/MetaMask/eth-json-rpc-middleware/releases).
50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
import { createScaffoldMiddleware, mergeMiddleware } from 'json-rpc-engine';
|
|
import {
|
|
createBlockRefMiddleware,
|
|
createRetryOnEmptyMiddleware,
|
|
createBlockCacheMiddleware,
|
|
createInflightCacheMiddleware,
|
|
createBlockTrackerInspectorMiddleware,
|
|
providerFromMiddleware,
|
|
} from 'eth-json-rpc-middleware';
|
|
|
|
import createInfuraMiddleware from 'eth-json-rpc-infura';
|
|
import { PollingBlockTracker } from 'eth-block-tracker';
|
|
|
|
import { NETWORK_TYPE_TO_ID_MAP } from '../../../../shared/constants/network';
|
|
|
|
export default function createInfuraClient({ network, projectId }) {
|
|
const infuraMiddleware = createInfuraMiddleware({
|
|
network,
|
|
projectId,
|
|
maxAttempts: 5,
|
|
source: 'metamask',
|
|
});
|
|
const infuraProvider = providerFromMiddleware(infuraMiddleware);
|
|
const blockTracker = new PollingBlockTracker({ provider: infuraProvider });
|
|
|
|
const networkMiddleware = mergeMiddleware([
|
|
createNetworkAndChainIdMiddleware({ network }),
|
|
createBlockCacheMiddleware({ blockTracker }),
|
|
createInflightCacheMiddleware(),
|
|
createBlockRefMiddleware({ blockTracker, provider: infuraProvider }),
|
|
createRetryOnEmptyMiddleware({ blockTracker, provider: infuraProvider }),
|
|
createBlockTrackerInspectorMiddleware({ blockTracker }),
|
|
infuraMiddleware,
|
|
]);
|
|
return { networkMiddleware, blockTracker };
|
|
}
|
|
|
|
function createNetworkAndChainIdMiddleware({ network }) {
|
|
if (!NETWORK_TYPE_TO_ID_MAP[network]) {
|
|
throw new Error(`createInfuraClient - unknown network "${network}"`);
|
|
}
|
|
|
|
const { chainId, networkId } = NETWORK_TYPE_TO_ID_MAP[network];
|
|
|
|
return createScaffoldMiddleware({
|
|
eth_chainId: chainId,
|
|
net_version: networkId,
|
|
});
|
|
}
|