aboutsummaryrefslogtreecommitdiffstats
path: root/ui/classic/lib/contract-namer.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-07-04 06:39:25 +0800
committerDan Finlay <dan@danfinlay.com>2017-07-04 06:39:25 +0800
commit5eb3d5d485b17b98b19443d8def2f03dec9b38ef (patch)
tree1b814f7706a9eb559824624b87937631ac3ca505 /ui/classic/lib/contract-namer.js
parentd0d01552da8d0a6f58fb7c5be16947175ec90267 (diff)
downloadtangerine-wallet-browser-5eb3d5d485b17b98b19443d8def2f03dec9b38ef.tar
tangerine-wallet-browser-5eb3d5d485b17b98b19443d8def2f03dec9b38ef.tar.gz
tangerine-wallet-browser-5eb3d5d485b17b98b19443d8def2f03dec9b38ef.tar.bz2
tangerine-wallet-browser-5eb3d5d485b17b98b19443d8def2f03dec9b38ef.tar.lz
tangerine-wallet-browser-5eb3d5d485b17b98b19443d8def2f03dec9b38ef.tar.xz
tangerine-wallet-browser-5eb3d5d485b17b98b19443d8def2f03dec9b38ef.tar.zst
tangerine-wallet-browser-5eb3d5d485b17b98b19443d8def2f03dec9b38ef.zip
Make folder for responsive UI
Diffstat (limited to 'ui/classic/lib/contract-namer.js')
-rw-r--r--ui/classic/lib/contract-namer.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/ui/classic/lib/contract-namer.js b/ui/classic/lib/contract-namer.js
new file mode 100644
index 000000000..f05e770cc
--- /dev/null
+++ b/ui/classic/lib/contract-namer.js
@@ -0,0 +1,33 @@
+/* CONTRACT NAMER
+ *
+ * Takes an address,
+ * Returns a nicname if we have one stored,
+ * otherwise returns null.
+ */
+
+const contractMap = require('eth-contract-metadata')
+const ethUtil = require('ethereumjs-util')
+
+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 ids = hashFromIdentities(identities)
+ return addrFromHash(address, ids)
+}
+
+function hashFromIdentities (identities) {
+ const result = {}
+ for (const key in identities) {
+ result[key] = identities[key].name
+ }
+ return result
+}
+
+function addrFromHash (addr, hash) {
+ const address = addr.toLowerCase()
+ return hash[address] || null
+}