1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 04:46:10 +01:00
metamask-extension/test/unit/app/controllers/permissions
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
..
helpers.js Add permissions controller unit tests (#7969) 2020-03-16 10:13:22 -07:00
mocks.js Fix order of accounts in eth_accounts response (#8342) 2020-04-16 15:20:01 -03:00
permissions-controller-test.js Fix order of accounts in eth_accounts response (#8342) 2020-04-16 15:20:01 -03:00
permissions-log-controller-test.js Add permissions controller unit tests (#7969) 2020-03-16 10:13:22 -07:00
permissions-middleware-test.js Wait for extension unlock before processing eth_requestAccounts (#8149) 2020-03-23 09:25:55 -07:00
restricted-methods-test.js Fix order of accounts in eth_accounts response (#8342) 2020-04-16 15:20:01 -03:00