-
Notifications
You must be signed in to change notification settings - Fork 1
/
allDeals.js
105 lines (91 loc) · 4.17 KB
/
allDeals.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
function DealFullDisplay(dealEventArgs){
var toInt = function(bigNumber){
return parseInt(bigNumber.toString());
};
this._dealId = toInt(dealEventArgs._dealId);
this._startTime = toInt(dealEventArgs._startTime);
this._depositDurationInHours = toInt(dealEventArgs._depositDurationInHours);
this._claimDurationInHours = toInt(dealEventArgs._claimDurationInHours);
this._claimUnitValueInEther = dealEventArgs._claimUnitValueInWei.dividedBy(etherToWei);
this._claimDepositInEther = dealEventArgs._claimDepositInWei.dividedBy(etherToWei);
this._minNumClaims = dealEventArgs._minNumClaims;
this.dealStatus = null;
this.addStatus = function( _dealStatus ){
this.dealStatus = _dealStatus;
};
this.getLineId = function(){
return "AllDeals_lineid_" + this._dealId.toString();
};
this.getDealLine = function(){
var getIconCol = function(iconName, text){
return "<td><i class=\"fa fa-" + iconName + "\" aria-hidden=\"true\"></i> " + text.toString() + "</td>";
};
var get2IconCol = function(iconName1, iconName2, text){
return "<td><i class=\"fa fa-" + iconName1 + "\" aria-hidden=\"true\"></i><i class=\"fa fa-" + iconName2 + "\" aria-hidden=\"true\"></i> " + text.toString() + "</td>";
};
var startTimeDate = new Date(this._startTime * 1000 );
var line = "<tr class=\"dapp-input\" id=\"" + this.getLineId() + "\">" +
getIconCol("hashtag",this._dealId) +
getIconCol("calendar",startTimeDate) +
get2IconCol("clock-o","shopping-cart",this._claimDurationInHours) +
get2IconCol("clock-o","bank", this._depositDurationInHours) +
getIconCol("money", this._claimUnitValueInEther) +
getIconCol("legal", this._claimDepositInEther) +
getIconCol("user-times", this._minNumClaims);
if( this.dealStatus !== null ){
line += getIconCol("users", this.dealStatus.getNumClaims()) +
getIconCol("percent", this.dealStatus.getDepositSumPercent());
}
return line + "</tr>";
};
this.makeUI = function(){
if( $("#" + this.getLineId()).length > 0 ){
$("#" + this.getLineId()).html(this.getDealLine());
}
else{
$("#all_deals_table").append(this.getDealLine());
}
if( this.dealStatus === null ){
var hanldeDealStatus = function(err, result){
if( err ) return handleError(err);
this.dealStatus = new DealStatus(result[0],
result[1],
result[2],
result[3]);
this.makeUI();
};
globalContractInstance.dealStatus( new BigNumber(this._dealId), hanldeDealStatus.bind(this));
}
};
}
var makeAllDealsTable = function(){
var event = globalContractInstance.NewDeal({},{fromBlock: 0, toBlock: 'latest'});
event.get(function(err,logs){
if( err ) return handleError(err);
for( var i = 0 ; i < logs.length ; i++ ){
args = logs[i].args;
deal = new DealFullDisplay(args);
deal.makeUI();
}
// finished loading
$("#all_deals_table").show();
$("#all_deals_before_load").hide();
});
};
var toggleLegend = function(){
//$("#all_deals_show_legend").toggle();
$("#all_deals_table_legend").toggle();
if($("#all_deals_show_legend").html() === "Show Legend"){
$("#all_deals_show_legend").html("Hide Legend");
}
else{
$("#all_deals_show_legend").html("Show Legend");
}
};
var allDealsPage = function(){
$("#all_deals_div").show();
$("#all_deals_table").hide();
$("#all_deals_table_legend").hide();
$("#all_deals_show_legend").mouseover(toggleLegend);
makeAllDealsTable();
};