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.
* added eth sign first step
* added modal
* added validation for form
* updated width with block
* added state trigger for toggle
* updated Eth sign modal text changes
* added eth sign toggle tex
* removed unnecessary code
* fixed form validation text
* updated eth toggle text
* added test
* added analytics
* updated design changes
* lint fix
* updated error text
* updated changes
* UX: Multichain: Implement Account Details Popover
* Styling account details popover
* using ButtonSecondary with variant, removing Text
* adding account-details jest test
* Close popover when outside area clicked
* Move all export functionality into the popover
* Improve jest tests
* Implement new design for export key screens
* Hide warning when popover is closed
* Vertically align the copy button
* Move AccountDetailsDisplay to its own file
* Move authentication to its own file
* Move private key to its own component
* Fix misalignment of avatar on display screen
* Move private key to its own component
* Update ui/components/multichain/account-details/account-details-authenticate.js
Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>
* Update ui/components/multichain/account-details/account-details.test.js
Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>
* Prevent account name overflow, update text size
* Use FormTextField
* Add analytics
* Move location of accountDetailsAddress
* Ensure passsword input is used
---------
Co-authored-by: Victor Thomas <10986371+vthomas13@users.noreply.github.com>
Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>
* 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
* 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.
* 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>
* Add updated version of the Snaps list UI
Add more changes to match the designs of snaps list
Add next design iteration for snaps list
Update icons, sizes and pointer behaviour
Add redesign for snap settings page
Refactor and improve designs
Fix unit tests and refactor code
Fix e2e test
Fix lint
Update margin values
Add CSS override for connected sites list and update margins
Update paddings as requested
Fix vertical alignment of links
Fix tooltip position on the enable button
Add usage of getSnapName function for displaying snap names
Fix e2e tests and update date format for snap install date
Improve unit test for snap-settings-card
Change installation info logic
Update mocked state for snap
Add tests for ViewSnap component, refactor and update mocked state
Add check for version info
Change Snaps icon in Settings
Refactor Snaps list to use selector
Add handling in case of missing version history
* Fix icon ref
* Remove console logs
* Remove onClick from selector
* Add code fencing for imports in selectors.js
* switched to use banner alert and added story
* enabled dismiss functionality
* remove close button
* bump global branches coverage target
* replace Typography with Text and (link) Button with ButtonLink
* unit test for component rendering
* left-align button links to match text
* update copy to reflect figma mock ups
* update unit test snapshot
* bump coverage threshold
* update snapshot to reflect button component changes
* update snapshot to reflect box changes
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.
* 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
The mobile sync feature has been removed. It has been disabled for
years. When we enable sync again, it will be using a different
implementation. This has already been removed on the mobile side.
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
* 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
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.
* updated ethereum logo icon
* Updating eth logo (#18631)
* Updating eth logo
* Removing border from eth logo identicon
* Removing old eth logo
* updated snapshot and lint errors
* updated eth logo from svg to png
---------
Co-authored-by: George Marshall <george.marshall@consensys.net>
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
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
* 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
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
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
* 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
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
* 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>
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.
* UX: Multichain: App header
* Export app header, provide required information, put feature flag in place
* Provide available data
* Implement account picker -- centered and opens account popover
* Remove backgrounds, use isUnlocked
* Fix placement of the global menu
* Show logo when unlocked
* Add selector for getting current network, provide props to AvatarNetwork and PickerNetwork
* Wire up the network menu to the header
* fixed ui for all the screens
* updated story for header
* fixed import and header settings
* updated lint error
* fixed tests
* updated header
* removed test
* updated snapshot test
* updated network menu
* updated changes
* removed comment from menu bar
* updated css
* updated test for network list menu
* updated stylesheet
* updated ButtonIcon import
---------
Co-authored-by: NidhiKJha <menidhikjha@gmail.com>
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>
* Ensure that all networkConfiguration object in networkController state have an id
* Lint fix
* Update app/scripts/migrations/084.ts
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
* Add unit tests for error cases
* Simplify code
* Remove unnecessary any typing
* Fix network controller type checking
* Lint fix
* Improve typing
---------
Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
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>
The announcement controller has been updated to v2.0.1. The breaking
change in v2 was the migration to the BaseControllerV2 API. This
affected the constructor, as well as some methods/properties that we do
not use.
* use session storage, instead of chrome.runtime.onStartup and globalThis, for firstTimeLoaded architecture
* Ensure account tracker accounts remain defined upon service worker restart
* lint fix
* Simplify code
* Only call browser.storage.session in mv3
* Only call browser.storage.session.set after resetStates in mv3
* fix metamask controller reset states unit tests
* fix test
* fix test
* Actually fix tests
* lint fix
* Added confirm add institutional feature page
* Finished implementing component
* Added all institutional ducks
* Fixed tests
* Removed ducks and console log
* Fixed snapshots
* Fixed messages json
* Changed method name and using useEffect
* Replace useEffect hook with a simple if statement to check if connectRequest exists and add null return statement to avoid warnings
* Remove unneeded dependency
* Added back useEffect and added a extra check to return null if connectRequest is false
* Fixed eslint problem
* Fixed all issues commented in the pr
* 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
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.
* Add permission cell component
Add storybook and handling for revoked permission colors
* Fix things after conflict resolve after rebase
* Add code refactoring and minor UI changes
* Add permission cell component to snap-update flow
* Update storybook
* Add unit tests for permission cell
* Update component padding
* Fix spacing between permission cells
* Fix main icon color for approved permissions
* Update width value with constant