1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 18:41:38 +01:00
metamask-extension/ui/lib/contract-namer.js

30 lines
663 B
JavaScript
Raw Normal View History

2016-07-07 02:58:46 +02:00
/* CONTRACT NAMER
*
* Takes an address,
* Returns a nicname if we have one stored,
* otherwise returns null.
*/
// Nickname keys must be stored in lower case.
2016-07-07 02:58:46 +02:00
const nicknames = {}
2016-11-11 19:26:12 +01:00
module.exports = function (addr, identities = {}) {
const address = addr.toLowerCase()
const ids = hashFromIdentities(identities)
return addrFromHash(address, ids) || addrFromHash(address, nicknames)
}
2016-11-11 19:26:12 +01:00
function hashFromIdentities (identities) {
const result = {}
2016-11-11 19:26:12 +01:00
for (const key in identities) {
result[key] = identities[key].name
2016-07-07 02:58:46 +02:00
}
return result
}
2016-07-07 02:58:46 +02:00
2016-11-11 19:26:12 +01:00
function addrFromHash (addr, hash) {
const address = addr.toLowerCase()
return hash[address] || null
2016-07-07 02:58:46 +02:00
}