1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00
metamask-extension/app/scripts/lib
Elliot Winkler ed3cc404f2
NetworkController: Split network into networkId and networkStatus (#17556)
The `network` store of the network controller crams two types of data
into one place. It roughly tracks whether we have enough information to
make requests to the network and whether the network is capable of
receiving requests, but it also stores the ID of the network (as
obtained via `net_version`).

Generally we shouldn't be using the network ID for anything, as it has
been completely replaced by chain ID, which all custom RPC endpoints
have been required to support for over a year now. However, as the
network ID is used in various places within the extension codebase,
removing it entirely would be a non-trivial effort. So, minimally, this
commit splits `network` into two stores: `networkId` and
`networkStatus`. But it also expands the concept of network status.

Previously, the network was in one of two states: "loading" and
"not-loading". But now it can be in one of four states:

- `available`: The network is able to receive and respond to requests.
- `unavailable`: The network is not able to receive and respond to
  requests for unknown reasons.
- `blocked`: The network is actively blocking requests based on the
  user's geolocation. (This is specific to Infura.)
- `unknown`: We don't know whether the network can receive and respond
  to requests, either because we haven't checked or we tried to check
  and were unsuccessful.

This commit also changes how the network status is determined —
specifically, how many requests are used to determine that status, when
they occur, and whether they are awaited. Previously, the network
controller would make 2 to 3 requests during the course of running
`lookupNetwork`.

* First, if it was an Infura network, it would make a request for
  `eth_blockNumber` to determine whether Infura was blocking requests or
  not, then emit an appropriate event. This operation was not awaited.
* Then, regardless of the network, it would fetch the network ID via
  `net_version`. This operation was awaited.
* Finally, regardless of the network, it would fetch the latest block
  via `eth_getBlockByNumber`, then use the result to determine whether
  the network supported EIP-1559. This operation was awaited.

Now:

* One fewer request is made, specifically `eth_blockNumber`, as we don't
  need to make an extra request to determine whether Infura is blocking
  requests; we can reuse `eth_getBlockByNumber`;
* All requests are awaited, which makes `lookupNetwork` run fully
  in-band instead of partially out-of-band; and
* Both requests for `net_version` and `eth_getBlockByNumber` are
  performed in parallel to make `lookupNetwork` run slightly faster.
2023-03-30 16:49:12 -06:00
..
ens-ipfs Deprecating the Rinkeby, Ropsten, and Kovan test networks (#15989) 2022-09-28 20:26:01 -07:00
middleware Convert Transaction constants to typescript (#17149) 2023-01-18 08:47:29 -06:00
migrator remove exclusions for mismatched object jsdoc type casing (#15351) 2022-07-27 08:28:05 -05:00
rpc-method-middleware feat: add the ConsenSys zkEVM (Linea) as a default network (#17875) 2023-03-21 13:58:38 -02:30
segment Persisting segment events in MetaMetricsController store (#16198) 2022-11-08 04:33:03 +05:30
account-tracker.js Fix/use etherjs specific imports (#15461) 2023-01-24 08:10:36 -06:00
account-tracker.test.js Upgrading the Import Account modal (#17763) 2023-03-06 09:48:28 -08:00
cleanErrorStack.js Add JSDoc ESLint rules (#12112) 2022-01-07 12:27:33 -03:30
cleanErrorStack.test.js Jestify app/scripts/lib/**/*.test.js (#12890) 2021-12-06 10:40:39 -06:00
ComposableObservableStore.js Migrate to new controller packages (#16547) 2022-11-24 16:29:07 -03:30
ComposableObservableStore.test.js Migrate to new controller packages (#16547) 2022-11-24 16:29:07 -03:30
createDupeReqFilterMiddleware.js Adding middleware to filter out duplicate requests from DAPP (#16730) 2022-12-02 21:08:12 +05:30
createDupeReqFilterMiddleware.test.js Privacy - Update metametrics copy during onboarding (#16825) 2022-12-07 12:56:57 -06:00
createLoggerMiddleware.js Add JSDoc ESLint rules (#12112) 2022-01-07 12:27:33 -03:30
createMetamaskMiddleware.js Update eth-json-rpc-middleware from v9 to v10 (#17591) 2023-02-27 13:19:08 -03:30
createMetaRPCHandler.js Persist state in metaRPCHandler so that we are sure state is persisted before sending back response to actions (#15978) 2022-10-10 17:10:44 -05:00
createMetaRPCHandler.test.js Remove nodeify (#13003) 2021-12-08 18:06:53 -03:30
createOnboardingMiddleware.js Deprecate extensionizer for webextension-polyfill (#13960) 2022-03-18 14:07:05 -05:00
createOriginMiddleware.js Add JSDoc ESLint rules (#12112) 2022-01-07 12:27:33 -03:30
createRPCMethodTrackingMiddleware.js Fix Sign-in With Ethereum (SIWE) metametric, add tests, and clean RPC method middleware event logic (#18008) 2023-03-29 15:25:01 -03:00
createRPCMethodTrackingMiddleware.test.js Fix Sign-in With Ethereum (SIWE) metametric, add tests, and clean RPC method middleware event logic (#18008) 2023-03-29 15:25:01 -03:00
createStreamSink.js @metamask/eslint config@5.0.0 (#10358) 2021-02-04 10:15:23 -08:00
createTabIdMiddleware.js Add JSDoc ESLint rules (#12112) 2022-01-07 12:27:33 -03:30
decrypt-message-manager.js Use async/await instead of Promise.resolve (#16221) 2023-01-20 14:20:18 -06:00
encryption-public-key-manager.js Use async/await instead of Promise.resolve (#16221) 2023-01-20 14:20:18 -06:00
extractEthjsErrorMessage.js Add JSDoc ESLint rules (#12112) 2022-01-07 12:27:33 -03:30
get-first-preferred-lang-code.js ensure that we default users with browser language code 'zh' to the supported 'zh_CN' language code (#16329) 2022-10-31 16:48:51 -05:00
getObjStructure.js remove exclusions for mismatched object jsdoc type casing (#15351) 2022-07-27 08:28:05 -05:00
local-store.js Convert app//scripts/lib/util.js to typescript (#17330) 2023-01-23 10:18:22 -06:00
local-store.test.js Persist state in metaRPCHandler so that we are sure state is persisted before sending back response to actions (#15978) 2022-10-10 17:10:44 -05:00
metaRPCClientFactory.js Remove related UI code from the app dir (#15384) 2022-09-16 14:05:21 -05:00
metaRPCClientFactory.test.js Fix rpc and tests (#15570) 2022-08-16 18:21:35 +05:30
network-store.js Persist state in metaRPCHandler so that we are sure state is persisted before sending back response to actions (#15978) 2022-10-10 17:10:44 -05:00
notification-manager.js fix(17855): persist popup when sw is restarted (#17855) 2023-03-02 16:50:00 +00:00
notification-manager.test.ts fix(17855): persist popup when sw is restarted (#17855) 2023-03-02 16:50:00 +00:00
security-provider-helpers.js Change api used for opensea validation (#18383) 2023-03-30 17:33:35 -02:30
seed-phrase-verifier.js Refactor KeyringTypes constant (#17490) 2023-03-21 12:13:22 -02:30
seed-phrase-verifier.test.js Refactor KeyringTypes constant (#17490) 2023-03-21 12:13:22 -02:30
sentry-filter-events.ts Fix Sentry deduplication of events that were never sent (#15677) 2022-08-23 16:14:14 -02:30
setupSentry.js NetworkController: Split network into networkId and networkStatus (#17556) 2023-03-30 16:49:12 -06:00
setupSentry.test.js Sanitize privacy sensitive data before sending to sentry. (#16780) 2022-12-16 11:56:23 -03:30
stream-utils.js Minor scripts/ui.js file cleanup (#16566) 2022-11-18 20:57:01 +07:00
util.test.js Convert Transaction constants to typescript (#17149) 2023-01-18 08:47:29 -06:00
util.ts Convert app//scripts/lib/util.js to typescript (#17330) 2023-01-23 10:18:22 -06:00