@web3auth/no-modal
Version:
Multi chain wallet aggregator for web3Auth
38 lines (35 loc) • 1.05 kB
JavaScript
import { createFetchMiddleware } from '@toruslabs/base-controllers';
import { mergeMiddleware } from '@web3auth/auth';
function createEthChainIdMiddleware(chainId) {
return (req, res, next, end) => {
if (req.method === "eth_chainId") {
res.result = chainId;
return end();
}
return next();
};
}
function createEthProviderConfigMiddleware(providerConfig) {
return (req, res, next, end) => {
if (req.method === "eth_provider_config") {
res.result = providerConfig;
return end();
}
return next();
};
}
function createEthJsonRpcClient(providerConfig) {
const {
chainId,
rpcTarget
} = providerConfig;
const fetchMiddleware = createFetchMiddleware({
rpcTarget
});
const networkMiddleware = mergeMiddleware([createEthChainIdMiddleware(chainId), createEthProviderConfigMiddleware(providerConfig), fetchMiddleware]);
return {
networkMiddleware,
fetchMiddleware
};
}
export { createEthChainIdMiddleware, createEthJsonRpcClient, createEthProviderConfigMiddleware };