Add nickname rendering for recipient address

feature/default_network_editable
Dan Finlay 9 years ago
parent 306035f575
commit e8efe84320
  1. 44
      test/unit/nameForAccount_test.js
  2. 2
      ui/app/components/pending-tx-details.js
  3. 22
      ui/lib/contract-namer.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)
})
})
})

@ -177,7 +177,7 @@ PTXP.miniAccountPanelForRecipient = function () {
style: { style: {
fontFamily: 'Montserrat Bold, Montserrat, sans-serif', fontFamily: 'Montserrat Bold, Montserrat, sans-serif',
}, },
}, nameForAddress(txParams.to)), }, nameForAddress(txParams.to, props.identities)),
h('span.font-small', { h('span.font-small', {
style: { style: {
fontFamily: 'Montserrat Light, Montserrat, sans-serif', fontFamily: 'Montserrat Light, Montserrat, sans-serif',

@ -5,13 +5,27 @@
* otherwise returns null. * otherwise returns null.
*/ */
// Nickname keys must be stored in lower case.
const nicknames = {} const nicknames = {}
module.exports = function(address) { module.exports = function(addr, identities = {}) {
if (address in nicknames) { const address = addr.toLowerCase()
return nicknames[address] 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
} }

Loading…
Cancel
Save