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

1291 Commits

Author SHA1 Message Date
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
Brad Decker
b60b9f441f
Bundle size reduction: Upgrading ethereumjs/tx and ethereumjs/common (#18302)
* upgrade ethereumjs/tx and deps

* Yarn dedupe

---------

Co-authored-by: Dan J Miller <danjm.com@gmail.com>
2023-05-05 10:55:41 -05:00
Albert Olivé
33f9d6f480
[MMI] Applied code fencing in transactions and pending tx tracker controllers (#17909)
* Applied code fencing in trabsactions and pending tx tracker controllers

* remove unneeded URL from the comment

* Added test

* Added useful comment

* Fixing code fences

---------

Co-authored-by: António Regadas <apregadas@gmail.com>
2023-05-05 15:58:40 +02:00
Matthew Walsh
f62d8fce61
Use core signature controller (#18654) 2023-05-05 13:05:52 +01:00
OGPoyraz
cbcb46f704
fix: prevent cancel and speedup transactions to call accept approval (#18846) 2023-05-03 13:07:03 +02:00
Mark Stacey
d1cea85f33
Rename provider to providerConfig (#18907)
* Rename `provider` to `providerConfig`

The network controller `provider` state has been renamed to
 `providerConfig`. This better reflects what this state is, and makes
this controller more closely aligned with the core network controller.

All references to the provider configuration have been updated to
prefer `providerConfig` over `provider`, to make the distinction clear
between a provider and provider config.

Closes #18902

* Add migration
2023-05-02 13:23:20 -02:30
Frederik Bolding
4d015de43e
Fence snaps endowments and permissions for stable/flask (#18847)
* Fence snaps endowments and permissions for stable/flask

* Fix lint

* Fix tests

* Actually fix tests

* Fix another test
2023-05-02 14:51:16 +02:00
Mark Stacey
483ffdb5c0
Simplify network controller unit test setup (#18901)
* Simplify network controller unit test setup

The network controller unit tests have been refactored to simplify the
setup steps related to the controller messenger. The messenger is now
constructed by the `withController` helper function, rather than being
manually setup in each test that references it.

Relates to https://github.com/MetaMask/core/issues/1197

* Bring tests closer in alignment to core

The function to build default controller constructor parameters has
been removed, bringing these tests closer in alignment to the core
tests.
2023-05-02 09:02:57 -02:30
Bernardo Garces Chapero
1253c768c7
Return state when calling EncryptionPublicKeyController.cancelEncryptionPublicKey (#18845)
* returns state

* adds unit test
2023-04-27 11:39:37 +01:00
OGPoyraz
6d0f3a0b26
Consume Decrypt Message Manager from @metamask/message-manager (#18379) 2023-04-26 17:02:33 +02:00
Olaf Tomalka
95c37e1ba3
feat: add yaml feature management (#18125)
* feat: add yaml feature management

Add yaml feature file per build type.
Also add method to parse yaml and set
enabled features env to true. The build
process will then replace any process.env[feature]
that exists on the config by its value

* chore: add example for desktop

* Added initial draft of build features

* [TMP] Sync between computers

* Is able to succesfully build stable extension with snaps feature

* Removing var context from builds.yml

* Add asssets to builds.yml

* Minor bug fixes and removing debug logs

* [WIP] Test changes

* Removed TODOs

* Fix regession bug

Also
* remove debug logs
* merge Variables.set and Variables.setMany with an overload

* Fix build, lint and a bunch of issues

* Update LavaMoat policies

* Re-add desktop build type

* Fix some tests

* Fix desktop build

* Define some env variables used by MV3

* Fix lint

* Fix remove-fenced-code tests

* Fix README typo

* Move new code

* Fix missing asset copy

* Move Jest env setup

* Fix path for test after rebase

* Fix code fences

* Fix fencing and LavaMoat policies

* Fix MMI code-fencing after rebase

* Fix MMI code fencing after merge

* Fix more MMI code fencing

---------

Co-authored-by: cryptotavares <joao.tavares@consensys.net>
Co-authored-by: Frederik Bolding <frederik.bolding@gmail.com>
Co-authored-by: Brad Decker <bhdecker84@gmail.com>
2023-04-25 16:32:51 +02:00
Nidhi Kumari
0efd00b755
UX Multichain: Added product tour component (#18571)
* adding product tour component

* updated control for prevIcon

* updated app-header and product tour

* updated css

* updated message strings

* updated tests

* removed console statement

* added selector for product tour

* updated test

* updated test

* updated state with steps

* Update ui/components/multichain/product-tour-popover/product-tour-popover.js

Co-authored-by: Garrett Bear <gwhisten@gmail.com>

* Update ui/components/multichain/product-tour-popover/product-tour-popover.js

Co-authored-by: Garrett Bear <gwhisten@gmail.com>

* Update ui/components/multichain/product-tour-popover/product-tour-popover.js

Co-authored-by: Garrett Bear <gwhisten@gmail.com>

* Update ui/components/multichain/product-tour-popover/product-tour-popover.js

Co-authored-by: Garrett Bear <gwhisten@gmail.com>

* Update ui/components/multichain/product-tour-popover/product-tour-popover.js

Co-authored-by: Garrett Bear <gwhisten@gmail.com>

* Update ui/components/multichain/product-tour-popover/product-tour-popover.js

Co-authored-by: Garrett Bear <gwhisten@gmail.com>

* Update ui/components/multichain/product-tour-popover/product-tour-popover.js

Co-authored-by: Garrett Bear <gwhisten@gmail.com>

* Update ui/components/multichain/product-tour-popover/product-tour-popover.js

Co-authored-by: Garrett Bear <gwhisten@gmail.com>

* Update ui/components/multichain/product-tour-popover/product-tour-popover.js

Co-authored-by: Garrett Bear <gwhisten@gmail.com>

* Update ui/components/multichain/product-tour-popover/product-tour-popover.scss

Co-authored-by: Garrett Bear <gwhisten@gmail.com>

* fixed lint errors

* updated lint error

* added changes for rtl support

* added changes for rtl support

* fixed lint errors

* Some suggestions (#18676)

* updated messages and indentation

* fixed popup close on my final step

* updated rtl classname condition

---------

Co-authored-by: Garrett Bear <gwhisten@gmail.com>
Co-authored-by: George Marshall <george.marshall@consensys.net>
2023-04-21 20:58:18 +05:30
Jyoti Puri
7f00c2f313
Fixing issue with gasLimit in transaction being 0 (#18682) 2023-04-21 11:17:38 +05:30
Elliot Winkler
73b9c1095a
Update NC setProviderType to clear rpcUrl/nickname (#18675)
In the core version of NetworkController, `setProviderType` sets
`rpcTarget` (its name for `rpcUrl`) and `nickname` to `undefined`.
While it would be better to completely remove these properties, it would
be better to follow suit so that we can make the tests between the two
versions of the controllers more alike.
2023-04-20 15:50:59 -02:30
Elliot Winkler
24eae1d3c6
Use fake provider for NetworkController unit tests (#18628)
* Use fake provider for NetworkController unit tests

In the unit tests for NetworkController, it's important to prevent
network requests from occurring. Currently we do that by using Nock.
However, the `core` version of NetworkController uses a fake provider
object. This is arguably a better approach for unit tests because it
prevents us from having to think about the behavior that a specific
middleware may have. For instance, the Infura middleware intercepts
`eth_chainId` to return a static result, and the block cache middleware
replaces the `latest` block tag with the latest block number, making an
extra call to `eth_blockNumber` in doing so. We have to account for
these kinds of behaviors when using Nock, but we do not need to do this
when using a fake provider.

This should make it easier to compare the difference between the unit
tests in this repo vs. in the `core` repo, which should ultimately help
us merge the two controllers together.

* Rename fake-provider-engine to fake-provider

* Rearrange imports

* Move fake-provider and fake-block-tracker into a directory and exclude it from coverage

* Make FakeBlockTracker inert, and fix JSDocs

* Remove generics from FakeProvider

* Call beforeCompleting (and beforeResolving) using async/await

* Fix signature of sendAsync; align other signatures within FakeProvider

* No need to check whether error is not a string

* Don't exclude the provider-api-tests directory from coverage

* Make sure to mock both net_version and eth_getBlockByNumber when testing network status

* Fix FakeProvider so that none of the methods have optional callbacks
2023-04-20 15:21:41 -02:30
Mark Stacey
8e52ed3fac
Make upsertNetworkConfiguration async (#18606)
The network controller method `upsertNetworkConfiguration` has been
made async. It makes one async call internally, which is the optional
step of setting the given network as the active network.

If the `setActive` option is set to `true`, this function will not
resolve until after the network switch has completed. If the
`setActive` option is `false`, this change will not have any functional
impact.

Relates to https://github.com/MetaMask/metamask-extension/issues/18587
2023-04-19 20:24:50 -02:30
Dan J Miller
7ca9383785
Fix swaps controller: update provider after networkIdStore state update (#18670)
* Fix swaps controller: update provider after networkIdStore state update

* Listen for changes on networkController.store, instead of networkController.networkIdStore, in the swaps controller

* Fix unit tests
2023-04-19 18:15:26 -02:30
Elliot Winkler
a876eaba23
removeNetworkConfiguration validates given ID (#18650)
In the `core` version of NetworkController, `removeNetworkConfiguration`
throws an error if the given network configuration ID doesn't match an
existing network configuration. This commits adds the same check for
consistency. It also makes some minor changes to the implementation and
tests for `removeNetworkConfiguration` for consistency as well.
2023-04-19 09:47:33 -06:00
Mark Stacey
1fe28ee15a
Make setActiveNetwork async (#18605)
The network controller method `setActiveNetwork` is now async, and the
asynchronous `_setProviderConfig` step is now awaited. The function
will not resolve until the network has finished switching.

This change affects the `eth_switchEthereumChain` and
`eth_addEthereumChain` middleware, and it affects any network switching
performed in our UI.

Relates to https://github.com/MetaMask/metamask-extension/issues/18587
2023-04-18 13:25:05 -02:30
Dan J Miller
e6f73f5fe9
Pass correct params to fetchEstimatedL1Fee in the swaps controller (#18634) 2023-04-18 12:15:18 -02:30
Vinicius Stevam
ae0af1b283
Adopt security provider request from core (#18520) 2023-04-18 08:33:32 +01:00
Jyoti Puri
00d2d43d45
Fix error in console on rejecting signature request (#18614) 2023-04-18 05:58:28 +05:30
Mark Stacey
e5835ac459
Make resetConnection async (#18601)
The network controller method `resetConnection` is now async. This has
no functional impact.

Relates to https://github.com/MetaMask/metamask-extension/issues/18587
2023-04-17 15:45:22 -02:30
Mark Stacey
b87c1b8526
Make setProviderType async (#18604)
The network controller method `setProviderType` is now async, and the
async operation `_setProviderConfig` called at the end of the method is
now awaited.

Because the only async operation was the last step, this should have no
impact upon the flow of execution. The only functional change is that
now any callers have the option of waiting until the network switch
operation has completed.

One such change was made, in the `switch-ethereum-chain` middleware. As
a result, an error thrown while the network is switching will now
be thrown in this middleware and returned to the dapp as an internal
error.

Relates to https://github.com/MetaMask/metamask-extension/issues/18587
2023-04-17 15:45:01 -02:30
Mark Stacey
39dff02a04
Consolidate network stores (#18595)
* Consolidate network stores

The network controller used to have multiple different state stores,
which were composed together to form the main controller state store.
They have been consolidated into a single store. This required few
changes because most state access was already being done through the
composed store.

Fixes https://github.com/MetaMask/metamask-extension/issues/18303

* Add JSDoc comment
2023-04-17 13:24:13 -02:30
Mark Stacey
3588e6d28e
Make network controller internal fields private (#18607)
Internal network controller methods and fields are now private fields,
using the JavaScript `#` syntax rather than the `private` TypeScript
keyword or a leading underscore.

The one reference to a private field was in the preferences controller
unit tests. Fortunately it was being used to create a test fixture that
was unused. The unnecessary test fixtures have been removed from that
test suite.

Fixes https://github.com/MetaMask/metamask-extension/issues/18588
2023-04-17 12:45:33 -02:30
Frederik Bolding
47f4f4008b
[FLASK] Remove unused snaps code (#18565)
* Remove unused code after snap_confirm was removed

* Remove more unused code

* Fix lint
2023-04-17 12:55:08 +02:00
Mark Stacey
73efd2edeb
Make rollbackToPreviousProvider async (#18599)
The network controller method `rollbackToPreviousProvider` is now
async. It will resolve when the network switch has completed.

Relates to https://github.com/MetaMask/metamask-extension/issues/18587
2023-04-15 10:31:59 -02:30
Mark Stacey
e6d1b052f0
Make _setProviderConfig async (#18600)
The network controller internal method `_setProviderConfig` has been
made async, the async `_switchNetwork` operation is now `await`-ed.

Since the `_switchNetwork` call was the last operation, this has zero
functional impact.

Relates to https://github.com/MetaMask/metamask-extension/issues/18587
2023-04-14 19:10:32 -02:30
Mark Stacey
b9ff4e8798
Remove the network controller previousProviderStore (#18593)
* Remove the network controller `previousProviderStore`

The `previousProvider` network controller state has been replaced with
a private internal property. This was only used internally, it did not
need to be part of state.

This relates to https://github.com/MetaMask/metamask-extension/issues/18303

* Remove redundant tests
2023-04-14 16:24:57 -02:30
Matthew Walsh
fa32c5deb9
Disable rate limiting for signature approval requests (#18594) 2023-04-14 18:33:53 +01:00
Mark Stacey
d85d2318a3
Make _switchNetwork async (#18597)
The network controller internal method `_switchNetwork` has been made
async, and the `lookupNetwork` call is now awaited. Because this method
is only used internally, and because the `await`-ed async operation was
the last operation in this function, this change has no functional
impact whatsoever.

Relates to https://github.com/MetaMask/metamask-extension/issues/18587
2023-04-14 14:53:57 -02:30
vthomas13
40e4a3653f
Updating Terms of Use, Adding popover and onboarding flow check (#18221)
* WIP commit

* Moving copy out of messages.json, styling changes

* handling scroll button click and disable logic

* moving scrollButton up to popover component, adding logic for accepting terms of use in popover and onboarding flows

* adding terms of use to e2e wallet creation/import

* adjusting failing unit test

* fixing QR code e2e

* updating welcome test

* setting app state in fixtures

* Update app/scripts/controllers/app-state.js

removing console log

Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>

* Update ui/components/app/terms-of-use-popup/terms-of-use-popup.stories.js

adding args to ToU popup storybook

Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>

* Update ui/components/app/terms-of-use-popup/terms-of-use-popup.js

Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>

* updating DS components in terms of use

* popover styling changes

* adding metametrics tracking

* editing scrollbutton behavior

* adding unit test

* code fencing

---------

Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>
2023-04-14 12:51:13 -04:00
Elliot Winkler
26db0aee46
Convert NetworkController net client tests to TS (#18490)
In order to be able to better compare differences between the version of
NetworkController in this repo and the version in the `core` repo before
we replace this version with the `core` version, this commit converts
the NetworkController network client tests to TypeScript.

The added types here are copied from the `core` repo. We plan on
making more improvements on the `core` side at some point to polish the
tests and types and reduce some of the duplication, but for now we're
just trying to keep things as similar as possible.
2023-04-14 10:21:29 -06:00
Vinicius Stevam
a3af0b53e3
Trigger unlock popup in appStateController using ApprovalController (#18386) 2023-04-14 05:50:17 +01:00
Bernardo Garces Chapero
6ed72d6934
Refactor eth_getEncryptionPublicKey handling (#18319)
* add EncryptionPublicKeyController

* update message-managers package
2023-04-13 09:24:59 +01:00
Elliot Winkler
6439551075
Convert NetworkController unit tests to TypeScript (#18476)
This helps us more easily compare the unit tests for NetworkController
in this repo and the NetworkController in the `core` repo.

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
2023-04-12 13:53:34 -06:00
Elliot Winkler
3577d3545f
Convert NetworkController to TS (#18358)
Converting this controller to TypeScript furthers the goal of getting
this whole codebase converted, of course, but it also helps in comparing
the differences between this version of the NetworkController and the
version in the `core` repo more easily, which will ultimately help us in
coalescing the two implementations.

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
2023-04-11 10:07:24 -06:00
Matthew Walsh
bb0dff9443
Trigger transaction popup using ApprovalController (#18400) 2023-04-11 14:18:43 +01:00
Vinicius Stevam
b9c5120332
Remove openPopup from preferences controller (#18343) 2023-04-05 08:39:58 +01:00
OGPoyraz
6e40a0eb7e
feat: use siwe detection from @metamask/controller-utils (#18409) 2023-04-04 17:25:57 +02:00
Mark Stacey
7059894399
Update @metamask/swappable-obj-proxy (#18422)
* Update `@metamask/swappable-obj-proxy`

The package `@metamask/swappable-obj-proxy` has been updated to the
latest version. The breaking changes include moving the package under
the `@metamask` scope and converting it to TypeScript.

* Update policy
2023-04-04 09:27:51 -02:30
Mark Stacey
74f2d27d10
Update @metamask/safe-event-emitter (#18419)
The package `safe-event-emitter` has been updated to v2. This update
includes renaming the package to be scoped under `@metamask`, and it
includes a TypeScript migration.
2023-04-03 15:57:39 -02:30
Elliot Winkler
1304ec7af5
Convert shared/constants/metametrics to TS (#18353)
We want to convert NetworkController to TypeScript in order to be able
to compare differences in the controller between in this repo and the
core repo. To do this, however, we need to convert the dependencies of
the controller to TypeScript.

As a part of this effort, this commit converts
`shared/constants/metametrics` to TypeScript. Note that simple objects
have been largely replaced with enums. There are some cases where I even
split up some of these objects into multiple enums.

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2023-04-03 09:31:04 -06:00
Pedro Figueiredo
fbd68d4a3f
Introduce action metrics for mv3 service worker restart (#18346)
* fix dapp interaction e2e test

* wip

* add sentry post request mock

* fix console errors

* fix scripting console error and remove e2e test unnecessary check

* clean up

* remove e2e test

* stop skipping  test

* fixing build mv3 job

* fixing unit tests

* fixing unit tests

* fixing unit tests

* update coverages

* revert skip mv3 e2e test

* remove IN_TEST on the npm script

* remove console.log

* revert aria label changes

* revert aria label changes

* revert permission changes

* revert permission changes

* implement sw restart delay tracking

* fix rebase
2023-03-31 14:22:33 +01:00
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
Elliot Winkler
9b0a6ecc90
NetworkController: Use messenger for events (#18041)
Currently, the network controller notifies consumers about events by
emitting them directly from the controller. In order to migrate the
controller to the core repo, where controllers use the BaseControllerV2
interface, events should be emitted via a messenger object.

This commit updates the network controller to use a messenger, and then
updates all of the controllers that listen for network events to use the
messenger as well.
2023-03-30 12:39:36 -06:00