1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 03:36:18 +02:00
metamask-extension/app/scripts
Mark Stacey 63633635ab
Fix order of accounts in eth_accounts response (#8342)
* Fix order of accounts in `eth_accounts` response

The accounts returned by `eth_accounts` were in a fixed order - the
order in which the keyring returned them - rather than ordered with the
selected account first. The accounts returned by the `accountsChanged`
event were ordered with the selected account first, but the same order
wasn't used for `eth_accounts`.

We needed to store additional state in order to determine the correct
account order correctly on all dapps. We had only been storing the
current selected account, but since we also need to determine the
primary account per dapp (i.e. the last "selected" account among the
accounts exposed to that dapp), that wasn't enough.

A `lastSelected` property has been added to each identity in the
preferences controller to keep track of the last selected time. This
property is set to the current time (in milliseconds) whenever a new
selection is made. The accounts returned with `accountsChanged` and by
`eth_accounts` are both ordered by this property.

The `updatePermittedAccounts` function was merged with the internal
methods for responding to account selection, to keep things simpler. It
wasn't called externally anyway, so it wasn't needed in the public API.

* Remove caveat update upon change in selected account

The order of accounts in the caveat isn't meaningful, so the caveat
doesn't need to be updated when the accounts get re-ordered.

* Emit event regardless of account order

Now that we're no longer relying upon the caveat for the account order,
we also have no way of knowing if a particular account selection
resulted in a change in order or not. The notification is now emitted
whenever an exposed account is selected - even if the order stayed the
same.

The inpage provider currently caches the account order, so it can be
relied upon to ignore these redundant events. We were already emiting
redundant `accountsChanged` events in some cases anyway.
2020-04-16 15:20:01 -03:00
..
account-import-strategies Clean up "JSON File" import strategy test output (#7855) 2020-01-17 19:59:47 -03:30
controllers Fix order of accounts in eth_accounts response (#8342) 2020-04-16 15:20:01 -03:00
lib Prevent accidental use of globals (#8340) 2020-04-15 14:23:27 -03:00
migrations Enable arrow-parens ESLint rule 2020-02-15 17:04:21 -03:30
platforms Refactor notification manager and triggerUi to use extension platform (#8317) 2020-04-11 12:12:45 -03:00
background.js Focus the notification popup if it's already open (#8318) 2020-04-11 20:43:55 -03:00
chromereload.js Fix console.error references 2016-08-29 17:32:39 -07:00
contentscript.js Merge pull request #8056 from whymarrh/arrow-parens 2020-02-17 15:26:43 -07:00
first-time-state.js Migrate codebase to use ESM (#7730) 2020-01-09 00:04:58 -03:30
inpage.js update inpage-provider; minor fixes (#7997) 2020-02-06 07:57:54 -08:00
metamask-controller.js Fix order of accounts in eth_accounts response (#8342) 2020-04-16 15:20:01 -03:00
phishing-detect.js Replace METAMASK_UI_TYPE global with helper function (#8279) 2020-04-01 19:28:10 -03:00
README.md add READMEs to folders, re #3427 2018-03-14 15:33:22 +02:00
ui.js Remove ineffectual close popup function (#8316) 2020-04-10 12:27:58 -03:00

Main MetaMask Code

This folder contains the core-code.

Currently, it is organized mostly based on file category, like:

controllers, migrations, lib

Ongoing Task

Refactor code-structure, thus the subsystems are reflected on the filesystem.

Examples