Loading project information

In crowdfunding, we defined a project struct that contains fundraising information, as follows:

struct Project {
address addr;
string name;
string website;
uint totalRaised;
uint minimumToRaise;
uint currentBalance;
uint deadline;
uint completeAt;
Status status;
}

Let's define some related information in HTML, for example:

<table class="table table-hover table-striped">
<tbody>
<tr>
<th scope="row">address</th>
<td><span class="text-info" id="address"></span
</td>
</tr>
<tr>
<th scope="row">name</th>
<td><span class="text-info" id="name"></span></td>
</tr>
<tr>
<th scope="row">website</th>
<td><span class="text-info" id="website"></span></td>
</tr>
<tr>
<th scope="row">totalRaised</th>
<td><span class="text-info" id="totalRaised"></span></td>

</tbody>
</table>

The CrowdFunding.deployed() function will create an instance of CrowdFunding that represents the default address managed by CrowdFunding. The code here shows us how to display project information:

    App.contracts.CrowdFunding.deployed().then(function(instance) {
crowdFundingInstance = instance;
return crowdFundingInstance.project();
}).then(function(projectInfo) {
$("#address").text(projectInfo[0].toString());
$("#name").text(projectInfo[1]);
$("#website").text(projectInfo[2]);
$("#totalRaised").text(projectInfo[3].toString());
..
if(projectInfo[6].toString().length>0) {
var deadline = new
Date(Number(projectInfo[6].toString())*1000);
deadlineDate = moment(deadline).format("YYYY-MM-DD h:mm:ss");
$("#deadline").text(deadlineDate);
}
if(projectInfo[7].toString().length>0 && projectInfo[7].toString()!='0') {
console.log(projectInfo[7].toString());
var completeAt = new Date(Number(projectInfo[7].toString())*1000);
completeAtDate = moment(completeAt).format("YYYY-MM-DD h:mm:ss");
$("#completeAt").text(completeAtDate);
}
}).catch(function(error) {
..
});

The result will be displayed as follows:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset