Convert contribution owner to ID, use smaller number formats #73

Merged
raucao merged 14 commits from feature/contribution_owner into master 2019-04-04 21:40:17 +00:00
Showing only changes of commit 181e6f3c23 - Show all commits

View File

@ -1,5 +1,4 @@
const ethers = require('ethers'); const ethers = require('ethers');
const RSVP = require('rsvp');
const ContributionSerializer = require('../serializers/contribution'); const ContributionSerializer = require('../serializers/contribution');
const Base = require('./base'); const Base = require('./base');
@ -7,14 +6,15 @@ const Base = require('./base');
class Contribution extends Base { class Contribution extends Base {
all() { all() {
return this.functions.contributionsCount() return this.functions.contributionsCount()
.then(count => { .then(async (count) => {
let contributions = []; let contributions = [];
for (let id = 1; id <= count; id++) { for (let id = 1; id <= count; id++) {
contributions.push(this.getById(id)); const contribution = await this.getById(id)
contributions.push(contribution);
} }
return RSVP.all(contributions); return contributions;
fsmanuel commented 2019-04-04 21:04:18 +00:00 (Migrated from github.com)
Review

❤️

❤️
bumi commented 2019-04-04 21:37:33 +00:00 (Migrated from github.com)
Review

to promise or not to promise? :bumiwonders:

to promise or not to promise? :bumiwonders:
fsmanuel commented 2019-04-04 21:40:36 +00:00 (Migrated from github.com)
Review

If you can wait for it you don't need to promise anything.

If you can wait for it you don't need to promise anything.
}); });
fsmanuel commented 2019-04-04 15:54:23 +00:00 (Migrated from github.com)
Review

It is missing a .

It is missing a `.`
} }
@ -30,38 +30,20 @@ class Contribution extends Base {
return this.functions.getContributorAddressById(contributorId) return this.functions.getContributorAddressById(contributorId)
.then(address => this.getByContributorAddress(address)); .then(address => this.getByContributorAddress(address));
} }
// return this.functions.balanceOf(address)
// then(balance => {
// count = balance.toNumber();
//
// let contributions = [];
//
// for (let index = 0; index <= count; index++) {
// this.functions.tokenOfOwnerByIndex(address, index)
// .then((id) => {
// contributions.push(this.getById(id));
// });
// }
//
// return RSVP.all(contributions);
// });
}
getByContributorAddress(address) { getByContributorAddress(address) {
return this.functions.balanceOf(address) return this.functions.balanceOf(address)
.then((balance) => { .then(async (balance) => {
count = balance.toNumber(); const count = balance.toNumber();
const contributions = [];
let contributions = []; for (let index = 0; index < count; index++) {
const id = await this.functions.tokenOfOwnerByIndex(address, index);
for (let index = 0; index <= count; index++) { const contribution = await this.getById(id);
this.functions.tokenOfOwnerByIndex(address, index) contributions.push(contribution);
.then((id) => {
contributions.push(this.getById(id));
});
} }
return RSVP.all(contributions); return contributions;
}); });
} }