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

1300 Commits

Author SHA1 Message Date
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
Filip Sekulic
0351309227
OpenSea security provider metrics (#17688)
* Added metrics for the OpenSea security provider

* Fixed tests

* Fixed a test

* Fixed metrics

* Code refactor

* Lint fixed

* Removed unnecessary code

* Fix build

* Fix e2e

* Cleanup

* Fix e2e

* Code refactor

* Removed unnecessary code

* rpc middleware: catch securityProviderCheck errors
to not block dapp rpc requests

* Fixed an issue

* Added aditional test

* Applied some changes

* Fixed a test

* Fixed a test

* Code refactor

* Covered more code with tests

* Updated a test

* Fixed an issue

---------

Co-authored-by: Jyoti Puri <jyotipuri@gmail.com>
Co-authored-by: digiwand <20778143+digiwand@users.noreply.github.com>
Co-authored-by: Brad Decker <bhdecker84@gmail.com>
2023-03-23 14:01:51 -03:00
Alex Donesky
349c9d4a03
Refactor network client constructor (#17652) 2023-03-22 17:20:59 -05:00
vthomas13
16fa967740
Revert "What's new - OpenSea security provider (#16831)" (#17968)
This reverts commit 932282e638.
2023-03-22 12:51:37 -04:00
Elliot Winkler
bf851a56a4
Align network client tests with core repo (#17904)
When the network client tests in this repo were copied over to the core
repo, some alterations were made. This commit copies them back to this
repo so that the two test suites are easier to compare to each other.
Changes include:

* Extracting `testsFor*` functions (functions that bundle similar tests
  together) into separate files
* Reordering the tests defined in
  `testsForRpcMethodsThatCheckForBlockHashInResponse`
* Reordering the set of RPC methods listed in `shared-tests.js`
* Reordering the type definitions defined in `shared-tests.js` to be
  closer to the functions that use them
* Updating the tests defined in `testsForRpcMethodSupportingBlockParam`
  so that when they make requests they pass params, even if it's just an
  empty array
2023-03-20 10:50:52 -06:00
Matthew Walsh
bf29922488
Use core message managers and create sign controller (#18163) 2023-03-20 13:19:50 +00:00
Alex Donesky
d45c4ed497
make network-controller methods overwrite rather than merge provider state (#18127)
* make network-controller methods overwrite rather than merge provider state
2023-03-16 15:53:29 -05:00
Mark Stacey
bd23a49013
Revert "Moved subscribe and filter into network controller (#16693)" (#18129)
* Revert "Moved subscribe and filter into network controller (#16693)"

This reverts commit 6f6984fa58. That
commit was an RPC middleware refactor intended to move the subscribe
and filter middleware into the network controller, to simplify the
process of sharing this middleware between clients.

This refactor resulted in `eth_subscribe` notifications being sent on
the wrong connections, causing the UI to break in some cases (the UI
`provider` connection does not support notifications). This happened
because the `setupProviderEngine` function runs per-connection,
whereas the engine setup inside the network controller is global. The
global network client cannot support notifications because it has no
way to route them; they'll need to stay in the per-connection provider
engine.

Closes #17467

* Add e2e test

An e2e test has been added that confirms subscriptions are only
broadcast to the site that registered them. This test fails on
`develop`.
2023-03-15 12:16:31 -02:30
Alex Donesky
23ca4460cf
Migrate network configurations (previously frequentRpcListDetail) from PreferencesController to NetworkController (#17421) 2023-03-09 15:00:28 -06:00
Hassan Malik
7086494b72
[FLASK] BREAKING - snaps-monorepo@0.30.0 (#17718)
* updated snap permission to wallet_snap, updated tests and added migration

* updated snap packages

* yarn.lock fix

* fixed errors

* override policy

* update policy

* undo override

* updated localization message descriptions

* updated lavamoat policy

* more policy updates

* update permission controller version

* update policy

* update fixture builder

* updated code to include permission value to satisfy wallet_snap permission description call

* fix import issue

* update test-snaps version

* added missing actions, added snap permission dedupe function

* prettier fix

* fix fencing

* add more fencing

* prettier fix

* fix fencing (again)

* added new action and selector and updated view snap accordingly

* update test snaps website version

* unfence request variable

* add fencing

* add optional chaining to fix type error

* update migration #

* remove old migration

* prettier fix

* fix migration test

* fix fencing

* added missing fencing

* updated code to workaround fencing

* update test-snaps site version and remove snap confirm test

* update snap packages

* update policies

* fix merge marker issue

* update test

* more fixes

* fix permissions

* update test

* fixed test

* Bump test-snaps and iframe-execution-environment

* remove unused snap permission from fixture builder

* update policies

* undo comment removal, update selector implementation

* removed unnecessary function, updated migration, updated caveat action

* remove optional chaining

* fix type issue

* more type fixes

* fix migration test

* remove isFlask check, make migration logic more robust

* update coverage

* Update LavaMoat policies

* Update test/e2e/snaps/enums.js

* add extra bail condition

* Revert "add extra bail condition"

This reverts commit b45c53dcfc6e6e35a5e283d4955d6d6ea9ca5965.

* Revert "Revert "add extra bail condition""

This reverts commit cd2ded677935c9cdab0c02b6af55474c83727f60.

* fix test

* add SnapController entry to state object

* updated permission name and caveat type with hardcoded values

* add extra test for non-flask scenario

* update lavamoat policies

* fix locale messages

* change coverage target

* re-enable rpc snap test

* revert locale message change

* fix el message

* reverted changes

---------

Co-authored-by: Frederik Bolding <frederik.bolding@gmail.com>
2023-03-08 13:29:23 -05:00
Brad Decker
d9826e9385
fix issue with fragment messageIds (#17949) 2023-03-07 09:46:41 -06:00
Matthew Walsh
d0417da3d0
Move desktop code to flask build type (#17960) 2023-03-06 19:35:00 +00:00
Vinicius Stevam
e07ec9dcf3
identify desktop is paired in the metrics event (#17892) 2023-03-02 14:55:27 -06:00
Danica Shen
987daee854
fix(17855): persist popup when sw is restarted (#17855)
* fix(17463): persist popup when sw is restarted

* feat(17855): clear local variable when close window
2023-03-02 16:50:00 +00:00
Mark Stacey
e223348fb3
Update eth-json-rpc-middleware from v9 to v10 (#17591)
This release only includes one breaking change, which is the renaming
of the package to be under the `@metamask` scope. It includes
improvements to the types that will unblock migrating our network
clients to TypeScript.
2023-02-27 13:19:08 -03:30
Filip Sekulic
932282e638
What's new - OpenSea security provider (#16831) 2023-02-27 10:20:22 -06:00
Elliot Winkler
b106bbf1d9
Remove extraneous methods from NetworkController (#17522)
The network controller has a variety of methods that just retrieve
controller state. These methods are not necessary because controller
state is already part of the public API of the controller and can be
accessed directly.

These methods are:

- getCurrentChainId
- getCurrentRpcUrl
- getNetworkIdentifier
- getNetworkState
- getProviderConfig
- isNetworkLoading

This is part of a larger effort to normalize the API of both network
controllers, to make them easier to merge.
2023-02-22 10:43:37 -07:00
David Walsh
24e0a9030b
UX: Move Portfolio link to its own button (#17722) 2023-02-21 09:32:08 -06:00
Nidhi Kumari
33cc8d587a
NFT: Replaced all the instances of collectibles with NFTs (#17741)
* replaced all the instances of collectibles with nfts

* updated actions

* updated e2e seeder

* updated confirm Approve test

* updated test dapp change

* updated test dapp change

* nit fix

* nit fix

* updated casing and snapshots

* updated casinG

* added migrations

* updated ,igration

* updated 078.test

* updated tests for 078 migration

* updated migration

* updated 078 index.js
2023-02-17 00:53:29 +05:30
Guillaume Roux
ccde54937f
Pass excludedPermissions to SnapController (#17321)
Co-authored-by: Frederik Bolding <frederik.bolding@gmail.com>
2023-02-15 11:09:47 +01:00
tgmichel
3a00b5ab54
Additional incoming transactions support (#14219) 2023-02-14 12:35:42 -06:00
Elliot Winkler
7e97ff2be4
Expand network controller unit test coverage (#17498)
The network controller has some tests, but they are incomplete and don't
follow our latest best practices for writing unit tests.

This commit greatly increases the amount of test coverage for the API
that we want to retain in NetworkController, in particular the seemingly
myriad paths that the code takes starting from `initializeProvider`,
`resetConnection`, `setRpcTarget`, `setProviderType`,
`rollbackToPreviousProvider`, and `lookupNetwork`.

There were a couple of pieces of logic I noted which don't seem to have
any effect due to being redundant or unreachable, but they also don't
make our lives more difficult, either, so I opted to leave them in.

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
Co-authored-by: Zachary Belford <belfordz66@gmail.com>
2023-02-08 13:10:04 -07:00
Harry
b4ecc4c3f5
Disable eth_sign by default, allow users to toggle it back on (#17308)
* Added translation for eth sign toggle

* Disabled the ability to call eth_sign by default. Added ability within advanced settings to renable support for eth_sign

* Add test case for eth_sign being enabled and disabled

* Modified copy

* Moved rpc method preference to its own object within store

* Complete work on moving rpc method preference into its own object within store

* Fix with prettier

* Fix lint

* Fix a unit test

* Fix test

* Renamed function and object keys to be more intuitive

* Fix e2e test

* Enabled eth_sign through preferences fixture

* Fix lint

* Fix e2e test

Wait for the notification popup to close, leaving 2 window handles the extension and the test dapp

* Fix e2e test

* Fix unit test

Enable eth_sign method

* Lint fix

---------

Co-authored-by: PeterYinusa <peter.yinusa@consensys.net>
Co-authored-by: Dan J Miller <danjm.com@gmail.com>
2023-02-06 13:17:50 -03:30
Mark Stacey
d2f50d47fa
Add network client tests for methods not supported by Infura (#17347)
Any methods in the Ethereum JSON-RPC spec are now included in our
network client tests. These tests were skipped previously because they
are not supported by Infura.

Closes #16938
2023-02-02 15:44:22 -03:30
vthomas13
532a10f9f5
Adding browser outdated notification (#17027)
* Adding browser outdated notification

* updating dependency

* adding unit tests for util function

* adding unit tests for selectors, lintfix

* Added Tests, refactored notification delay logic

* lint:fix

* adding test coverage for method parameter

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

adding documentation details

Co-authored-by: Mark Stacey <markjstacey@gmail.com>

* moving declaration into test

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

spacing in test file

Co-authored-by: Mark Stacey <markjstacey@gmail.com>

* Update jest.config.js

removing duplicate entries

Co-authored-by: Mark Stacey <markjstacey@gmail.com>

* using async submitRequestToBackground method

* removing unused import

* removing unnecessary link syntax in notification

* adding opera and edge and associated tests

* handling the undefined case in bowser.satisfies

* setOutdatedBrowserWarningLastShown try/catch

* lint:fix

* Removing try/catch and letting errors bubble up

Removing deprecated displayWarning method

Co-authored-by: Mark Stacey <markjstacey@gmail.com>

* taking out forceMetamaskUpdateState call

* excludint app-state test from mocha test suite

* Added note: Jest files should match Mocha excluded

* syntax error, lint:fix

---------

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2023-02-02 13:56:41 -05:00
Harry
fd819451e1
🐛 Calldata validation (#17326)
Co-authored-by: Dan J Miller <danjm.com@gmail.com>
Co-authored-by: Pedro Figueiredo <pedro.figueiredo@consensys.net>
Co-authored-by: brad-decker <bhdecker84@gmail.com>
2023-02-01 16:34:55 -06:00
Mark Stacey
db2e461416
Add tests for retryOnEmpty middleware (#17364)
* Add tests for `retryOnEmpty` middleware

Tests have been added for the `retryOnEmpty` middleware.

This middleware is only used on the Infura network client, so the tests
that demonstrate this retry behavior are only enabled for the `infura`
provider type.

Most of the tests added were to cover cases where the retry middleware
is skipped, so they were applicable for both provider types.

Closes #17004

* Improve readability of block number tests

The test cases for passing a block number parameter have been made more
readable. Specifically, a comment has been added each time params are
built to call attention to the block parameter and what value it has,
so that it's clear whether it's larger or smaller than the current
block number.

Additionally the blocks for "less than the current block number" and
"equal to the current block number" have been combined using
`describe.each`.
2023-02-01 16:33:26 -03:30
Brad Decker
d9275bb1c1
Fixing/extending type definitions for later usage (#17514) 2023-02-01 11:53:21 -06:00
Brad Decker
6e7f5c3e21
Move THEME_TYPE to new preferences.ts file (#17515) 2023-01-31 17:49:00 -06:00
Danica Shen
c23bd4925b
feature: convert level 32 files to typescript (#17390) 2023-01-27 18:28:03 +00:00
Mark Stacey
001ea4c951
Test parameter change cache miss (#17346)
Tests have been added to ensure that our middleware will not return a
cached response to a request with unique parameters. Each parameter
supported by each method is tested independently.

Closes #17003
2023-01-26 12:27:46 -03:30
David Walsh
29d4799f46
Fix #17388 - Remove dismiss button from NFT notification (#17389) 2023-01-25 13:28:15 -06:00
amerkadicE
dd09245ff6
Fix/use etherjs specific imports (#15461)
* replace ethers with submodules

Co-authored-by: Alex <adonesky@gmail.com>
2023-01-24 08:10:36 -06:00
Brad Decker
ead1446c98
Refactor usages of conversion util in the app folder and shared folder in favor of Numeric (#17331) 2023-01-23 11:41:01 -06:00
Vladimir Saric
f988dc1c5e
Enable the Token Allowance flow by default for all users (#16740) 2023-01-23 21:49:55 +05:30
Filip Sekulic
27d34166fe
Security provider check (OpenSea) (#16584) 2023-01-23 20:02:01 +05:30
Mark Stacey
d6cf809bcc
Setup network controller mocks per-test (#17250)
The network controller unit test network mocks are now setup for each
test. This makes modifying network behavior on a per-test basis easier,
and makes it more clear which test relies upon which mocks.
2023-01-23 10:52:42 -03:30
David Walsh
cb6ee2b3fe
Use async/await instead of Promise.resolve (#16221) 2023-01-20 14:20:18 -06:00
Brad Decker
92f6ea6f6b
Relocate conversion utils to shared/modules/conversion.utils.js (#17319) 2023-01-20 11:04:37 -06:00
ryanml
a19a5d60d3
Convert shared/constants/hardware-wallets.js -> Typescript (#17310) 2023-01-20 09:14:40 -06:00
Brad Decker
5f6d2ba6b0
Convert Transaction constants to typescript (#17149) 2023-01-18 08:47:29 -06:00
Mark Stacey
7d77554f3b
Refactor: Construct the network controller within each test (#17199)
The network controller is now constructed within each network
controller unit test, rather than in the `beforeEach`. This allows us
to customize the constructor options in each test, which some planned
future tests will require.

The controller is constructed with a helper function that also handles
calling `destroy` after each test, even if the test failed. This helps
to prevent tests from affecting each other.

Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
2023-01-17 19:58:16 -03:30
Mark Stacey
3c52e80713
Remove unnecessary test (#17181)
This test was testing a function that was only present in the test
module.

The function under test was mistakenly moved here when it was
discovered that it wasn't being used elsewhere, under the assumption
that it was used in these tests. I hadn't realized it was being tested
directly.
2023-01-17 19:57:41 -03:30
Mark Stacey
61d8fbb1d4
Refactor: Use network mocks for network unit tests (#17126)
The network controller unit tests now use network mocks rather than
mocking controller methods.

This makes the tests less brittle, as they will no longer break when
internal changes to the `_getLatestBlock` method are made.
2023-01-17 14:39:02 -03:30
Niranjana Binoy
a0bb4a6c5a
Toggle option to enable/disable balance and Token rate checking for using third-party API (#16772) 2023-01-17 10:23:04 -05:00
Mark Stacey
15ee9e1556
Await initializeProvider in network controller tests (#17180)
The network controller unit tests have been updated to wait until the
network controller is fully initialized before proceeding. This ensures
that the initialization doesn't have any side-effects that affect later
tests.
2023-01-13 12:53:39 -03:30
Alex Donesky
709b64c128
Remove dead addressbook migration code (#17127)
* remove dead address book migration code

* cleanup

* addToFrequentRpcList -> upsertToFrequentRpcList

* remove migrateAddressBookState function
2023-01-12 13:05:48 -06:00
Mark Stacey
6482848610
Fix NetworkController destroy before initialization (#17136)
The NetworkController `destroy` method has been updated to ensure that
it no longer throws if called before initialization.

This method was added recently in #17032, but we forgot to handle the
case where the controller was not initialized.
2023-01-11 15:26:33 -03:30
Mark Stacey
e8e0cf5786
Remove unecessary code from the network controller tests (#17137)
The `initializeProvider` parameters were removed recently in #16863,
but they were still being set in tests. They have now been removed.

An unused property was also being set in the tests, which has now also
been removed.
2023-01-11 15:26:18 -03:30
David Walsh
dc3a09de16
Dark Mode: Set to default based on user preferred scheme (#15870) 2023-01-06 14:07:47 -06:00
Mark Stacey
87ce653c86
Move MetaMask middleware out of network controller (#16863)
The "MetaMask middleware" is the set of middleware for handling methods that
we don't send to the network. This includes signing, encryption, `getAccounts`,
and methods that rely on pending transaction state.

Previously this middleware was setup as part of the network client, despite
having nothing to do with the network. They have been moved into the main RPC
pipeline established in `metamask-controller.js` instead.

This is a pure refactor, and should have no functional changes. The middleware
are still run in exactly the same order with the same arguments.
2023-01-06 13:44:50 -03:30
Zachary Belford
cd2249f193
Add tests for custom JSON-RPC network client (#16337)
Previously we had written tests for `createInfuraClient`, which creates a middleware stack designed to connect to an Infura provider. These tests exercise various RPC methods that relate to the behavior that the middleware provides (mainly around caching). 

Now we need to write the same tests but for `createJsonRpcClient`, which creates a middleware stack designed to connect to a non-Infura RPC endpoint. To do this, we had to:

- Consolidate the tests for both types of RPC client into a single test file.
- Add conditions around tests or assertions in tests to account for differences in behavior between the two sets of middleware stacks.
- Relocate code in `createJsonRpcClient` which slows down `eth_estimateGas` calls just for tests so that this behavior can be disabled in the network client tests.

Eventually, as we unify the network controllers in this repo and in the core repo, we will move these tests into the core repo.

Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
2023-01-06 10:10:17 -07:00
Michal
b1254843ac
determine tx type using normalized txparams (#17055)
Co-authored-by: ryanml <ryanlanese@gmail.com>
2023-01-05 17:37:50 -07:00
Brad Decker
f586f142be
add an extra identifier on anonymized duplicate events (#17080) 2023-01-05 08:49:55 -06:00
Mark Stacey
8d28fbccc5
Stop block tracker after each network controller unit test (#17032)
The network controller unit tests have been updated to stop the block
tracker after each test. This was accomplished with a new `destroy`
method.
2023-01-04 17:46:22 -03:30
Daniel
2832f8a97e
Update quote selection for Optimism (#16998) 2022-12-21 20:59:34 +01:00
Zachary Belford
6f6984fa58
Moved subscribe and filter into network controller (#16693)
Our middleware for handling subscription and filter-related methods (`eth-json-rpc-filters`) currently lives in our RPC pipeline ahead of the network stack. This commit moves this middleware to the network client middleware instead. There are two reasons for this change. First, this middleware wraps RPC methods that are supported by the network. Second, it is necessary for this middleware to live with the network client so that it will aid us in unifying the NetworkController in this repo and the NetworkController in the `controllers` repo.

Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
2022-12-20 10:28:09 -07:00
Jyoti Puri
c61d44a3be
Making add un-approved transaction idempotent (#16995) 2022-12-20 18:01:37 +05:30
Olusegun Akintayo
13de51e748
Security and Privacy Settings Re-org (#16756) 2022-12-19 18:46:36 +01:00
Mark Stacey
3e98758719
Rename the network controller module (#16974)
The network controller module has been renamed from `network.js` to
`network-controller.js`. All of our newer controllers have "controller"
in the module names, so this aligns better with that convention. It
also brings the test module name into alignment (it's already called
"network-controller.test.js").
2022-12-16 16:37:06 -03:30
Mark Stacey
dbe77289d3
Make initializeProvider and lookupNetwork async (#16881)
* Make `initializeProvider` and `lookupNetwork` async

These two methods were "synchronous" previously, but initiated an
asynchronous operation. They have both been made `async` to bring them
more in-line with the mobile controller API, and to make them easier
to test.

This should include zero functional changes. These methods are still
being invoked without an `await`, to preserve the same behaviour they
had previously.

This relates to https://github.com/MetaMask/controllers/issues/971

* Move 'net_version' query to private function

* Fix error made when resolving conflicts

* Refactor to improve readability
2022-12-16 13:03:22 -03:30
Alex Donesky
5d285f7be5
fix cached detected token results (#16866) 2022-12-14 12:26:08 +05:30
Elliot Winkler
dd59792392
Remove if to expose more network client tests (#16906)
This commit affects the network client tests, which were added in a
previous PR to test the behavior of `createInfuraClient`, a function
called that sets up a portion of the middleware stack in the JSON-RPC
layer.

An `if` statement appears in the tests which limits the execution of
certain tests. However, this seems to have been added for debugging
purposes and is not actually needed.

Co-authored-by: Brad Decker <bhdecker84@gmail.com>
2022-12-13 12:49:58 -07:00
Mark Stacey
69e5d6da4a
Make certain network controller methods private (#16883)
Five network controller methods have been renamed to start with an
underscore:
* `getLatestBlock`
* `setNetworkState`
* `setNetworkEIPSupport`
* `clearNetworkDetails`
* `setProviderConfig`

All of these methods were used solely within the network controller.
The leading underscore now documents these methods as being private.

A few tests required updates as well because they were stubbing out one
of these methods.

This should include zero functional changes.

This relates to https://github.com/MetaMask/controllers/issues/971
2022-12-13 15:43:54 -03:30
Mark Stacey
06d87fb98b
Refactor how network state is passed to transaction controller (#16922)
The network state is now passed to the TransactionController via a
getter function and a subscription function, instead of passing one of
the network controller stores directly.

This way of passing the state makes further refactoring easier, as we
don't have to change the input when the store is changed or replaced.
It's also more aligned with our conventions today.

This change was made as part of a larger refactor of the network
controller, as part of the effort to merge the mobile and extension
network controllers.
2022-12-13 15:43:12 -03:30
Mark Stacey
75177c5998
Make setProviderType synchronous (#16879)
The network controller method `setProviderType` was marked as `async`
despite doing nothing async internally. The `async` has been dropped.

This should have zero functional impact.

This relates to https://github.com/MetaMask/controllers/issues/971
2022-12-13 13:57:48 -03:30
Mark Stacey
5df6f653af
Remove unused verifyNetwork method (#16882)
The network controller method `verifyNetwork` has been deleted. It was
unused.

This relates to https://github.com/MetaMask/controllers/issues/971
2022-12-13 13:57:28 -03:30
Mark Stacey
6d64951938
Move infuraProjectId to network controller constructor (#16884)
The network controller `setInfuraProjectId` method has been deleted.
The Infura project ID is only ever set upon construction, so it is now
passed in as a constructor parameter instead.

Rather than adding this as a second parameter, the network controller
now uses an "options bag" for constructor parameters. The initial state
was the first parameter, but it's now passed in as the `state` option
instead.

These changes make the API more similar to the mobile network
controller API.

This should have zero functional changes.

This relates to https://github.com/MetaMask/controllers/issues/971

Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
2022-12-13 12:09:21 -03:30
Mark Stacey
048b7e4cb6
Fix shared mocks in RPC network client test (#16856)
* Fix shared mocks in RPC network client test

Some of the provider api unit tests were inadvertently sharing test
mocks. A `params` object used for mock RPC calls was being shared
between tests and between calls within individual tests. They have been
updated to generate a fresh `params` object for each mock RPC call.

* Explicitly set blockParam to undefined
2022-12-12 13:49:22 -03:30
Jyoti Puri
8125473dc5
Removing flag for EIP1559 V2 support (#16446) 2022-12-09 00:07:06 +05:30
Jyoti Puri
154172d5f8
Network request in background should not start until onboarding is completed (#16773) 2022-12-02 23:29:03 +05:30
Pedro Figueiredo
d096560d85
Give the user ability to opt out of get balance batch request for all loaded accounts (#16746) 2022-12-01 21:16:04 +00:00
Brad Decker
b3895b6840
remove rpc urls from metrics (#16710) 2022-11-30 09:52:25 -06:00
Frederik Bolding
dfb6210910
[FLASK] snaps-monorepo@0.25.0 (#16673)
* snaps-monorepo@0.25.0

* Regen LavaMoat policies

* Bump test-snaps

* [FLASK] Add Snaps JSON-RPC handler permission (#16670)

* Add Snaps JSON-RPC handler permission

* Add copy and icon

* Fix test

Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>
2022-11-30 13:19:33 +01:00
Elliot Winkler
51cffa15dd
Migrate to new controller packages (#16547)
* Migrate to new controller packages

`@metamask/controllers` is deprecated, and most of the controllers that
lived here are now located in their own package ([1]). This commit
replaces `@metamask/controllers` in `package.json` with references to
these packages and updates `import` lines to match.

[1]: https://github.com/MetaMask/controllers/pull/831

* Support GitHub registry for draft PRs (#16549)

* Add additional allowed host to lockfile linter

* Update LavaMoat policies

* Add policy exception for nanoid

* Add additional nanoid overrides

* Update LavaMoat policies again

* Bump controller packages

* Update lavamoat

* Bump controller packages

* Update packages to v1.0.0

* Expand gitignore comment

* Unpin controller dependencies, using ^ range instead

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2022-11-24 16:29:07 -03:30
Jyoti Puri
82dc628fa3
Remove callback from being saved in controller state (#16627) 2022-11-23 23:30:05 +05:30
Olusegun Akintayo
086a7d0483
Keep memstore contents after service worker restarts (#15913)
* Add all controllers in memstore to store
Add methods to controller to reset memstore
Reset memstore when popup or tab is closed.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* When profile is loaded, set isFirstTime to true..
After resetting the controllers, set the flag to false.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Remove console.logs

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* For some reason programmatically computing the store is not working.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Proper check for browser.storage

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* do a list of rest methods instead of reset controllers.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Mock controller resetStates and localstore get/set

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Comments about TLC

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* bind this.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* use globalThis instead of locastore to store first time state.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Test to check that resetStates is not called a second time

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Set init state in GasFeeController and other controllers so that their
state is persisted accross SW restarts

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Revert localstore changes

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* wrap the reset states changes in MV3 flag

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Remove localstore from metamask-controller

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Always reset state on MMController start in MV2.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Use relative path for import of isManifestV3

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Fix unit test

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>
2022-11-22 20:56:26 +04:00
Frederik Bolding
de955f3faa
[FLASK] snaps-monorepo@0.24.1 (#16525)
* snaps-monorepo@0.24.0

* Fix imports and regen LavaMoat policies

* Bump iframe-execution-environment

* Fix tests

* Add permissions

* Bump patch

* Bump test-snaps

* [FLASK] Fix update e2e test to catch snaps with caveats (#16546)

* changed snap to update to bip32

* small changes to test

* Fix lint

* Fix E2E

* Update copy

* Update icon

Co-authored-by: Bowen Sanders <bowensanders@gmail.com>
2022-11-22 13:07:08 +01:00
Filip Sekulic
3746ad9451
Add transaction security check toggle (#16271)
Co-authored-by: Brad Decker <bhdecker84@gmail.com>
2022-11-17 08:13:02 -06:00
David Walsh
4ce6487160
BETA - Add beta banner to all screens (#16307)
* Add beta home banner to home screen

* Move the beta home notification to the app-header

* Updates to formatting

* Add beta home banner to home screen

* Move the beta home notification to the app-header

* Updates to formatting

* Update ui/components/app/app-header/index.scss

Co-authored-by: George Marshall <george.marshall@consensys.net>

* Update ui/components/app/app-header/index.scss

Co-authored-by: George Marshall <george.marshall@consensys.net>

* Update ui/components/app/app-header/index.scss

Co-authored-by: George Marshall <george.marshall@consensys.net>

* Move banner to top of page

* Move to own folder, update styles

* Swith to BOX component

* Address feedback

* Add tests

* Update name of component

* Fix tests

* Fix proptype errors

* Fixups

* Remove unrelated changes

* Remove unwanted string changes

* Update beta component name and text

* Update mock data

Co-authored-by: George Marshall <george.marshall@consensys.net>
2022-11-16 11:41:15 -06:00
Brad Decker
0688c3d9ad
persist user traits for comparison (#16506) 2022-11-16 08:17:55 -06:00
Mark Stacey
4f66dc948f
Update @metamask/controllers to v33 (#16493)
The controllers package has been updated to v33. The only breaking
change in this release was to rename the term "collectible" to "NFT"
wherever it appeared in the API.

Changes in this PR have been kept minimal; additional renaming can be
done in separate PRs. This PR only updates the controller names,
controller state, controller methods, and any direct references to
these things. NFTs are still called "collectibles" in most places.
2022-11-15 15:19:42 -03:30
Dan J Miller
5a28a7bd6d
Call onbootcleanup at the end of the tx controller constructor (#16449)
* Call onbootcleanup at the end of the tx controller constructor

* Update app/scripts/controllers/transactions/index.js

Co-authored-by: Frederik Bolding <frederik.bolding@gmail.com>

Co-authored-by: Frederik Bolding <frederik.bolding@gmail.com>
2022-11-10 09:58:27 -03:30
Jyoti Puri
6c0930899d
Make event tracking idempotent using unique messageId (#16267) 2022-11-08 23:38:08 +05:30
Filip Sekulic
f3efe5a0bd
Add improved token allowance experience toggle (#16291) 2022-11-08 11:21:38 -06:00
Frederik Bolding
de3068d932
[FLASK] snaps-monorepo@0.23.0 (#16394)
* snaps-monorepo@0.23.0

* Regen LavaMoat policies

* Update iframe-execution-environment

* Fix tests

* Bump luxon

* Fix lint

* Update test-snaps

* Bump post-message-stream

* Fix E2E
2022-11-08 10:31:22 +01:00
Jyoti Puri
e7deab4b9b
Persisting segment events in MetaMetricsController store (#16198) 2022-11-08 04:33:03 +05:30
Jyoti Puri
83ec64ddd2
Fix approve transaction call in _onBootCleanUp (#16382) 2022-11-04 23:17:53 +05:30
Niranjana Binoy
39037684d4
Fix: To differentiate between which chrome alarm is triggered (#16360) 2022-11-04 11:23:56 -04:00
Erik Marks
a8c1756816
Remove 3box feature and delete ThreeBoxController (#14571)
* Remove 3box feature and delete ThreeBoxController

Lint locale messages

lavamoat policy updates

* Restore 3Box user trait with value `false`

The 3Box user trait has been restored and hard-coded as `false`. This
ensures that users don't get stuck in our metrics as having this trait.

A deprecation comment has been left in various places for this trait.

* Remove unused state

* Remove additional 3box-related things

* Run `yarn-deduplicate`

* Restore migration that was lost while rebasing

* Remove obsolete override

* Remove additional unused resolutions/dependencies

* Update LavaMoat policies

* Remove obsolete security advisory ignore entries

* Remove 3Box fixture builder method

* Update unit tests

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2022-10-31 13:50:50 -02:30
ryanml
6c84e9604c
Enable "Add Popular Network" feature by default for all users (#16172)
* Enable "Add Popular Network" feature by default

* Fixing e2e tests

* Attempt to fix e2e tests

* Revert "Attempt to fix e2e tests"

This reverts commit d88e8944b8df8f7c3075753f8d8b3480439f8e30.

* Get e2e tests passing

Co-authored-by: Dan J Miller <danjm.com@gmail.com>
2022-10-27 07:55:30 -02:30
Jyoti Puri
6995174cbc
MV3 Segment Fix (#16020) 2022-10-11 20:34:32 +05:30