aboutsummaryrefslogtreecommitdiffstats
path: root/old-ui/lib/contract-namer.js
diff options
context:
space:
mode:
authorLe Quoc Viet <vietlq85@gmail.com>2018-03-15 16:11:42 +0800
committerGitHub <noreply@github.com>2018-03-15 16:11:42 +0800
commit04079455e36e48433cf8055c8f1f79e1e7e18298 (patch)
treed7de2a6603b67b56abacf09bee4d2bbbfe886b8f /old-ui/lib/contract-namer.js
parent5bdee96e73f65a0b369277e9c56b0afe5159e65b (diff)
parente2efc91aee64072c408ab509219dcbfb389c7609 (diff)
downloadtangerine-wallet-browser-04079455e36e48433cf8055c8f1f79e1e7e18298.tar.gz
tangerine-wallet-browser-04079455e36e48433cf8055c8f1f79e1e7e18298.tar.zst
tangerine-wallet-browser-04079455e36e48433cf8055c8f1f79e1e7e18298.zip
Merge pull request #1 from MetaMask/master
Merge from the source
Diffstat (limited to 'old-ui/lib/contract-namer.js')
-rw-r--r--old-ui/lib/contract-namer.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/old-ui/lib/contract-namer.js b/old-ui/lib/contract-namer.js
new file mode 100644
index 000000000..f05e770cc
--- /dev/null
+++ b/old-ui/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
+}