pull out fetchMeta

This commit is contained in:
Jannis R 2016-12-08 12:54:13 +01:00
parent 2d6656fc43
commit 2b34d76b8c
No known key found for this signature in database
GPG Key ID: 0FE83946296A88A5

View File

@ -38,16 +38,9 @@ export default class BadgeReg {
.then((badgeReg) => {
return badgeReg.instance.fromName.call({}, [name])
.then(([ id, address ]) => {
return Promise.all([
badgeReg.instance.meta.call({}, [id, 'TITLE']),
badgeReg.instance.meta.call({}, [id, 'IMG'])
])
.then(([ title, img ]) => {
title = bytesToHex(title);
title = title === ZERO ? null : hex2Ascii(title);
if (bytesToHex(img) === ZERO) img = null;
const data = { address, name, title, icon: img };
return this.fetchMeta(id)
.then(({ title, icon }) => {
const data = { address, name, title, icon };
this.certifiers[name] = data;
return data;
});
@ -55,6 +48,22 @@ export default class BadgeReg {
});
}
fetchMeta (id) {
return this._registry.getContract('badgereg')
.then((badgeReg) => {
return Promise.all([
badgeReg.instance.meta.call({}, [id, 'TITLE']),
badgeReg.instance.meta.call({}, [id, 'IMG'])
]);
})
.then(([ title, icon ]) => {
title = bytesToHex(title);
title = title === ZERO ? null : hex2Ascii(title);
if (bytesToHex(icon) === ZERO) icon = null;
return { title, icon };
});
}
checkIfCertified (certifier, address) {
if (!this.contracts[certifier]) {
this.contracts[certifier] = this._api.newContract(ABI, certifier);