1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 04:46:10 +01:00
metamask-extension/app/scripts/controllers/permissions/restrictedMethods.js
Dan J Miller fda4c94670
Design improvements for the Connect flow (#8494)
* Design improvements for the Connect flow

* Make new-account-modal close a button

* Update e2e tests for auto select account on connect flow
2020-05-04 18:10:09 -02:30

38 lines
1.3 KiB
JavaScript

export default function getRestrictedMethods ({ getIdentities, getKeyringAccounts }) {
return {
'eth_accounts': {
description: `View your public address (required)`,
method: (_, res, __, end) => {
getKeyringAccounts()
.then((accounts) => {
const identities = getIdentities()
res.result = accounts
.sort((firstAddress, secondAddress) => {
if (!identities[firstAddress]) {
throw new Error(`Missing identity for address ${firstAddress}`)
} else if (!identities[secondAddress]) {
throw new Error(`Missing identity for address ${secondAddress}`)
} else if (identities[firstAddress].lastSelected === identities[secondAddress].lastSelected) {
return 0
} else if (identities[firstAddress].lastSelected === undefined) {
return 1
} else if (identities[secondAddress].lastSelected === undefined) {
return -1
}
return identities[secondAddress].lastSelected - identities[firstAddress].lastSelected
})
end()
})
.catch(
(err) => {
res.error = err
end(err)
}
)
},
},
}
}