add donate action; fix saying no to confirm

This commit is contained in:
Iuri Matias 2019-05-22 14:46:27 -04:00
parent a27c17f067
commit 2f3021e631
3 changed files with 48 additions and 1 deletions

View File

@ -15,7 +15,8 @@ function doAction(actionText, action) {
name: 'action',
message: 'Execute?',
}
]).then(() => {
]).then((answer) => {
if (answer.action === false) return;
console.dir("executing...");
try {
action()
@ -87,6 +88,14 @@ class Actions {
});
}
donate(params) {
let text = `await LiquidPledging.methods.donate(${params.funderId}, ${params.projectId}, \"${LiquidPledging.options.address}\", web3.utils.toWei(\"${params.amount}\", \"ether\")).send({gas: 2000000});`
doAction(text, async () => {
let donateReceipt = await LiquidPledging.methods.donate(params.funderId, params.projectId, LiquidPledging.options.address, web3.utils.toWei(params.amount, "ether")).send({gas: 2000000});
console.dir("txHash: " + donateReceipt.transactionHash)
});
}
}
module.exports = Actions;

View File

@ -15,6 +15,9 @@ async function app(actions) {
let params = (await menus.createProject(actions.web3().eth.defaultAccount))
actions.addProject(params);
} if (subAction === 'view Project') {
} if (subAction === 'Donate to Project') {
let params = (await menus.donate())
actions.donate(params);
}
} else if (action === 'Funders') {
subAction = (await menus.funders()).action

View File

@ -32,6 +32,7 @@ const menus = {
'List Projects',
'Create Project',
'View Project',
'Donate to Project',
// new inquirer.Separator(),
// 'Back',
// new inquirer.Separator(),
@ -233,6 +234,40 @@ const menus = {
filter: Number
}
])
},
donate: async function(lpAddress) {
console.dir("note: don't forget to approve the token to be withdrawn by the LF address");
return inquirer.prompt([
{
type: 'input',
name: 'funderId',
message: 'What is the funder Id?',
filter: Number
},
{
type: 'input',
name: 'projectId',
message: 'What is the projectId?',
filter: Number
},
{
type: 'input',
name: 'tokenAddress',
message: 'What is the token address?',
filter: String,
validate: function(value) {
return value.indexOf("0x") === 0;
}
},
{
type: 'input',
name: 'amount',
message: 'amount (in ether units)',
default: 2,
filter: Number
}
])
}
}