feat: list funders + refactoring
This commit is contained in:
parent
d5d2786b97
commit
b6c56cbc55
|
@ -1,7 +1,7 @@
|
||||||
var inquirer = require('inquirer');
|
var inquirer = require('inquirer');
|
||||||
const Web3 = require("web3");
|
const Web3 = require("web3");
|
||||||
const Table = require('cli-table');
|
const Table = require('cli-table');
|
||||||
|
const PledgeAdminUtils = require('./pledgeadmin-utils');
|
||||||
|
|
||||||
const Contracts = require("./contracts.js");
|
const Contracts = require("./contracts.js");
|
||||||
|
|
||||||
|
@ -69,23 +69,10 @@ class Actions {
|
||||||
|
|
||||||
async listProjects() {
|
async listProjects() {
|
||||||
try {
|
try {
|
||||||
let numProjects = await this.contracts.LiquidPledging.methods.numberOfPledgeAdmins().call();
|
const pledgeAdmins = await PledgeAdminUtils.getPledgeAdmins(this.contracts.LiquidPledging);
|
||||||
|
PledgeAdminUtils.printTable(pledgeAdmins.filter(x => x !== PledgeAdminUtils.constants.PROJECT));
|
||||||
const table = new Table({
|
|
||||||
head: ['Id', 'Name', 'URL', 'ParentProject', 'Status', 'Commit Time', 'Owner', 'Plugin']
|
|
||||||
});
|
|
||||||
|
|
||||||
for(let i = 1; i <= numProjects; i++){
|
|
||||||
const pledgeAdmin = await this.contracts.LiquidPledging.methods.getPledgeAdmin(i).call();
|
|
||||||
if(pledgeAdmin.adminType !== '2') continue;
|
|
||||||
|
|
||||||
table.push(
|
|
||||||
[i, pledgeAdmin.name, pledgeAdmin.url, pledgeAdmin.parentProject, pledgeAdmin.canceled ? 'Canceled' : 'Active', pledgeAdmin.commitTime, pledgeAdmin.addr, pledgeAdmin.plugin]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(table.toString());
|
|
||||||
} catch(error){
|
} catch(error){
|
||||||
|
console.log(error);
|
||||||
console.log("Couldn't obtain the list of projects: ", error.message);
|
console.log("Couldn't obtain the list of projects: ", error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,19 +82,23 @@ class Actions {
|
||||||
doAction(text, async () => {
|
doAction(text, async () => {
|
||||||
try {
|
try {
|
||||||
const pledgeAdmin = await this.contracts.LiquidPledging.methods.getPledgeAdmin(params.id).call();
|
const pledgeAdmin = await this.contracts.LiquidPledging.methods.getPledgeAdmin(params.id).call();
|
||||||
const table = new Table({
|
PledgeAdminUtils.printTable([pledgeAdmin].filter(x => x !== PledgeAdminUtils.constants.PROJECT));
|
||||||
head: ['Id', 'Name', 'URL', 'ParentProject', 'Status', 'Commit Time', 'Owner', 'Plugin']
|
|
||||||
});
|
|
||||||
table.push(
|
|
||||||
[params.id, pledgeAdmin.name, pledgeAdmin.url, pledgeAdmin.parentProject, pledgeAdmin.canceled ? 'Canceled' : 'Active', pledgeAdmin.commitTime, pledgeAdmin.addr, pledgeAdmin.plugin]
|
|
||||||
);
|
|
||||||
console.log(table.toString());
|
|
||||||
} catch(error){
|
} catch(error){
|
||||||
console.log("Couldn't obtain the project: ", error.message);
|
console.log("Couldn't obtain the project: ", error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async listFunders() {
|
||||||
|
try {
|
||||||
|
const pledgeAdmins = await PledgeAdminUtils.getPledgeAdmins(this.contracts.LiquidPledging);
|
||||||
|
PledgeAdminUtils.printTable(pledgeAdmins.filter(x => x !== PledgeAdminUtils.constants.FUNDER));
|
||||||
|
} catch(error){
|
||||||
|
console.log(error);
|
||||||
|
console.log("Couldn't obtain the list of funders: ", error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addGiver(params) {
|
addGiver(params) {
|
||||||
let text = `await LiquidPledging.methods.addGiver(\"${params.name}\", \"${params.url}\", ${params.commitTime}, \"${params.plugin}\").send({from: \"${web3.eth.defaultAccount}\", gas: 2000000})`
|
let text = `await LiquidPledging.methods.addGiver(\"${params.name}\", \"${params.url}\", ${params.commitTime}, \"${params.plugin}\").send({from: \"${web3.eth.defaultAccount}\", gas: 2000000})`
|
||||||
doAction(text, async () => {
|
doAction(text, async () => {
|
||||||
|
|
|
@ -25,6 +25,7 @@ async function app(actions) {
|
||||||
subAction = (await menus.funders()).action
|
subAction = (await menus.funders()).action
|
||||||
|
|
||||||
if (subAction === 'List Funders') {
|
if (subAction === 'List Funders') {
|
||||||
|
actions.listFunders();
|
||||||
} if (subAction === 'Create Funder') {
|
} if (subAction === 'Create Funder') {
|
||||||
let params = (await menus.createProject())
|
let params = (await menus.createProject())
|
||||||
actions.addProject(params);
|
actions.addProject(params);
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
const Table = require('cli-table');
|
||||||
|
|
||||||
|
const FUNDER = "0";
|
||||||
|
const PROJECT = "2";
|
||||||
|
const printTable = (pledgeAdmins) => {
|
||||||
|
const table = new Table({
|
||||||
|
head: ['Id', 'Name', 'URL', 'ParentProject', 'Status', 'Commit Time', 'Owner', 'Plugin']
|
||||||
|
});
|
||||||
|
|
||||||
|
for(let i = 0; i < pledgeAdmins.length; i++){
|
||||||
|
table.push(
|
||||||
|
[i, pledgeAdmins[i].name, pledgeAdmins[i].url, pledgeAdmins[i].parentProject, pledgeAdmins[i].canceled ? 'Canceled' : 'Active', pledgeAdmins[i].commitTime, pledgeAdmins[i].addr, pledgeAdmins[i].plugin]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(table.toString());
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const getPledgeAdmins = async (LiquidPledging) => {
|
||||||
|
let numProjects = await LiquidPledging.methods.numberOfPledgeAdmins().call();
|
||||||
|
let pledgeAdmins = [];
|
||||||
|
for(let i = 1; i <= numProjects; i++){
|
||||||
|
pledgeAdmins.push(LiquidPledging.methods.getPledgeAdmin(i).call());
|
||||||
|
}
|
||||||
|
return Promise.all(pledgeAdmins);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
printTable,
|
||||||
|
getPledgeAdmins,
|
||||||
|
constants: {
|
||||||
|
FUNDER,
|
||||||
|
PROJECT
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue