diff options
-rw-r--r-- | test/unit/nameForAccount_test.js | 44 | ||||
-rw-r--r-- | ui/app/components/pending-tx-details.js | 2 | ||||
-rw-r--r-- | ui/lib/contract-namer.js | 22 |
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 } |