Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ module.exports = {
'^.+\\.tsx?$': 'ts-jest'
},
// testRegex: 'spec\\.(ts|tsx)$' // TODO Skip api/ tests for now, as it's still WIP
testRegex: `packages/(abi|electron|light\.js|light\.js-react)/.*spec\\.(ts|tsx)$`
testRegex: `packages/(abi|contracts|electron|light\.js|light\.js-react)/.*spec\\.(ts|tsx)$`
};
20 changes: 11 additions & 9 deletions packages/contracts/src/badgereg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,29 @@ export default class BadgeReg {
public certifiers: Metadata[] = [];
public contracts: {
[key: string]: Contract;
};
} = {};
private _registry: Registry;

constructor(api: Api, registry: Registry) {
constructor (api: Api, registry: Registry) {
this._api = api;
this._registry = registry;

registry.getContract('badgereg');
}

getContract() {
getContract () {
return this._registry.getContract('badgereg');
}

certifierCount() {
certifierCount () {
return this.getContract().then((badgeReg: Contract) => {
return badgeReg.instance.badgeCount
.call({}, [])
.then((count: BigNumber) => count.valueOf());
});
}

fetchCertifier(id: number) {
fetchCertifier (id: number) {
if (this.certifiers[id]) {
return Promise.resolve(this.certifiers[id]);
}
Expand All @@ -75,7 +75,7 @@ export default class BadgeReg {
});
}

fetchCertifierByName(name: string) {
fetchCertifierByName (name: string) {
return this.getContract()
.then((badgeReg: Contract) => {
return badgeReg.instance.fromName.call({}, [name]);
Expand All @@ -94,7 +94,7 @@ export default class BadgeReg {
});
}

fetchMeta(id: number) {
fetchMeta (id: number) {
return this.getContract()
.then((badgeReg: Contract) => {
return Promise.all([
Expand All @@ -106,15 +106,17 @@ export default class BadgeReg {
title = bytesToHex(title).replace(/(00)+$/, '');
title = title === ZERO32 ? null : hexToAscii(title);

let resultIcon: string | null = icon;

if (bytesToHex(icon) === ZERO32) {
icon = null;
resultIcon = null;
}

return { title, icon };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you mean to return { title, icon: resultIcon } here?

});
}

checkIfCertified(certifier: string, address: string) {
checkIfCertified (certifier: string, address: string) {
if (!this.contracts[certifier]) {
this.contracts[certifier] = this._api.newContract(ABI, certifier);
}
Expand Down
18 changes: 9 additions & 9 deletions packages/contracts/src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import TokenReg from './tokenreg';
import GithubHint from './githubhint';
import BadgeReg from './badgereg';

let instance: Contracts = null;
let instance: Contracts | undefined;

export default class Contracts {
private _api: Api;
Expand All @@ -22,7 +22,7 @@ export default class Contracts {
private _signaturereg: SignatureReg;
private _tokenreg: TokenReg;

constructor(api: Api) {
constructor (api: Api) {
instance = this;

this._api = api;
Expand All @@ -34,31 +34,31 @@ export default class Contracts {
this._badgeReg = new BadgeReg(api, this._registry);
}

get registry() {
get registry () {
return this._registry;
}

get badgeReg() {
get badgeReg () {
return this._badgeReg;
}

get dappReg() {
get dappReg () {
return this._dappreg;
}

get signatureReg() {
get signatureReg () {
return this._signaturereg;
}

get tokenReg() {
get tokenReg () {
return this._tokenreg;
}

get githubHint() {
get githubHint () {
return this._githubhint;
}

static get(api: Api) {
static get (api: Api) {
if (!instance) {
instance = new Contracts(api);
}
Expand Down
20 changes: 10 additions & 10 deletions packages/contracts/src/dappreg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,54 @@ export default class DappReg {
private _api: Api;
private _registry: Registry;

constructor(api: Api, registry: Registry) {
constructor (api: Api, registry: Registry) {
this._api = api;
this._registry = registry;

this.getInstance();
}

getContract() {
getContract () {
return this._registry.getContract('dappreg');
}

getInstance() {
getInstance () {
return this.getContract().then((contract: Contract) => contract.instance);
}

count() {
count () {
return this.getInstance().then((instance: ContractInstance) => {
return instance.count.call();
});
}

at(index: number) {
at (index: number) {
return this.getInstance().then((instance: ContractInstance) => {
return instance.at.call({}, [index]);
});
}

get(id: string) {
get (id: string) {
return this.getInstance().then((instance: ContractInstance) => {
return instance.get.call({}, [id]);
});
}

meta(id: string, key: string) {
meta (id: string, key: string) {
return this.getInstance().then((instance: ContractInstance) => {
return instance.meta.call({}, [id, key]);
});
}

getImage(id: string) {
getImage (id: string) {
return this.meta(id, 'IMG');
}

getContent(id: string) {
getContent (id: string) {
return this.meta(id, 'CONTENT');
}

getManifest(id: string) {
getManifest (id: string) {
return this.meta(id, 'MANIFEST');
}
}
2 changes: 1 addition & 1 deletion packages/contracts/src/githubhint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let githubHint: GithubHint;
let instance: ContractInstance;
let registry: Registry;

function create() {
function create () {
instance = {
__id: 'testInstance',
entries: {
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts/src/githubhint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ export default class GithubHint {
private _instance: ContractInstance = null;
private _registry: Registry;

constructor(api: Api, registry: Registry) {
constructor (api: Api, registry: Registry) {
this._api = api;
this._registry = registry;

this.getInstance();
}

getContract() {
getContract () {
return this._registry.getContract('githubhint');
}

getInstance() {
getInstance () {
if (this._instance) {
return Promise.resolve(this._instance);
}
Expand All @@ -33,7 +33,7 @@ export default class GithubHint {
});
}

getEntry(entryId: string) {
getEntry (entryId: string) {
return this.getInstance().then((instance: ContractInstance) => {
return instance.entries.call({}, [entryId]);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/registry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let api: Api;
let instance: ContractInstance;
let registry: Registry;

function create() {
function create () {
instance = {
__id: 'testInstance',
get: {
Expand Down
20 changes: 10 additions & 10 deletions packages/contracts/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as abis from './abi';
import { Api, Contract, ContractInstance } from './types';

interface QueueItem {
resolve(...args: any[]): void;
resolve (...args: any[]): void;
}

const REGISTRY_V1_HASHES = [
Expand All @@ -26,15 +26,15 @@ export default class Registry {
[key: string]: Promise<Contract>;
} = {};
private _queue: QueueItem[] = [];
private _registryContract: Contract = null;
private _registryContract: Contract | null = null;

constructor(api: Api) {
constructor (api: Api) {
this._api = api;

this.getInstance();
}

getInstance() {
getInstance () {
if (this._instance) {
return Promise.resolve(this._instance);
}
Expand All @@ -61,7 +61,7 @@ export default class Registry {
});
}

getContract(_name: string) {
getContract (_name: string) {
const name = _name.toLowerCase();

if (this._contracts[name]) {
Expand All @@ -86,13 +86,13 @@ export default class Registry {
return promise;
}

getContractInstance(_name: string) {
getContractInstance (_name: string) {
return this.getContract(_name).then(
(contract: Contract) => contract.instance
);
}

fetchContract() {
fetchContract () {
if (this._registryContract) {
return Promise.resolve(this._registryContract);
}
Expand Down Expand Up @@ -133,14 +133,14 @@ export default class Registry {
});
}

_createGetParams(_name: string, key: string) {
_createGetParams (_name: string, key: string) {
const name = _name.toLowerCase();
const sha3 = this._api.util.sha3.text(name);

return [sha3, key];
}

lookupAddress(name: string) {
lookupAddress (name: string) {
return this.getInstance()
.then((instance: ContractInstance) => {
return instance.getAddress.call({}, this._createGetParams(name, 'A'));
Expand All @@ -151,7 +151,7 @@ export default class Registry {
});
}

lookupMeta(name: string, key: string) {
lookupMeta (name: string, key: string) {
return this.getInstance().then((instance: ContractInstance) => {
return instance.get.call({}, this._createGetParams(name, key));
});
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/src/signaturereg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ export default class SignatureReg {
private _api: Api;
private _registry: Registry;

constructor(api: Api, registry: Registry) {
constructor (api: Api, registry: Registry) {
this._api = api;
this._registry = registry;

this.getInstance();
}

getInstance() {
getInstance () {
return this._registry.getContractInstance('signaturereg');
}

lookup(signature: string) {
lookup (signature: string) {
return this.getInstance().then((instance: ContractInstance) => {
return instance.entries.call({}, [signature]);
});
Expand Down
10 changes: 5 additions & 5 deletions packages/contracts/src/tokenreg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ export default class TokenReg {
private _api: Api;
private _registry: Registry;

constructor(api: Api, registry: Registry) {
constructor (api: Api, registry: Registry) {
this._api = api;
this._registry = registry;

this.getInstance();
}

getContract() {
getContract () {
return this._registry.getContract('tokenreg');
}

getInstance() {
getInstance () {
return this.getContract().then((contract: Contract) => contract.instance);
}

tokenCount() {
tokenCount () {
return this.getInstance().then((instance: ContractInstance) => {
return instance.tokenCount.call();
});
}

token(index: number) {
token (index: number) {
return this.getInstance().then((instance: ContractInstance) => {
return instance.token.call({}, [index]);
});
Expand Down