Fix/refactor contribution wrapper
This commit is contained in:
parent
19556349f6
commit
181e6f3c23
@ -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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user