MCPcopy Create free account
hub / github.com/ICBNetwork/web3-Wallet / getRpcMethodMiddleware

Function getRpcMethodMiddleware

app/core/RPCMethods/RPCMethodMiddleware.ts:263–912  ·  view source on GitHub ↗
({
  hostname,
  channelId,
  getProviderState,
  navigation,
  // Website info
  url,
  title,
  icon,
  // Bookmarks
  isHomepage,
  // Show autocomplete
  fromHomepage,
  toggleUrlModal,
  // Wizard
  wizardScrollAdjusted,
  // For the browser
  tabId,
  // For WalletConnect
  isWalletConnect,
  // For MM SDK
  isMMSDK,
  injectHomePageScripts,
  // For analytics
  analytics,
}: RPCMethodsMiddleParameters)

Source from the content-addressed store, hash-verified

261 * Handle RPC methods called by dapps
262 */
263export const getRpcMethodMiddleware = ({
264 hostname,
265 channelId,
266 getProviderState,
267 navigation,
268 // Website info
269 url,
270 title,
271 icon,
272 // Bookmarks
273 isHomepage,
274 // Show autocomplete
275 fromHomepage,
276 toggleUrlModal,
277 // Wizard
278 wizardScrollAdjusted,
279 // For the browser
280 tabId,
281 // For WalletConnect
282 isWalletConnect,
283 // For MM SDK
284 isMMSDK,
285 injectHomePageScripts,
286 // For analytics
287 analytics,
288}: RPCMethodsMiddleParameters) => {
289 // Make sure to always have the correct origin
290 hostname = hostname.replace(AppConstants.MM_SDK.SDK_REMOTE_ORIGIN, '');
291 DevLogger.log(
292 `getRpcMethodMiddleware hostname=${hostname} channelId=${channelId}`,
293 );
294 // all user facing RPC calls not implemented by the provider
295 return createAsyncMiddleware(async (req: any, res: any, next: any) => {
296 // Used by eth_accounts and eth_coinbase RPCs.
297 const getEthAccounts = async () => {
298 const accounts: string[] =
299 (await getPermittedAccounts(channelId ?? hostname)) ?? [];
300 res.result = accounts;
301 };
302
303 const checkTabActive = () => {
304 if (!tabId) return true;
305 const { browser } = store.getState();
306 if (tabId !== browser.activeTab)
307 throw providerErrors.userRejectedRequest();
308 };
309
310 const getSource = () => {
311 if (analytics?.isRemoteConn)
312 return AppConstants.REQUEST_SOURCES.SDK_REMOTE_CONN;
313 if (isWalletConnect) return AppConstants.REQUEST_SOURCES.WC;
314 return AppConstants.REQUEST_SOURCES.IN_APP_BROWSER;
315 };
316
317 const startApprovalFlow = (opts: StartFlowOptions) => {
318 checkTabActive();
319 Engine.context.ApprovalController.clear(
320 providerErrors.userRejectedRequest(),

Callers 8

setupSnapProviderMethod · 0.90
setupSignatureFunction · 0.90
constructorMethod · 0.85
WalletConnectClass · 0.85
getDefaultBridgeParamsFunction · 0.85
setupBridgeFunction · 0.85

Calls 15

polyfillGasPriceFunction · 0.90
getAllNetworksFunction · 0.90
getPermittedAccountsFunction · 0.90
resemblesAddressFunction · 0.90
getVersionFunction · 0.90
stringsFunction · 0.90
removeBookmarkFunction · 0.90
blockTagParamIndexFunction · 0.90
isWhitelistedRPCFunction · 0.90
setEventStageFunction · 0.90
setEventStageErrorFunction · 0.90
nextFunction · 0.85

Tested by 1

setupSignatureFunction · 0.72