add donate action; fix saying no to confirm
This commit is contained in:
parent
a27c17f067
commit
2f3021e631
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
35
src/menus.js
35
src/menus.js
|
@ -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
|
||||
}
|
||||
])
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue