1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/app/scripts/controllers
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
..
ens Use ethereum-ens-network-map for network support (#7960) 2020-01-31 09:56:50 -03:30
network Implementation encrypt/decrypt feature (#7831) 2020-02-19 14:24:16 -04:00
permissions Fix order of accounts in eth_accounts response (#8342) 2020-04-16 15:20:01 -03:00
transactions Use specified gas limit when speeding up a transaction (#8178) 2020-03-12 11:33:11 -03:00
ab-test.js Remove usages of xtend from the background scripts (#7796) 2020-01-13 08:59:36 -10:00
app-state.js Wait for extension unlock before processing eth_requestAccounts (#8149) 2020-03-23 09:25:55 -07:00
balance.js Consistent jsdoc syntax (#7755) 2020-01-13 14:36:36 -04:00
cached-balances.js Enable arrow-parens ESLint rule 2020-02-15 17:04:21 -03:30
detect-tokens.js Cleanup detect-tokens controller and tests (#8329) 2020-04-13 17:14:42 -03:00
incoming-transactions.js Enable arrow-parens ESLint rule 2020-02-15 17:04:21 -03:30
infura.js Prevent accidental use of globals (#8340) 2020-04-15 14:23:27 -03:00
onboarding.js Remove usages of xtend from the background scripts (#7796) 2020-01-13 08:59:36 -10:00
preferences.js Fix order of accounts in eth_accounts response (#8342) 2020-04-16 15:20:01 -03:00
README.md add READMEs to folders, re #3427 2018-03-14 15:33:22 +02:00
recent-blocks.js Remove usages of xtend from the background scripts (#7796) 2020-01-13 08:59:36 -10:00
threebox.js Migrate codebase to use ESM (#7730) 2020-01-09 00:04:58 -03:30
token-rates.js Prevent accidental use of globals (#8340) 2020-04-15 14:23:27 -03:00

Controllers

Different controllers (in the sense of *VC *View-Controller).