Merge pull request #11 from status-im/feat/withdraw

feat: withdraw
This commit is contained in:
Iuri Matias 2019-05-23 15:09:37 -04:00 committed by GitHub
commit 9c6b9dcc15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 4 deletions

View File

@ -97,6 +97,17 @@ class Actions {
});
}
async withdraw(params) {
let text = `await LiquidPledging.methods.withdraw(\"${params.id}\", web3.utils.toWei(\"${params.amount}\", "ether")).send({gas: 2000000})`;
return doAction(text, async () => {
const toSend = this.contracts.LiquidPledging.methods.withdraw(params.id.toString(), web3.utils.toWei(params.amount.toString(), "ether"));
const receipt = await TrxUtils.executeAndWait(toSend, web3.eth.defaultAccount);
console.dir("txHash: " + receipt.transactionHash);
const paymentId = receipt.events.AuthorizePayment.returnValues.idPayment;
console.log("Payment ID: " , paymentId);
});
}
async viewPledges(params) {
return new Promise(async (resolve, reject) => {
try {

View File

@ -33,6 +33,11 @@ function mainMenu(actions) {
if (subAction === 'View Pledges') {
await actions.viewPledges();
}
if (subAction === 'Withdraw') {
let params = (await menus.withdraw())
await actions.withdraw(params);
}
} else if (action === 'Funders') {
subAction = (await menus.funders()).action

View File

@ -9,12 +9,19 @@ class Contracts {
loadContracts() {
console.dir("loading contracts for " + this.chain);
const LPVaultJSONConfig = require(`../chains/${this.chain}/contracts/LPVault.json`);
const LPVault = new this.web3.eth.Contract(LPVaultJSONConfig.abiDefinition, LPVaultJSONConfig.address);
const LiquidPledgingJSONConfig = require(`../chains/${this.chain}/contracts/LiquidPledging.json`);
const LiquidPledging = new this.web3.eth.Contract(LiquidPledgingJSONConfig.abiDefinition, LiquidPledgingJSONConfig.address);
this.contracts.LiquidPledging = LiquidPledging;
const StandardTokenJSONConfig = require(`../chains/${this.chain}/contracts/StandardToken.json`);
const StandardToken = new this.web3.eth.Contract(StandardTokenJSONConfig.abiDefinition, StandardTokenJSONConfig.address);
LiquidPledging.options.jsonInterface.push(LPVault.options.jsonInterface.find(x => x.type === 'event' && x.name ==='AuthorizePayment'));
this.contracts.LiquidPledging = LiquidPledging;
this.contracts.LPVault = LPVault;
this.contracts.StandardToken = StandardToken;
}

View File

@ -33,7 +33,7 @@ const menus = {
'List Projects',
'Create Project',
'View Project',
'Donate to Project',
'Fund a Project',
new inquirer.Separator(),
'Back',
// new inquirer.Separator(),
@ -71,6 +71,7 @@ const menus = {
message: 'Pledges> ',
choices: [
'View Pledges',
'Withdraw',
new inquirer.Separator(),
'Back',
// new inquirer.Separator(),
@ -182,6 +183,26 @@ const menus = {
])
},
withdraw: async function() {
return inquirer.prompt([
{
type: 'input',
name: 'id',
message: 'What is the Pledge ID?',
filter: Number,
default: 0
},
{
type: 'input',
name: 'amount',
message: 'amount (in ether units)',
default: 2,
filter: Number
}
])
},
createFunder: async function() {
return inquirer.prompt([
{

View File

@ -30,11 +30,11 @@ const PledgeState = {
const printTable = (pledges, web3) => {
const table = new Table({
head: ['Id', 'Owner', 'Token', 'Amount', 'nDelegates', 'IntededProject (?)', 'Commit Time (?)', 'Old Pledge Id', 'Pledge State']
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]]
[pledges[i].id, `${pledges[i].owner} (${pledges[i].ownerData.name}, ${pledges[i].ownerData.commitTime})`, 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());