aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-05-26 15:19:24 +0800
committerDan Finlay <dan@danfinlay.com>2017-05-26 15:43:14 +0800
commitd8c94fca75ca2aed11387c0b1d4c6064bead447e (patch)
tree55469f52c02d8e71719c6fc289b8d15671902eac /ui
parent8f9a230d8d2c8351cd325bddf3c2ca04f06c9619 (diff)
downloadtangerine-wallet-browser-d8c94fca75ca2aed11387c0b1d4c6064bead447e.tar
tangerine-wallet-browser-d8c94fca75ca2aed11387c0b1d4c6064bead447e.tar.gz
tangerine-wallet-browser-d8c94fca75ca2aed11387c0b1d4c6064bead447e.tar.bz2
tangerine-wallet-browser-d8c94fca75ca2aed11387c0b1d4c6064bead447e.tar.lz
tangerine-wallet-browser-d8c94fca75ca2aed11387c0b1d4c6064bead447e.tar.xz
tangerine-wallet-browser-d8c94fca75ca2aed11387c0b1d4c6064bead447e.tar.zst
tangerine-wallet-browser-d8c94fca75ca2aed11387c0b1d4c6064bead447e.zip
Add address image map to icon factory
Deriving from the new address image map repository I've added here: https://github.com/MetaMask/ethereum-contract-icons With this PR, images for addresses added to that repository will be shown instead of jazzicons in MetaMask.
Diffstat (limited to 'ui')
-rw-r--r--ui/lib/icon-factory.js39
1 files changed, 21 insertions, 18 deletions
diff --git a/ui/lib/icon-factory.js b/ui/lib/icon-factory.js
index 82cc839d6..4aed9109b 100644
--- a/ui/lib/icon-factory.js
+++ b/ui/lib/icon-factory.js
@@ -1,4 +1,7 @@
var iconFactory
+const isValidAddress = require('ethereumjs-util').isValidAddress
+const toChecksumAddress = require('ethereumjs-util').toChecksumAddress
+const iconMap = require('ethereum-contract-icons')
module.exports = function (jazzicon) {
if (!iconFactory) {
@@ -12,22 +15,12 @@ function IconFactory (jazzicon) {
this.cache = {}
}
-IconFactory.prototype.iconForAddress = function (address, diameter, imageify) {
- if (imageify) {
- return this.generateIdenticonImg(address, diameter)
- } else {
- return this.generateIdenticonSvg(address, diameter)
+IconFactory.prototype.iconForAddress = function (address, diameter) {
+ const addr = toChecksumAddress(address)
+ if (iconExistsFor(addr)) {
+ return imageElFor(addr)
}
-}
-
-// returns img dom element
-IconFactory.prototype.generateIdenticonImg = function (address, diameter) {
- var identicon = this.generateIdenticonSvg(address, diameter)
- var identiconSrc = identicon.innerHTML
- var dataUri = toDataUri(identiconSrc)
- var img = document.createElement('img')
- img.src = dataUri
- return img
+ return this.generateIdenticonSvg(address, diameter)
}
// returns svg dom element
@@ -49,12 +42,22 @@ IconFactory.prototype.generateNewIdenticon = function (address, diameter) {
// util
+function iconExistsFor (address) {
+ return (address in iconMap) && isValidAddress(address)
+}
+
+function imageElFor (address) {
+ const fileName = iconMap[address]
+ const path = `images/contract/${fileName}`
+ const img = document.createElement('img')
+ img.src = path
+ img.style.width = '100%'
+ return img
+}
+
function jsNumberForAddress (address) {
var addr = address.slice(2, 10)
var seed = parseInt(addr, 16)
return seed
}
-function toDataUri (identiconSrc) {
- return 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(identiconSrc)
-}