mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Add nickname rendering for recipient address
This commit is contained in:
parent
306035f575
commit
e8efe84320
44
test/unit/nameForAccount_test.js
Normal file
44
test/unit/nameForAccount_test.js
Normal file
@ -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: {
|
||||
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',
|
||||
|
@ -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)
|
||||
|
||||
return null
|
||||
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
|
||||
}
|
||||
|
||||
function addrFromHash(addr, hash) {
|
||||
const address = addr.toLowerCase()
|
||||
return hash[address] || null
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user