From 181e6f3c23e98ed93d81bb47048fb36d58a13047 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 4 Apr 2019 22:56:06 +0200 Subject: [PATCH] Fix/refactor contribution wrapper --- lib/contracts/contribution.js | 42 ++++++++++------------------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/lib/contracts/contribution.js b/lib/contracts/contribution.js index cad029d..780049d 100644 --- a/lib/contracts/contribution.js +++ b/lib/contracts/contribution.js @@ -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; }); }