Merge pull request #1507 from MetaMask/AddContractIconMap

Add contract name map
feature/default_network_editable
kumavis 8 years ago committed by GitHub
commit 5e9274d4d5
  1. 1
      CHANGELOG.md
  2. 2
      package.json
  3. 12
      ui/lib/contract-namer.js
  4. 7
      ui/lib/icon-factory.js

@ -9,6 +9,7 @@
- Now enforce 95% of block's gasLimit to protect users. - Now enforce 95% of block's gasLimit to protect users.
- Removing provider-engine from the inpage provider. This fixes some error handling inconsistencies introduced in 3.7.0. - Removing provider-engine from the inpage provider. This fixes some error handling inconsistencies introduced in 3.7.0.
- Some contracts will now display logos instead of jazzicons. - Some contracts will now display logos instead of jazzicons.
- Some contracts will now have names displayed in the confirmation view.
## 3.7.0 2017-5-23 ## 3.7.0 2017-5-23

@ -62,11 +62,11 @@
"end-of-stream": "^1.1.0", "end-of-stream": "^1.1.0",
"ensnare": "^1.0.0", "ensnare": "^1.0.0",
"eth-bin-to-ops": "^1.0.1", "eth-bin-to-ops": "^1.0.1",
"eth-contract-metadata": "^1.0.0",
"eth-hd-keyring": "^1.1.1", "eth-hd-keyring": "^1.1.1",
"eth-query": "^2.1.1", "eth-query": "^2.1.1",
"eth-sig-util": "^1.1.1", "eth-sig-util": "^1.1.1",
"eth-simple-keyring": "^1.1.1", "eth-simple-keyring": "^1.1.1",
"ethereum-contract-icons": "^1.0.0",
"ethereumjs-tx": "^1.3.0", "ethereumjs-tx": "^1.3.0",
"ethereumjs-util": "ethereumjs/ethereumjs-util#ac5d0908536b447083ea422b435da27f26615de9", "ethereumjs-util": "ethereumjs/ethereumjs-util#ac5d0908536b447083ea422b435da27f26615de9",
"ethereumjs-wallet": "^0.6.0", "ethereumjs-wallet": "^0.6.0",

@ -5,14 +5,18 @@
* otherwise returns null. * otherwise returns null.
*/ */
// Nickname keys must be stored in lower case. const contractMap = require('eth-contract-metadata')
const nicknames = {} const ethUtil = require('ethereumjs-util')
module.exports = function (addr, identities = {}) { module.exports = function (addr, identities = {}) {
const checksummed = ethUtil.toChecksumAddress(addr)
if (contractMap[checksummed] && contractMap[checksummed].name) {
return contractMap[checksummed].name
}
const address = addr.toLowerCase() const address = addr.toLowerCase()
const ids = hashFromIdentities(identities) const ids = hashFromIdentities(identities)
return addrFromHash(address, ids)
return addrFromHash(address, ids) || addrFromHash(address, nicknames)
} }
function hashFromIdentities (identities) { function hashFromIdentities (identities) {

@ -1,7 +1,7 @@
var iconFactory var iconFactory
const isValidAddress = require('ethereumjs-util').isValidAddress const isValidAddress = require('ethereumjs-util').isValidAddress
const toChecksumAddress = require('ethereumjs-util').toChecksumAddress const toChecksumAddress = require('ethereumjs-util').toChecksumAddress
const iconMap = require('ethereum-contract-icons') const contractMap = require('eth-contract-metadata')
module.exports = function (jazzicon) { module.exports = function (jazzicon) {
if (!iconFactory) { if (!iconFactory) {
@ -43,11 +43,12 @@ IconFactory.prototype.generateNewIdenticon = function (address, diameter) {
// util // util
function iconExistsFor (address) { function iconExistsFor (address) {
return (address in iconMap) && isValidAddress(address) return (contractMap.address) && isValidAddress(address) && (contractMap[address].logo)
} }
function imageElFor (address) { function imageElFor (address) {
const fileName = iconMap[address] const contract = contractMap[address]
const fileName = contract.logo
const path = `images/contract/${fileName}` const path = `images/contract/${fileName}`
const img = document.createElement('img') const img = document.createElement('img')
img.src = path img.src = path

Loading…
Cancel
Save