Fix/refactor contribution wrapper
This commit is contained in:
parent
19556349f6
commit
181e6f3c23
@ -1,5 +1,4 @@
|
||||
const ethers = require('ethers');
|
||||
const RSVP = require('rsvp');
|
||||
|
||||
const ContributionSerializer = require('../serializers/contribution');
|
||||
const Base = require('./base');
|
||||
@ -7,14 +6,15 @@ const Base = require('./base');
|
||||
class Contribution extends Base {
|
||||
all() {
|
||||
return this.functions.contributionsCount()
|
||||
.then(count => {
|
||||
.then(async (count) => {
|
||||
let contributions = [];
|
||||
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
@ -30,38 +30,20 @@ class Contribution extends Base {
|
||||
return this.functions.getContributorAddressById(contributorId)
|
||||
.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) {
|
||||
return this.functions.balanceOf(address)
|
||||
.then((balance) => {
|
||||
count = balance.toNumber();
|
||||
.then(async (balance) => {
|
||||
const count = balance.toNumber();
|
||||
const contributions = [];
|
||||
|
||||
let contributions = [];
|
||||
|
||||
for (let index = 0; index <= count; index++) {
|
||||
this.functions.tokenOfOwnerByIndex(address, index)
|
||||
.then((id) => {
|
||||
contributions.push(this.getById(id));
|
||||
});
|
||||
for (let index = 0; index < count; index++) {
|
||||
const id = await this.functions.tokenOfOwnerByIndex(address, index);
|
||||
const contribution = await this.getById(id);
|
||||
contributions.push(contribution);
|
||||
}
|
||||
|
||||
return RSVP.all(contributions);
|
||||
return contributions;
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user