Skip to content

Commit

Permalink
Refactored to be generic contract metadata map
Browse files Browse the repository at this point in the history
  • Loading branch information
danfinlay committed May 26, 2017
1 parent a31e457 commit 4008dc6
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Ethereum Contract Icons [![CircleCI](https://circleci.com/gh/MetaMask/ethereum-contract-icons.svg?style=svg)](https://circleci.com/gh/MetaMask/ethereum-contract-icons)
# Ethereum Contract Metadata [![CircleCI](https://circleci.com/gh/MetaMask/ethereum-contract-icons.svg?style=svg)](https://circleci.com/gh/MetaMask/ethereum-contract-icons)

A mapping of checksummed ethereum addresses to images of those addresses' logos.
A mapping of checksummed ethereum addresses to metadata, like names, and images of those addresses' logos.

All address keys follow the [EIP 55 address checksum format](https://github.com/ethereum/EIPs/issues/55).

Submit PRs to add valid logos, and obviously valid logos will be merged.

## Usage

You can install from npm with `npm install ethereum-contract-icons` and use it in your code like this:
You can install from npm with `npm install eth-contract-metadata` and use it in your code like this:

```javascript
const iconMap = require('ethereum-contract-icons')
Expand All @@ -28,10 +28,19 @@ function imageElFor (address) {

1. Fork this repository.
2. Add your logo image in a web-safe format to the `images` folder.
3. Add an entry to the `icon-map.json` file with the specified address as the key, and the image file's name as the value.
3. Add an entry to the `contract-map.json` file with the specified address as the key, and the image file's name as the value.

Criteria:
- The icon should be small, but high resolution, ideally a vector/svg.
- Do not add your entry to the end of the JSON map, messing with the trailing comma. Your pull request should only be an addition of lines, and any line removals should be deliberate deprecations of those logos.

A sample submission:

```json
{
"0x6090A6e47849629b7245Dfa1Ca21D94cd15878Ef": {
"name": "ENS Registrar",
"logo": "ens.svg"
}
}
```
6 changes: 6 additions & 0 deletions contract-map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"0x6090A6e47849629b7245Dfa1Ca21D94cd15878Ef": {
"logo": "ens.svg",
"name": "ENS Registrar"
}
}
3 changes: 0 additions & 3 deletions icon-map.json

This file was deleted.

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./icon-map.json')
module.exports = require('./contract-map.json')
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ethereum-contract-icons",
"name": "eth-contract-metadata",
"version": "1.0.0",
"description": "A mapping of ethereum contract addresses to broadly accepted icons for those addresses.",
"main": "index.js",
Expand Down
17 changes: 10 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
const test = require('tape')
const iconMap = require('../')
const contractMap = require('../')

const util = require('ethereumjs-util')
const fs = require('fs')
const path = require('path')

test('the object is parsable', function (t) {
t.equal(typeof iconMap, 'object', 'is an object')
t.equal(typeof contractMap, 'object', 'is an object')
t.end()
})

test('the accounts are valid checksum addresses', function (t) {
Object.keys(iconMap).forEach(address => {
Object.keys(contractMap).forEach(address => {
t.ok(util.isValidChecksumAddress(address), `Address should be valid: ${address}`)
})

t.end()
})

test('value should correspond to a web image file', function (t) {
Object.keys(iconMap).forEach(address => {
const fileName = iconMap[address]
t.ok(fs.existsSync(path.join(__dirname, '..', 'images', fileName)), `file exists: ${fileName}`)
test('logos should correspond to an included web image file', function (t) {
Object.keys(contractMap).forEach(address => {
const contract = contractMap[address]
if ('logo' in contract) {
const fileName = contract.logo
t.ok(fs.existsSync(path.join(__dirname, '..', 'images', fileName)), `file exists: ${fileName}`)
}
})

t.end()
Expand Down

0 comments on commit 4008dc6

Please sign in to comment.