aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-07-08 04:21:45 +0800
committerDan Finlay <dan@danfinlay.com>2016-07-08 04:21:45 +0800
commite8efe84320ea791535b40e69a64525f7fdb3ea8a (patch)
treee5ac81f816c18871bbe4b14b546d15a924f904f2
parent306035f57508cafd07c27407896a5ac32dc1b435 (diff)
downloadtangerine-wallet-browser-e8efe84320ea791535b40e69a64525f7fdb3ea8a.tar.gz
tangerine-wallet-browser-e8efe84320ea791535b40e69a64525f7fdb3ea8a.tar.zst
tangerine-wallet-browser-e8efe84320ea791535b40e69a64525f7fdb3ea8a.zip
Add nickname rendering for recipient address
-rw-r--r--test/unit/nameForAccount_test.js44
-rw-r--r--ui/app/components/pending-tx-details.js2
-rw-r--r--ui/lib/contract-namer.js22
3 files changed, 63 insertions, 5 deletions
diff --git a/test/unit/nameForAccount_test.js b/test/unit/nameForAccount_test.js
new file mode 100644
index 000000000..6839d40f8
--- /dev/null
+++ b/test/unit/nameForAccount_test.js
@@ -0,0 +1,44 @@
+var assert = require('assert')
+var sinon = require('sinon')
+
+var path = require('path')
+var contractNamer = require(path.join(__dirname, '..', '..', 'ui', 'lib', 'contract-namer.js'))
+
+describe('contractNamer', function() {
+
+ beforeEach(function() {
+ this.sinon = sinon.sandbox.create()
+ })
+
+ afterEach(function() {
+ this.sinon.restore()
+ })
+
+ describe('naming a contract', function() {
+
+ it('should return nothing for an unknown random account', function() {
+ const input = '0x2386F26FC10000'
+ const output = contractNamer(input)
+ assert.deepEqual(output, null)
+ })
+
+ it('should accept identities as an optional second parameter', function() {
+ const input = '0x2386F26FC10000'.toLowerCase()
+ const expected = 'bar'
+ const identities = {}
+ identities[input] = { name: expected }
+ const output = contractNamer(input, identities)
+ assert.deepEqual(output, expected)
+ })
+
+ it('should check for identities case insensitively', function() {
+ const input = '0x2386F26FC10000'.toLowerCase()
+ const expected = 'bar'
+ const identities = {}
+ identities[input] = { name: expected }
+ const output = contractNamer(input.toUpperCase(), identities)
+ assert.deepEqual(output, expected)
+ })
+
+ })
+})
diff --git a/ui/app/components/pending-tx-details.js b/ui/app/components/pending-tx-details.js
index e0b629e89..b2c16e772 100644
--- a/ui/app/components/pending-tx-details.js
+++ b/ui/app/components/pending-tx-details.js
@@ -177,7 +177,7 @@ PTXP.miniAccountPanelForRecipient = function () {
style: {
fontFamily: 'Montserrat Bold, Montserrat, sans-serif',
},
- }, nameForAddress(txParams.to)),
+ }, nameForAddress(txParams.to, props.identities)),
h('span.font-small', {
style: {
fontFamily: 'Montserrat Light, Montserrat, sans-serif',
diff --git a/ui/lib/contract-namer.js b/ui/lib/contract-namer.js
index eae066ad5..62c7933e8 100644
--- a/ui/lib/contract-namer.js
+++ b/ui/lib/contract-namer.js
@@ -5,13 +5,27 @@
* otherwise returns null.
*/
+// Nickname keys must be stored in lower case.
const nicknames = {}
-module.exports = function(address) {
+module.exports = function(addr, identities = {}) {
- if (address in nicknames) {
- return nicknames[address]
+ const address = addr.toLowerCase()
+ const ids = hashFromIdentities(identities)
+
+ console.dir({ addr, ids })
+ return addrFromHash(address, ids) || addrFromHash(address, nicknames)
+}
+
+function hashFromIdentities(identities) {
+ const result = {}
+ for (let key in identities) {
+ result[key] = identities[key].name
}
+ return result
+}
- return null
+function addrFromHash(addr, hash) {
+ const address = addr.toLowerCase()
+ return hash[address] || null
}