-
+
+
{ isPopup && !connectedStatusPopoverHasBeenShown ? this.renderPopover() : null }
address === selectedAddress) === -1) {
+ return identities[selectedAddress]
+ }
+ }
+
+ return undefined
+}
+
+export function getOrderedConnectedAccountsForActiveTab (state) {
+ const { activeTab, metamask } = state
+ const { identities, permissionsHistory } = metamask
+
+ const permissionsHistoryByAccount = permissionsHistory[activeTab.origin]?.['eth_accounts']?.accounts
+
+ return getPermittedAccountsForCurrentTab(state)
+ .map((address) => ({
+ address,
+ name: identities[address].name,
+ lastActive: permissionsHistoryByAccount[address],
+ }))
+ .sort(({ address: addressA }, { address: addressB }) => {
+ const lastSelectedA = identities[addressA].lastSelected
+ const lastSelectedB = identities[addressB].lastSelected
+ if (lastSelectedA === lastSelectedB) {
+ return 0
+ } else if (lastSelectedA === undefined) {
+ return 1
+ } else if (lastSelectedB === undefined) {
+ return -1
+ }
+
+ return lastSelectedB - lastSelectedA
+ })
+}
+
+export function getPermissionsForActiveTab (state) {
+ const { activeTab, metamask } = state
+ const {
+ domains = {},
+ permissionsDescriptions,
+ } = metamask
+
+ return domains[activeTab.origin]?.permissions?.map(({ parentCapability }) => {
+ const description = permissionsDescriptions[parentCapability]
+ return {
+ key: parentCapability,
+ description,
+ }
+ })
+}
diff --git a/ui/app/selectors/tests/permissions.test.js b/ui/app/selectors/tests/permissions.test.js
index 3217ba10e..ad214c572 100644
--- a/ui/app/selectors/tests/permissions.test.js
+++ b/ui/app/selectors/tests/permissions.test.js
@@ -1,5 +1,9 @@
import assert from 'assert'
-import { getConnectedDomainsForSelectedAddress } from '../permissions'
+import {
+ getConnectedDomainsForSelectedAddress,
+ getOrderedConnectedAccountsForActiveTab,
+ getPermissionsForActiveTab,
+} from '../permissions'
describe('selectors', function () {
@@ -153,4 +157,255 @@ describe('selectors', function () {
})
})
+ describe('getConnectedAccountsForActiveTab', function () {
+ const mockState = {
+ activeTab: {
+ 'title': 'Eth Sign Tests',
+ 'origin': 'remix.ethereum.org',
+ 'protocol': 'https:',
+ 'url': 'https://remix.ethereum.org/',
+ },
+ metamask: {
+ identities: {
+ '0x7250739de134d33ec7ab1ee592711e15098c9d2d': {
+ 'address': '0x7250739de134d33ec7ab1ee592711e15098c9d2d',
+ 'name': 'Really Long Name That Should Be Truncated',
+ },
+ '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5': {
+ 'address': '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
+ 'name': 'Account 1',
+ },
+ '0xb3958fb96c8201486ae20be1d5c9f58083df343a': {
+ 'address': '0xb3958fb96c8201486ae20be1d5c9f58083df343a',
+ 'name': 'Account 2',
+ },
+ },
+ domains: {
+ 'remix.ethereum.org': {
+ 'permissions': [
+ {
+ '@context': [
+ 'https://github.com/MetaMask/rpc-cap',
+ ],
+ 'caveats': [
+ {
+ 'name': 'exposedAccounts',
+ 'type': 'filterResponse',
+ 'value': [
+ '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
+ '0x7250739de134d33ec7ab1ee592711e15098c9d2d',
+ ],
+ },
+ ],
+ 'date': 1586359844177,
+ 'id': '3aa65a8b-3bcb-4944-941b-1baa5fe0ed8b',
+ 'invoker': 'remix.ethereum.org',
+ 'parentCapability': 'eth_accounts',
+ },
+ ],
+ },
+ 'peepeth.com': {
+ 'permissions': [
+ {
+ '@context': [
+ 'https://github.com/MetaMask/rpc-cap',
+ ],
+ 'caveats': [
+ {
+ 'name': 'exposedAccounts',
+ 'type': 'filterResponse',
+ 'value': [
+ '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
+ ],
+ },
+ ],
+ 'date': 1585676177970,
+ 'id': '840d72a0-925f-449f-830a-1aa1dd5ce151',
+ 'invoker': 'peepeth.com',
+ 'parentCapability': 'eth_accounts',
+ },
+ ],
+ },
+ 'uniswap.exchange': {
+ 'permissions': [
+ {
+ '@context': [
+ 'https://github.com/MetaMask/rpc-cap',
+ ],
+ 'caveats': [
+ {
+ 'name': 'exposedAccounts',
+ 'type': 'filterResponse',
+ 'value': [
+ '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
+ ],
+ },
+ ],
+ 'date': 1585616816623,
+ 'id': 'ce625215-f2e9-48e7-93ca-21ba193244ff',
+ 'invoker': 'uniswap.exchange',
+ 'parentCapability': 'eth_accounts',
+ },
+ ],
+ },
+ },
+ domainMetadata: {
+ 'remix.ethereum.org': {
+ 'icon': 'https://remix.ethereum.org/icon.png',
+ 'name': 'Remix - Ethereum IDE',
+ },
+ },
+ permissionsHistory: {
+ 'remix.ethereum.org': {
+ 'eth_accounts': {
+ 'accounts': {
+ '0x7250739de134d33ec7ab1ee592711e15098c9d2d': 1586359844192,
+ '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5': 1586359844192,
+ },
+ 'lastApproved': 1586359844192,
+ },
+ },
+ },
+ permissionsDescriptions: {
+ 'eth_accounts': "View the addresses of the user's chosen accounts.",
+ },
+ },
+ }
+
+ it('should return a list of connected accounts', function () {
+ assert.deepEqual(getOrderedConnectedAccountsForActiveTab(mockState), [{
+ address: '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
+ name: 'Account 1',
+ lastActive: 1586359844192,
+ }, {
+ address: '0x7250739de134d33ec7ab1ee592711e15098c9d2d',
+ name: 'Really Long Name That Should Be Truncated',
+ lastActive: 1586359844192,
+ }])
+ })
+ })
+
+ describe('getPermissionsForActiveTab', function () {
+ const mockState = {
+ activeTab: {
+ 'title': 'Eth Sign Tests',
+ 'origin': 'remix.ethereum.org',
+ 'protocol': 'https:',
+ 'url': 'https://remix.ethereum.org/',
+ },
+ metamask: {
+ identities: {
+ '0x7250739de134d33ec7ab1ee592711e15098c9d2d': {
+ 'address': '0x7250739de134d33ec7ab1ee592711e15098c9d2d',
+ 'name': 'Really Long Name That Should Be Truncated',
+ },
+ '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5': {
+ 'address': '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
+ 'name': 'Account 1',
+ },
+ '0xb3958fb96c8201486ae20be1d5c9f58083df343a': {
+ 'address': '0xb3958fb96c8201486ae20be1d5c9f58083df343a',
+ 'name': 'Account 2',
+ },
+ },
+ domains: {
+ 'remix.ethereum.org': {
+ 'permissions': [
+ {
+ '@context': [
+ 'https://github.com/MetaMask/rpc-cap',
+ ],
+ 'caveats': [
+ {
+ 'name': 'exposedAccounts',
+ 'type': 'filterResponse',
+ 'value': [
+ '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
+ '0x7250739de134d33ec7ab1ee592711e15098c9d2d',
+ ],
+ },
+ ],
+ 'date': 1586359844177,
+ 'id': '3aa65a8b-3bcb-4944-941b-1baa5fe0ed8b',
+ 'invoker': 'remix.ethereum.org',
+ 'parentCapability': 'eth_accounts',
+ },
+ ],
+ },
+ 'peepeth.com': {
+ 'permissions': [
+ {
+ '@context': [
+ 'https://github.com/MetaMask/rpc-cap',
+ ],
+ 'caveats': [
+ {
+ 'name': 'exposedAccounts',
+ 'type': 'filterResponse',
+ 'value': [
+ '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
+ ],
+ },
+ ],
+ 'date': 1585676177970,
+ 'id': '840d72a0-925f-449f-830a-1aa1dd5ce151',
+ 'invoker': 'peepeth.com',
+ 'parentCapability': 'eth_accounts',
+ },
+ ],
+ },
+ 'uniswap.exchange': {
+ 'permissions': [
+ {
+ '@context': [
+ 'https://github.com/MetaMask/rpc-cap',
+ ],
+ 'caveats': [
+ {
+ 'name': 'exposedAccounts',
+ 'type': 'filterResponse',
+ 'value': [
+ '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
+ ],
+ },
+ ],
+ 'date': 1585616816623,
+ 'id': 'ce625215-f2e9-48e7-93ca-21ba193244ff',
+ 'invoker': 'uniswap.exchange',
+ 'parentCapability': 'eth_accounts',
+ },
+ ],
+ },
+ },
+ domainMetadata: {
+ 'remix.ethereum.org': {
+ 'icon': 'https://remix.ethereum.org/icon.png',
+ 'name': 'Remix - Ethereum IDE',
+ },
+ },
+ permissionsHistory: {
+ 'remix.ethereum.org': {
+ 'eth_accounts': {
+ 'accounts': {
+ '0x7250739de134d33ec7ab1ee592711e15098c9d2d': 1586359844192,
+ '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5': 1586359844192,
+ },
+ 'lastApproved': 1586359844192,
+ },
+ },
+ },
+ permissionsDescriptions: {
+ 'eth_accounts': "View the addresses of the user's chosen accounts.",
+ },
+ },
+ }
+
+ it('should return a list of permissions strings', function () {
+ assert.deepEqual(getPermissionsForActiveTab(mockState), [{
+ key: 'eth_accounts',
+ description: "View the addresses of the user's chosen accounts.",
+ }])
+ })
+ })
+
})