commit
86b7cc6637
After Width: | Height: | Size: 2.2 KiB |
@ -0,0 +1,84 @@ |
|||||||
|
{ |
||||||
|
"metamask": { |
||||||
|
"isInitialized": true, |
||||||
|
"isUnlocked": true, |
||||||
|
"currentDomain": "example.com", |
||||||
|
"rpcTarget": "https://rawtestrpc.metamask.io/", |
||||||
|
"identities": { |
||||||
|
"0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc": { |
||||||
|
"name": "Wallet 1", |
||||||
|
"address": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc", |
||||||
|
"mayBeFauceting": false |
||||||
|
}, |
||||||
|
"0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b": { |
||||||
|
"name": "Wallet 2", |
||||||
|
"address": "0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b", |
||||||
|
"mayBeFauceting": false |
||||||
|
}, |
||||||
|
"0xeb9e64b93097bc15f01f13eae97015c57ab64823": { |
||||||
|
"name": "Wallet 3", |
||||||
|
"address": "0xeb9e64b93097bc15f01f13eae97015c57ab64823", |
||||||
|
"mayBeFauceting": false |
||||||
|
}, |
||||||
|
"0x704107d04affddd9b66ab9de3dd7b095852e9b69": { |
||||||
|
"name": "Wallet 4", |
||||||
|
"address": "0x704107d04affddd9b66ab9de3dd7b095852e9b69", |
||||||
|
"mayBeFauceting": false |
||||||
|
} |
||||||
|
}, |
||||||
|
"unconfTxs": {}, |
||||||
|
"accounts": { |
||||||
|
"0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc": { |
||||||
|
"code": "0x", |
||||||
|
"balance": "0x01", |
||||||
|
"nonce": "0x0", |
||||||
|
"address": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc" |
||||||
|
}, |
||||||
|
"0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b": { |
||||||
|
"code": "0x", |
||||||
|
"nonce": "0x0", |
||||||
|
"balance": "0x01", |
||||||
|
"address": "0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b" |
||||||
|
}, |
||||||
|
"0xeb9e64b93097bc15f01f13eae97015c57ab64823": { |
||||||
|
"code": "0x", |
||||||
|
"nonce": "0x0", |
||||||
|
"balance": "0x01", |
||||||
|
"address": "0xeb9e64b93097bc15f01f13eae97015c57ab64823" |
||||||
|
}, |
||||||
|
"0x704107d04affddd9b66ab9de3dd7b095852e9b69": { |
||||||
|
"code": "0x", |
||||||
|
"balance": "0x0", |
||||||
|
"nonce": "0x0", |
||||||
|
"address": "0x704107d04affddd9b66ab9de3dd7b095852e9b69" |
||||||
|
} |
||||||
|
}, |
||||||
|
"transactions": [], |
||||||
|
"selectedAddress": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc", |
||||||
|
"network": "2", |
||||||
|
"seedWords": null, |
||||||
|
"isConfirmed": true, |
||||||
|
"unconfMsgs": {}, |
||||||
|
"messages": [], |
||||||
|
"provider": { |
||||||
|
"type": "testnet" |
||||||
|
}, |
||||||
|
"selectedAccount": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc" |
||||||
|
}, |
||||||
|
"appState": { |
||||||
|
"menuOpen": false, |
||||||
|
"currentView": { |
||||||
|
"name": "accountDetail", |
||||||
|
"detailView": null, |
||||||
|
"context": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc" |
||||||
|
}, |
||||||
|
"accountDetail": { |
||||||
|
"subview": "transactions" |
||||||
|
}, |
||||||
|
"currentDomain": "127.0.0.1:9966", |
||||||
|
"transForward": true, |
||||||
|
"isLoading": false, |
||||||
|
"warning": null |
||||||
|
}, |
||||||
|
"identities": {} |
||||||
|
} |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -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) |
||||||
|
}) |
||||||
|
|
||||||
|
}) |
||||||
|
}) |
@ -0,0 +1,74 @@ |
|||||||
|
const inherits = require('util').inherits |
||||||
|
const Component = require('react').Component |
||||||
|
const h = require('react-hyperscript') |
||||||
|
const Identicon = require('./identicon') |
||||||
|
|
||||||
|
module.exports = AccountPanel |
||||||
|
|
||||||
|
|
||||||
|
inherits(AccountPanel, Component) |
||||||
|
function AccountPanel () { |
||||||
|
Component.call(this) |
||||||
|
} |
||||||
|
|
||||||
|
AccountPanel.prototype.render = function () { |
||||||
|
var props = this.props |
||||||
|
var picOrder = props.picOrder || 'left' |
||||||
|
const { imageSeed } = props |
||||||
|
|
||||||
|
return ( |
||||||
|
|
||||||
|
h('.identity-panel.flex-row.flex-left', { |
||||||
|
style: { |
||||||
|
cursor: props.onClick ? 'pointer' : undefined, |
||||||
|
}, |
||||||
|
onClick: props.onClick, |
||||||
|
}, [ |
||||||
|
|
||||||
|
this.genIcon(imageSeed, picOrder), |
||||||
|
|
||||||
|
h('div.flex-column.flex-justify-center', { |
||||||
|
style: { |
||||||
|
lineHeight: '15px', |
||||||
|
order: 2, |
||||||
|
display: 'flex', |
||||||
|
alignItems: picOrder === 'left' ? 'flex-begin' : 'flex-end', |
||||||
|
}, |
||||||
|
}, this.props.children), |
||||||
|
]) |
||||||
|
) |
||||||
|
} |
||||||
|
|
||||||
|
AccountPanel.prototype.genIcon = function (seed, picOrder) { |
||||||
|
const props = this.props |
||||||
|
|
||||||
|
// When there is no seed value, this is a contract creation.
|
||||||
|
// We then show the contract icon.
|
||||||
|
if (!seed) { |
||||||
|
return h('.identicon-wrapper.flex-column.select-none', { |
||||||
|
style: { |
||||||
|
order: picOrder === 'left' ? 1 : 3, |
||||||
|
}, |
||||||
|
}, [ |
||||||
|
h('i.fa.fa-file-text-o.fa-lg', { |
||||||
|
style: { |
||||||
|
fontSize: '42px', |
||||||
|
transform: 'translate(0px, -16px)', |
||||||
|
}, |
||||||
|
}), |
||||||
|
]) |
||||||
|
} |
||||||
|
|
||||||
|
// If there was a seed, we return an identicon for that address.
|
||||||
|
return h('.identicon-wrapper.flex-column.select-none', { |
||||||
|
style: { |
||||||
|
order: picOrder === 'left' ? 1 : 3, |
||||||
|
}, |
||||||
|
}, [ |
||||||
|
h(Identicon, { |
||||||
|
address: seed, |
||||||
|
imageify: props.imageifyIdenticons, |
||||||
|
}), |
||||||
|
]) |
||||||
|
} |
||||||
|
|
@ -0,0 +1,31 @@ |
|||||||
|
/* CONTRACT NAMER |
||||||
|
* |
||||||
|
* Takes an address, |
||||||
|
* Returns a nicname if we have one stored, |
||||||
|
* otherwise returns null. |
||||||
|
*/ |
||||||
|
|
||||||
|
// Nickname keys must be stored in lower case.
|
||||||
|
const nicknames = {} |
||||||
|
|
||||||
|
module.exports = function(addr, identities = {}) { |
||||||
|
|
||||||
|
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 |
||||||
|
} |
||||||
|
|
||||||
|
function addrFromHash(addr, hash) { |
||||||
|
const address = addr.toLowerCase() |
||||||
|
return hash[address] || null |
||||||
|
} |
Loading…
Reference in new issue