1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00
Commit Graph

1337 Commits

Author SHA1 Message Date
Elliot Winkler
89cec5335f
Replace NetworkController w/ core version (#19486)
This commit fulfills a long-standing desire to get the extension using
the same network controller as mobile by removing NetworkController from
this repo and replacing it with NetworkController from the
`@metamask/network-controller` package.

The new version of NetworkController is different the old one in a few
ways:

- The new controller inherits from BaseControllerV2, so the `state`
  property is used to access the state instead of `store.getState()`.
  All references of the latter have been replaced with the former.
- As the new controller no longer has a `store` property, it cannot be
  subscribed to; the controller takes a messenger which can be
  subscribed to instead. There were various places within
  MetamaskController where the old way of subscribing has been replaced
  with the new way. In addition, DetectTokensController has been updated
  to take a messenger object so that it can listen for NetworkController
  state changes.
- The state of the new controller is not updatable from the outside.
  This affected BackupController, which dumps state from
  NetworkController (among other controllers), but also loads the same
  state into NetworkController on import. A method `loadBackup` has been
  added to NetworkController to facilitate this use case, and
  BackupController is now using this method instead of attempting to
  call `update` on NetworkController.
- The new controller does not have a `getCurrentChainId` method;
  instead, the chain ID can be read from the provider config in state.
  This affected MmiController. (MmiController was also updated to read
  custom networks from the new network controller instead of the
  preferences controller).
- The default network that the new controller is set to is always
  Mainnet (previously it could be either localhost or Goerli in test
  mode, depending on environment variables). This has been addressed
  by feeding the NetworkController initial state using the old logic, so
  this should not apply.
2023-06-22 12:46:09 -06:00
Elliot Winkler
bd12ea733a
Fix autolock field to accept decimals in Firefox (#19653)
The autolock field on the Settings screen — the field that allows users
to set the duration that MetaMask will wait for until automatically
locking — does not always accept decimal numbers. This breaks the e2e
test for this feature as it attempts to set this field to "0.1".

More specifically, the React component responsible for this field passes
whatever the user inputs through the `Number` function immediately and
then uses this to repopulate the input. Therefore, if the user enters
"3" followed by a ".", `Number("3.")` will be called. This evaluates to
the number 3, and "3" becomes the new value of the field. As a result,
the "." can never be typed.

Curiously, this behavior only happens in Firefox; Chrome seems to
keep the "." in the input field when it's typed. This happens because
`onChange` event doesn't seem to get fired until a number is typed
*after* the ".". This may be due to underlying differences in the DOM
between Chrome and Firefox.

Regardless, always passing the input through `Number` creates other odd
behavior, such as the fact that the input can never be cleared (because
`Number("")` evaluates to 0).

This commit solves these problems by saving the "raw" version of the
user's input as well as the normalized version. The raw version is
always used to populate the input, whereas the normalized version is
saved in state.
2023-06-22 10:29:24 -06:00
Elliot Winkler
b7f8c82edb
Copy missing lookupNetwork-related tests from core (#19431)
These tests were present in the core version of the NetworkController
tests, but not here. Add them makes it easier to visually compare
differences in the tests between core and this repo.
2023-06-21 13:52:01 -06:00
Elliot Winkler
bdd638400c
Shorten network type references in NC tests (#19430)
Update NetworkController tests to replace `NETWORK_TYPES.<NETWORK NAME>`
with `NetworkType.<network name>`. This makes it easier to visually
compare differences in the tests between core and this repo.
2023-06-21 11:31:08 -06:00
Elliot Winkler
2958c2230b
Reorder NetworkController tests to match core (#19429)
This makes it easier to visually compare differences in the
NetworkController unit tests between core and this repo.
2023-06-21 07:09:37 -07:00
OGPoyraz
39089e0f4c
Accept SignController approval request from frontend (#19184) 2023-06-20 15:37:09 +02:00
Victorien Gauch
e4923399a9
feat: add new linea mainnet network (#19326)
* feat: add new linea mainnet network

* fix: removed unused condition + lint code

* fix: update tests + fix network tab issue

* feat: add feature toggle for linea mainnet

* fix: add feature toggle for linea mainnet

* feat: add linea mainnet logo

* update @metamask/eth-json-rpc-infura package to support linea networks

* update linea mainnet block explorer url

* fix: refactor linea mainnet feature toggle

* fix: update linea mainnet chain id and rpc url

* fix: update settings-search unit test

* fix: update linea mainnet feature flag

* fix: remove useless async function keyword for linea mainnet feature flag
2023-06-16 14:05:33 -02:30
António Regadas
39e033ea00
[MMI] renames method for better understanding (#19622)
* better naming

* better naming

* undo change
2023-06-15 23:33:28 +01:00
Daniel
8b3e3c8a58
Swaps UI update (#19169) 2023-06-15 20:17:21 +02:00
António Regadas
1520f57b77
MMI start script and fixes a bug preventing it to run (#19594)
* adds MMI start script and fixes a bug preventing it to run

* lint fix
2023-06-15 17:57:35 +01:00
Elliot Winkler
436a3dff4e
Sync NetworkController lookupNetwork tests w/ core (#19401)
* Sync NC lookupNetwork tests with core

This makes it easier to visually compare differences in the
NetworkController unit tests between core and this repo.

* Add types for toBeFulfilled matcher

* Fix lint again
2023-06-15 10:12:43 -02:30
Victorien Gauch
1fca9255c1
fix: refactor linea goerli testnet implementation (#19321)
* fix: refactor linea goerli testnet implementation

* fix: rename linea goerli network

* feat: add linea testnet logo

* update linea goerli block explorer url

* update @metamask/eth-json-rpc-infura package to version 8.1.0

* fix: refactor ticker map object in shared/constants/networks.ts files
2023-06-15 09:08:07 -02:30
Elliot Winkler
7701b8b417
Sync NetworkController getEIP1559Compatibility tests w/ core (#19419)
This makes it easier to visually compare differences in the
NetworkController unit tests between core and this repo.
2023-06-14 08:35:43 -07:00
Elliot Winkler
312dadf91f
Sync NetworkController setProviderType tests (#19406)
This makes it easier to visually compare differences in the
NetworkController unit tests between core and this repo.
2023-06-14 09:23:36 -06:00
Elliot Winkler
9c91db5d31
Sync rollbackToPreviousProvider tests w/ core (#19428)
This makes it easier to visually compare differences in the
NetworkController unit tests between core and this repo.
2023-06-14 09:23:16 -06:00
Mark Stacey
b43900f743
Update message manager and signature controller (#19370)
* Update message manager and signature controller

The packages `@metamask/message-manager` and
`@metamask/signature-controller` have been updated to the latest
versions. These versions were part of part of the [core monorepo v53](MetaMask/core#1385)
release. The remaining packages released as part of v53 will be updated
in later PRs.

These releases included a few breaking changes, but none that affect
the extension. Both packages now expect `getCurrentChainId` to return
`Hex`, but that was already the case here. Additionally the signature
controller now has a peer dependency on the approval controller v3,
which is already present and at the correct version.

Relates to #19271

* Ignore error caused by TS bug

* Update types to omit metadata for encryption requests

* Update lavamoat policy
2023-06-14 11:27:41 -02:30
Matthew Walsh
4f4192c6f4
Await approval request in transaction controller (#19197) 2023-06-13 10:17:32 +01:00
Elliot Winkler
f77b1f65e2
Upgrade assets-controllers to v9 (#19472) 2023-06-09 15:48:48 -05:00
Elliot Winkler
c84b85f953
Add getEthQuery action to NetworkController (#19420)
The core version of NetworkControler features a controller action,
`NetworkController:getEthQuery`, which, as its name implies, can be used
to get the EthQuery instance that has been created specially to talk to
the currently selected network. As a result there is a corresponding
unit test for this action.

To make the test suites between this version of NetworkController and
core easier to compare, this commit adds the action along with its test.
2023-06-08 18:00:33 -06:00
Elliot Winkler
25b7016f06
Sync NetworkController setActiveNetwork tests w/ core (#19405)
This makes it easier to visually compare differences in the
NetworkController unit tests between core and this repo.
2023-06-08 18:00:18 -06:00
Elliot Winkler
b8b0de78a3
Sync removeNetworkConfiguration tests w/ core (#19427)
This makes it easier to visually compare differences in the
NetworkController unit tests between core and this repo.
2023-06-08 17:30:15 -06:00
Elliot Winkler
987c08f75a
Sync NetworkController upsertNetworkConfiguration w/ core (#19426)
This makes it easier to visually compare differences in the
NetworkController unit tests between core and this repo.
2023-06-08 17:29:14 -06:00
Erik Marks
9830b14786
Make eth_accounts return all permitted accounts (#18516)
* Make eth_accounts return all permitted accounts rather than just the most recently selected one

* fixup! Make eth_accounts return all permitted accounts rather than just the most recently selected one

* Trigger

---------

Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
Co-authored-by: Jiexi Luan <jiexiluan@gmail.com>
2023-06-08 13:01:43 -07:00
Elliot Winkler
db45a0aef4
setActiveNetwork captures network config ID (#19404)
In the core version of NetworkController, when the `setActiveNetwork`
method updates the provider configuration object, it will capture the ID
of the network configuration used to do so within the provider config
itself. In the same way, `setProviderType` clears any ID that was
previously set from the provider config.

This commit updates this version of NetworkController to be consistent
and updates tests to match.
2023-06-06 14:10:45 -06:00
António Regadas
51f6a29461
Have mmi build being generated (#19441)
* have mmi build being generated

* not needed right now

---------

Co-authored-by: Brad Decker <bhdecker84@gmail.com>
2023-06-06 16:43:31 +01:00
Frederik Bolding
f03f2d3f79
[FLASK] snaps@0.34.0-flask.1 (#19377)
* snaps@0.34.0-flask.1

* Update LavaMoat policies

* Replace instances of targetKey with targetName

* Replace use of PermissionKeys with PermissionNames

* Use Flask packages in tests for now

* Bump execution env

* Add another mock

* Fix lint
2023-06-05 13:51:19 +02:00
Elliot Winkler
a5c370cdfa
Sync NetworkController initializeProvider tests w/ core (#19297)
This makes it easier to visually compare differences in the
NetworkController unit tests between core and this repo.
2023-06-02 20:41:57 -06:00
Elliot Winkler
63c402155d
Sync default value of networkDetails w/ core (#19407)
In the core version of NetworkController, the `networkDetails` property
is initialized to `{ EIPS: {} }`. It is also reset to this
representation when `refreshNetwork` is called.

In this version of NetworkController, however, the default
representation of `networkDetails` is `{ EIPS: { 1559: undefined } }`.
From a consumer's perspective this doesn't make a difference — it's
practically the same. It does make a slight difference in tests,
however.

With that in mind, this commit changes the default representation to `{
EIPS: {} }`. This makes it easier to visually compare differences in the
NetworkController unit tests between core and this repo.
2023-06-02 14:35:08 -06:00
Elliot Winkler
fbcd2a1113
Ensure custom provider configs have chain ID and RPC URL (#19296)
Update NetworkController so that when it is creating the network client
based on configuration for a custom RPC endpoint, it verifies that the
configuration object contains both a chain ID and RPC URL. This check is
already present on the core side; bringing it over makes the tests more
consistent so we can compare them more easily.
2023-05-31 11:52:04 -06:00
Elliot Winkler
1fc4b39dc7
Update INFURA_NETWORKS in NC tests to ostensibly use dec #'s (#19316)
This is a tiny change in order to make the NetworkController tests
between core and this repo more consistent and easier to compare.
2023-05-31 11:51:46 -06:00
Elliot Winkler
206e4537d1
NetworkController tests: Sync withController helper (#19313)
This reduces the diff in the NetworkController tests between this repo
and core in order to make them easier to merge.
2023-05-31 11:50:32 -06:00
Elliot Winkler
84cb4a7b62
NetworkController tests: Remove commented line (#19315)
This line was accidentally left in a previous PR that swapped Nock in
the NetworkController tests for a fake provider. It does not show up in
the core version of these tests.
2023-05-31 11:16:48 -06:00
Elliot Winkler
3e0d717b97
NetworkController: Improve test for destroy (#19314)
This test for the `destroy` method in NetworkController uses `toBe` on
the core side because the use of `toBeTruthy` produces a lint warning
there. It doesn't here, but it's good to be consistent anyway so that
comparing the differences in NetworkController tests between this
extension and core is easier.
2023-05-31 09:30:17 -06:00
Elliot Winkler
cc2e18b16a
Add getProviderConfig action to NetworkController (#19317)
This controller action exists within the core version of
NetworkController. Although there are no plans to make use of this
action within the extension, it has accompanying tests. So ultimately,
the goal of this commit (like others) is to make it easier to compare
differences in the NetworkController tests between this repo and core
by adding a test for the `getProviderConfig` action.
2023-05-31 09:29:59 -06:00
Elliot Winkler
84d22e122c
Sync NetworkController constructor tests with core (#19311)
This makes it easier to compare the NetworkController unit tests between
extension and core.
2023-05-31 09:29:29 -06:00
David Drazic
f788121c3b
[FLASK] Add Snaps privacy warning on snap install (#18835)
* Add Snaps privacy warning on snap install

Add snap install warning status to storage

Add storybook

Add test for snap-privacy-warning

Resolve button type issue

Fix popup display logic

Update fixture

Update popup information and read more handling

Replace deprecated button

Update unit test

* Update buttons and add cancel flow

* Refactoring (review 1)

* Add more unit tests
2023-05-31 14:43:39 +02:00
António Regadas
edf2cc41cb
[MMI] adds mmi code fences to mm controller (#18279)
* adds code fencing

* MMI adds mmi-controller

* MMI prettier

* chore: create keyring builder for CustodyKeyrings

* updates code fence to build-mmi

* adds dependencies

* fix import and prettier

* lint

* clean up

* clean up

* removes old methods and adds new

* comment for now

* adds two missing methods

* runs yarn dedupe

* adds missing import

* bump target values

* lavamoat policy update

* bump values in coverage targets

* prettier import order

* coverage report update

* clean up

* yarn update

* yarn dedupe

* ran lavamoat:auto

* adds zlib entry to storybook/main.js

* adds browserify-zlib

* clean up

* clean up

* prettier

* prettier

* eslint fix

* fix paths

* fix prettier

* fix file name for mocha

* adds to config

* rename

* adds file to configs

* test lavamoat clean up

* run dedupe

* sets value in storybook main.js as false

* runs lavamoat auto

* updates mmi packages to lighter versions

* updates mmi packages

* lavamoat auto

* adds finalized tx status

* lavamoat auto

* yarn dedupe

* clean up

* moving stuff into mmi controller

* clean up

* updates tresholds

* yarn lock review

* updates the mmi controller

---------

Co-authored-by: Shane Terence Odlum <shane.odlum@consensys.net>
2023-05-29 16:38:28 +01:00
Elliot Winkler
c2bbbb1dbc
NetworkController: Simplify event types (#19252)
In the `core` version of this controller, event types are not held in an
enum but are specified directly as strings instead.

Simplifying the event types will make it easier to compare the
NetworkController unit tests between extension and core.
2023-05-26 10:35:52 -06:00
Elliot Winkler
b387a6e795
Reset all Jest mocks in NetworkController tests (#19295)
This makes it possible to test that mock functions are called the
correct amount of times (otherwise Jest will think that a mock function
has been called for as many tests as exist in the NetworkController unit
test suite).
2023-05-26 09:55:19 -06:00
Elliot Winkler
b7ef99847a
Refactor NC initializeProvider tests (#19253)
On the `core` side, the tests for `NetworkController.initializeProvider`
use the `lookupNetworkTests` to automatically test the `lookupNetwork`
behavior that `initializeProvider` initiates. This commit makes use of
the helper to bring the tests closer to the `core` version.
2023-05-25 11:47:36 -06:00
Elliot Winkler
5b85e9b73b
Refactor tests for refreshNetwork behavior (#19238)
The NetworkController tests in the `core` repo use a `refreshNetwork`
test helper to exercise the behavior performed by various methods
when switching the network. This commit brings over this test helper and
refactors tests for those methods to use it.
2023-05-25 11:36:38 -06:00
Albert Olivé
ae3021c697
[MMI] Added code fences to the following controllers: app-state, metametrics, preferences (#17894)
* Added code fences to the following controllers: app-state, metametrics, preferences

* Fixed prettier

* Updated code to be align with new changes in MMI

* Changing code fences

* Remove uneeded files

* Fixed tests

* Fixed code fence

* Changing logic to use async/await

* Removed accountAddress

* Reverted code from develop
2023-05-23 16:16:23 +02:00
legobeat
0e2d641813
test: sanitize url hostname check (#19053) 2023-05-18 00:09:20 +09:00
Mark Stacey
05715dd981
Support hex and number net_version responses (#19156)
Hex and number responses from the `net_version` request are now
accepted. While most chains return decimal strings for this request,
some chains were returning hex responses instead and failing our
validation for this request (which was added in v10.30.0). This
resolves that problem.

Support for number responses was added because it likely worked in
older versions as well, so support is maintained to avoid similar
problems.

Fixes #19151
2023-05-15 18:56:22 -02:30
Mark Stacey
e29faca3a6
Refactor lookupNetwork unit tests (#19070)
The `lookupNetwork` unit tests have been updated to expand test
coverage and match the unit tests for the core network controller. A
helper function `lookupNetworkTests` has been copied from core. It
covers most of the behavior of the function. Vidation tests and
functional tests not covered in core have been retained, but any tests
that are now redundant have been deleted.

Relates to #1197
2023-05-15 13:34:34 -02:30
OGPoyraz
d37d5bf0ee
feat: Refactor Transaction Confirmation selector (#18796) 2023-05-11 07:56:17 +02:00
Mark Stacey
cf7c790505
Only recognize "blocked" status for built-in networks (#19069)
The detection of the Infura "blocked" status has been updated to apply
only to built-in networks. The message we show to users in this state
is meant only for Infura; we don't want to show it for third-party RPC
APIs that happen to use the same error response.

This brings the network controller further in alignment with the core
network controller.

This isn't tested, but it was found in the course of porting unit tests
from core to extension. It will be covered by these tests, which will
be added in the next PR.
2023-05-10 12:11:57 -02:30
Elliot Winkler
05fb01802d
Re-enable tests for subscription-based RPC methods (#18994)
NetworkController doesn't handle `eth_subscribe` or `eth_unsubscribe`
specially, but as it's supported by Infura, we want to make sure we
exercise these RPC methods in the network client tests, even if it is
just to ensure that they get passed through to the network.

We had tests for these RPC methods, but they were commented out in
c095b1accd when the network client code
was extracted to a separate file. At the time we were considering adding
subscription- and filter-based middleware to NetworkController, and so
we commented out the tests for `eth_subscribe` and `eth_unsubscribe`
temporarily until we could rewrite them in a way that would exercise the
new middleware. We reverted that change in
bd23a49013, which meant that we could
restore the existing tests, but it appears that this task was not caught
during review. This commit takes care of restoring them.

Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
2023-05-10 09:34:10 -02:30
Vinicius Stevam
df3db6e559
Adopt ApprovalType from core (#18567) 2023-05-10 06:36:01 +01:00
Mark Stacey
9847179f54
Set network status to "unknown" when ID is invalid (#19068)
We now set the network status to "unknown" rather than "unavailable"
when the network ID is invalid. This better reflects what we know when
this happens, and it makes the network controller better aligned with
the core network controller.

This was accomplished by using a regular error for the network ID
assertion rather than using `assert` directly. `assert` would throw an
error with a `code` property, which resutled in us treating it like an
RPC error.

This isn't tested, but it was found in the course of porting unit tests
from core to extension. It will be covered by these tests, which will
be added in the next PR.

This change should have no functional impact because we treat these two
network statuses as equivalent. The distinction between unknown and
unavailable is useful only for debugging.
2023-05-09 15:44:14 -02:30