feat: view pledges
This commit is contained in:
parent
26f404261b
commit
7f6169bb7a
|
@ -1,6 +1,7 @@
|
||||||
var inquirer = require('inquirer');
|
var inquirer = require('inquirer');
|
||||||
const Web3 = require("web3");
|
const Web3 = require("web3");
|
||||||
const PledgeAdminUtils = require('./pledgeadmin-utils');
|
const PledgeAdminUtils = require('./pledgeadmin-utils');
|
||||||
|
const PledgeUtils = require('./pledge-utils');
|
||||||
const TrxUtils = require('./trx-utils');
|
const TrxUtils = require('./trx-utils');
|
||||||
const Contracts = require("./contracts.js");
|
const Contracts = require("./contracts.js");
|
||||||
|
|
||||||
|
@ -88,6 +89,7 @@ class Actions {
|
||||||
return doAction(text, async () => {
|
return 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();
|
||||||
|
pledgeAdmin.id = params.id;
|
||||||
PledgeAdminUtils.printTable([pledgeAdmin].filter(x => x.adminType === PledgeAdminUtils.constants.PROJECT));
|
PledgeAdminUtils.printTable([pledgeAdmin].filter(x => x.adminType === PledgeAdminUtils.constants.PROJECT));
|
||||||
} catch(error){
|
} catch(error){
|
||||||
console.log("Couldn't obtain the project: ", error.message);
|
console.log("Couldn't obtain the project: ", error.message);
|
||||||
|
@ -95,6 +97,19 @@ class Actions {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async viewPledges(params) {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
try {
|
||||||
|
const pledges = await PledgeUtils.getPledges(this.contracts.LiquidPledging);
|
||||||
|
PledgeUtils.printTable(pledges, web3);
|
||||||
|
} catch(error){
|
||||||
|
console.log(error);
|
||||||
|
console.log("Couldn't obtain the list of pledges: ", error.message);
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async listFunders() {
|
async listFunders() {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
|
@ -138,9 +153,9 @@ class Actions {
|
||||||
}
|
}
|
||||||
|
|
||||||
async donate(params) {
|
async donate(params) {
|
||||||
let text = `await LiquidPledging.methods.donate(${params.funderId}, ${params.projectId}, \"${this.contracts.LiquidPledging.options.address}\", web3.utils.toWei(\"${params.amount}\", \"ether\")).send({gas: 2000000});`
|
let text = `await LiquidPledging.methods.donate(${params.funderId}, ${params.projectId}, \"${params.tokenAddress}\", web3.utils.toWei(\"${params.amount}\", \"ether\")).send({gas: 2000000});`
|
||||||
return doAction(text, async () => {
|
return doAction(text, async () => {
|
||||||
const toSend = this.contracts.LiquidPledging.methods.donate(params.funderId, params.projectId, this.contracts.LiquidPledging.options.address, web3.utils.toWei(params.amount.toString(), "ether"));
|
const toSend = this.contracts.LiquidPledging.methods.donate(params.funderId, params.projectId, params.tokenAddress, web3.utils.toWei(params.amount.toString(), "ether"));
|
||||||
const receipt = await TrxUtils.executeAndWait(toSend, web3.eth.defaultAccount);
|
const receipt = await TrxUtils.executeAndWait(toSend, web3.eth.defaultAccount);
|
||||||
console.dir("txHash: " + receipt.transactionHash);
|
console.dir("txHash: " + receipt.transactionHash);
|
||||||
});
|
});
|
||||||
|
|
18
src/cmd.js
18
src/cmd.js
|
@ -11,16 +11,28 @@ function mainMenu(actions) {
|
||||||
|
|
||||||
if (subAction === 'List Projects') {
|
if (subAction === 'List Projects') {
|
||||||
await actions.listProjects();
|
await actions.listProjects();
|
||||||
} if (subAction === 'Create Project') {
|
}
|
||||||
|
|
||||||
|
if (subAction === 'Create Project') {
|
||||||
let params = (await menus.createProject(actions.web3().eth.defaultAccount))
|
let params = (await menus.createProject(actions.web3().eth.defaultAccount))
|
||||||
await actions.addProject(params);
|
await actions.addProject(params);
|
||||||
} if (subAction === 'View Project') {
|
}
|
||||||
|
|
||||||
|
if (subAction === 'View Project') {
|
||||||
let params = (await menus.viewProject())
|
let params = (await menus.viewProject())
|
||||||
await actions.viewProject(params);
|
await actions.viewProject(params);
|
||||||
} if (subAction === 'Donate to Project') {
|
}
|
||||||
|
|
||||||
|
if (subAction === 'Fund a Project') {
|
||||||
let params = (await menus.donate())
|
let params = (await menus.donate())
|
||||||
await actions.donate(params);
|
await actions.donate(params);
|
||||||
}
|
}
|
||||||
|
} else if(action === 'Pledges') {
|
||||||
|
subAction = (await menus.pledges()).action
|
||||||
|
|
||||||
|
if (subAction === 'View Pledges') {
|
||||||
|
await actions.viewPledges();
|
||||||
|
}
|
||||||
} else if (action === 'Funders') {
|
} else if (action === 'Funders') {
|
||||||
subAction = (await menus.funders()).action
|
subAction = (await menus.funders()).action
|
||||||
|
|
||||||
|
|
32
src/menus.js
32
src/menus.js
|
@ -12,6 +12,7 @@ const menus = {
|
||||||
choices: [
|
choices: [
|
||||||
'Projects',
|
'Projects',
|
||||||
'Funders',
|
'Funders',
|
||||||
|
'Pledges',
|
||||||
new inquirer.Separator(),
|
new inquirer.Separator(),
|
||||||
'Tokens',
|
'Tokens',
|
||||||
new inquirer.Separator(),
|
new inquirer.Separator(),
|
||||||
|
@ -61,6 +62,24 @@ const menus = {
|
||||||
])
|
])
|
||||||
},
|
},
|
||||||
|
|
||||||
|
pledges: async function() {
|
||||||
|
return inquirer
|
||||||
|
.prompt([
|
||||||
|
{
|
||||||
|
type: 'list',
|
||||||
|
name: 'action',
|
||||||
|
message: 'Pledges> ',
|
||||||
|
choices: [
|
||||||
|
'View Pledges',
|
||||||
|
new inquirer.Separator(),
|
||||||
|
'Back',
|
||||||
|
// new inquirer.Separator(),
|
||||||
|
// 'Exit'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
])
|
||||||
|
},
|
||||||
|
|
||||||
tokens: async function() {
|
tokens: async function() {
|
||||||
return inquirer
|
return inquirer
|
||||||
.prompt([
|
.prompt([
|
||||||
|
@ -150,6 +169,7 @@ const menus = {
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
},
|
},
|
||||||
|
|
||||||
viewProject: async function() {
|
viewProject: async function() {
|
||||||
return inquirer.prompt([
|
return inquirer.prompt([
|
||||||
{
|
{
|
||||||
|
@ -247,6 +267,18 @@ const menus = {
|
||||||
])
|
])
|
||||||
},
|
},
|
||||||
|
|
||||||
|
viewDonations: async function() {
|
||||||
|
return inquirer.prompt([
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
name: 'id',
|
||||||
|
message: 'What is the Funder/Delegate/Project ID?',
|
||||||
|
filter: Number,
|
||||||
|
default: 0
|
||||||
|
}
|
||||||
|
])
|
||||||
|
},
|
||||||
|
|
||||||
donate: async function(lpAddress) {
|
donate: async function(lpAddress) {
|
||||||
console.dir("note: don't forget to approve the token to be withdrawn by the LF address");
|
console.dir("note: don't forget to approve the token to be withdrawn by the LF address");
|
||||||
return inquirer.prompt([
|
return inquirer.prompt([
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
const Table = require('cli-table');
|
||||||
|
|
||||||
|
const getPledges = async (LiquidPledging) => {
|
||||||
|
let numPledges = await LiquidPledging.methods.numberOfPledges().call();
|
||||||
|
let pledges = [];
|
||||||
|
let pledgeAdmins = [];
|
||||||
|
for(let i = 1; i <= numPledges; i++){
|
||||||
|
pledges.push(LiquidPledging.methods.getPledge(i).call());
|
||||||
|
}
|
||||||
|
pledges = await Promise.all(pledges);
|
||||||
|
for(let i = 0; i < pledges.length; i++){
|
||||||
|
pledges[i].id = i+1;
|
||||||
|
pledgeAdmins.push(LiquidPledging.methods.getPledgeAdmin(pledges[i].owner).call())
|
||||||
|
}
|
||||||
|
|
||||||
|
pledgeAdmins = await Promise.all(pledgeAdmins);
|
||||||
|
for(let i = 0; i < pledges.length; i++){
|
||||||
|
pledges[i].ownerData = pledgeAdmins[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return pledges;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PledgeState = {
|
||||||
|
'0': "Pledged",
|
||||||
|
'1': "Paying",
|
||||||
|
'2': "Paid"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const printTable = (pledges, web3) => {
|
||||||
|
const table = new Table({
|
||||||
|
head: ['Id', 'Owner', 'Token', 'Amount', 'nDelegates', 'IntededProject (?)', 'Commit Time (?)', 'Old Pledge Id', 'Pledge State']
|
||||||
|
});
|
||||||
|
for(let i = pledges.length - 1; i >= 0; i--){
|
||||||
|
table.push(
|
||||||
|
[pledges[i].id, `${pledges[i].owner} (${pledges[i].ownerData.name})`, pledges[i].token, web3.utils.fromWei(pledges[i].amount, "ether"), pledges[i].nDelegates, pledges[i].intendedProject, pledges[i].commitTime, pledges[i].oldPledge, PledgeState[pledges[i].pledgeState]]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
console.log(table.toString());
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getPledges,
|
||||||
|
printTable
|
||||||
|
};
|
|
@ -9,7 +9,7 @@ const printTable = (pledgeAdmins) => {
|
||||||
|
|
||||||
for(let i = 0; i < pledgeAdmins.length; i++){
|
for(let i = 0; i < pledgeAdmins.length; i++){
|
||||||
table.push(
|
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]
|
[pledgeAdmins[i].id, pledgeAdmins[i].name, pledgeAdmins[i].url, pledgeAdmins[i].parentProject, pledgeAdmins[i].canceled ? 'Canceled' : 'Active', pledgeAdmins[i].commitTime, pledgeAdmins[i].addr, pledgeAdmins[i].plugin]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,11 @@ const getPledgeAdmins = async (LiquidPledging) => {
|
||||||
for(let i = 1; i <= numProjects; i++){
|
for(let i = 1; i <= numProjects; i++){
|
||||||
pledgeAdmins.push(LiquidPledging.methods.getPledgeAdmin(i).call());
|
pledgeAdmins.push(LiquidPledging.methods.getPledgeAdmin(i).call());
|
||||||
}
|
}
|
||||||
return Promise.all(pledgeAdmins);
|
const results = await Promise.all(pledgeAdmins);
|
||||||
|
for(let i = 0; i < results.length; i++){
|
||||||
|
results[i].id = i+1;
|
||||||
|
}
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue