removed await from liquidPledging.js
This commit is contained in:
parent
ebf53f885a
commit
bb14e679f0
|
@ -1,4 +1,3 @@
|
|||
/* eslint-disable no-await-in-loop */
|
||||
const LiquidPledgingAbi = require('../build/LiquidPledging.sol').LiquidPledgingAbi;
|
||||
const LiquidPledgingCode = require('../build/LiquidPledging.sol').LiquidPledgingByteCode;
|
||||
const LiquidPledgingMockAbi = require('../build/LiquidPledgingMock.sol').LiquidPledgingMockAbi;
|
||||
|
@ -11,21 +10,19 @@ module.exports = (test) => {
|
|||
|
||||
const LiquidPledging = generateClass($abi, $byteCode);
|
||||
|
||||
async function $getNote(idNote) {
|
||||
LiquidPledging.prototype.$toDecimal = function (val) { return this.$web3.utils.toDecimal(val); };
|
||||
LiquidPledging.prototype.$toNumber = function (val) { this.$web3.utils.toBN(val); };
|
||||
|
||||
LiquidPledging.prototype.$getNote = function (idNote) {
|
||||
const note = {
|
||||
delegates: [],
|
||||
};
|
||||
const res = await this.getNote(idNote);
|
||||
|
||||
return this.getNote(idNote)
|
||||
.then((res) => {
|
||||
note.amount = this.$toNumber(res.amount);
|
||||
note.owner = res.owner;
|
||||
for (let i = 1; i <= this.$toDecimal(res.nDelegates); i += 1) {
|
||||
const delegate = {};
|
||||
const resd = await this.getNoteDelegate(idNote, i);
|
||||
delegate.id = this.$toDecimal(resd.idDelegate);
|
||||
delegate.addr = resd.addr;
|
||||
delegate.name = resd.name;
|
||||
note.delegates.push(delegate);
|
||||
}
|
||||
|
||||
if (res.proposedProject) {
|
||||
note.proposedProject = this.$toDecimal(res.proposedProject);
|
||||
note.commmitTime = this.$toDecimal(res.commitTime);
|
||||
|
@ -42,14 +39,31 @@ module.exports = (test) => {
|
|||
} else {
|
||||
note.paymentState = 'Unknown';
|
||||
}
|
||||
return note;
|
||||
|
||||
const promises = [];
|
||||
for (let i = 1; i <= this.$toDecimal(res.nDelegates); i += 1) {
|
||||
promises.push(
|
||||
this.getNoteDelegate(idNote, i)
|
||||
.then(r => ({
|
||||
id: this.$toDecimal(r.idDelegate),
|
||||
addr: r.addr,
|
||||
name: r.name,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
LiquidPledging.prototype.$getNote = $getNote;
|
||||
return Promise.all(promises);
|
||||
})
|
||||
.then((delegates) => {
|
||||
note.delegates = delegates;
|
||||
return note;
|
||||
});
|
||||
};
|
||||
|
||||
async function $getManager(idManager) {
|
||||
LiquidPledging.prototype.$getManager = function (idManager) {
|
||||
const manager = {};
|
||||
const res = await this.getNoteManager(idManager);
|
||||
return this.getNoteManager(idManager)
|
||||
.then((res) => {
|
||||
if (res.managerType === '0') {
|
||||
manager.type = 'Donor';
|
||||
} else if (res.managerType === '1') {
|
||||
|
@ -67,30 +81,35 @@ module.exports = (test) => {
|
|||
manager.canceled = res.canceled;
|
||||
}
|
||||
return manager;
|
||||
});
|
||||
};
|
||||
|
||||
LiquidPledging.prototype.$getManager = $getManager;
|
||||
|
||||
async function getState() {
|
||||
const st = {
|
||||
notes: [null],
|
||||
managers: [null],
|
||||
};
|
||||
const nNotes = await this.numberOfNotes();
|
||||
LiquidPledging.prototype.getState = function () {
|
||||
const getNotes = () => this.numberOfNotes()
|
||||
.then((nNotes) => {
|
||||
const promises = [];
|
||||
for (let i = 1; i <= nNotes; i += 1) {
|
||||
const note = await this.$getNote(i);
|
||||
st.notes.push(note);
|
||||
promises.push(this.$getNote(i));
|
||||
}
|
||||
return Promise.all(promises);
|
||||
});
|
||||
|
||||
const nManagers = await this.numberOfNoteManagers();
|
||||
const getManagers = () => this.numberOfNoteManagers()
|
||||
.then((nManagers) => {
|
||||
const promises = [];
|
||||
for (let i = 1; i <= nManagers; i += 1) {
|
||||
const manager = await this.$getManager(i);
|
||||
st.managers.push(manager);
|
||||
promises.push(this.$getManager(i));
|
||||
}
|
||||
return st;
|
||||
};
|
||||
|
||||
LiquidPledging.prototype.getState = getState;
|
||||
return Promise.all(promises);
|
||||
});
|
||||
|
||||
return Promise.all([getNotes(), getManagers()])
|
||||
.then(([notes, managers]) => ({
|
||||
notes: [null, ...notes],
|
||||
managers: [null, ...managers],
|
||||
}));
|
||||
};
|
||||
|
||||
LiquidPledging.prototype.generateDonorsState = function () {
|
||||
const donorsState = [];
|
||||
|
|
Loading…
Reference in New Issue