forked from blockchainmanc/simple-ledger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
147 lines (120 loc) · 5.63 KB
/
index.html
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<html>
<head>
<title>Betting Boys</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./style.css">
</head>
<body>
<div id="vue-app">
<h1>Betting Boys</h1>
<p v-if="loading" class="spinner">
<i class="fa fa-money fa-spin fa-5x fa-fw"></i>
<span class="sr-only">Loading...</span>
</p>
<div v-if="!loading" v-cloak>
<div class="titleBar">
<span @click="selectingContract = !selectingContract">{{ selectedContract.name }}</span>
<i class="fa fa-chevron-down fa-fw" @click="selectingContract = !selectingContract"></i>
<div class="titleBarInner">
<div class="hoverMenu" v-if="selectingContract" v-for="contract in allContracts" href="#" @click="selectContract(contract)">
{{ contract.name }}
</div>
</div>
</div>
<div v-for="contract in allContracts" v-if="selectedContract == contract">
<h2><span class="grandTotal"><i class="fa fa-gbp"></i>{{ contract.grandTotal }}</span></h2>
<div class="boyRow" v-for="boy in contract.boys">
<div class="boyName">
{{ boy.name }}
<span v-if="boy.champion" class="champion"><i class="fa fa-trophy"></i></span>
</div>
<div class="month">{{ boy.month }}</div>
<div class="total" :class="{ 'pos': boy.total > 0, 'neut': boy.total === 0, 'tbc': boy.total === -1 }">
{{ boy.total }}
</div>
</div>
</div>
</div>
</div>
<script src="https://use.fontawesome.com/e88a1894a6.js" type="text/javascript"></script>
<script src="https://cdn.ethers.io/scripts/ethers-v2.0.min.js" type="text/javascript"></script>
<script src="https://unpkg.com/vue/dist/vue.js" type="text/javascript"></script>
<script src="https://gstatic.com/firebasejs/4.0.0/firebase.js" type="text/javascript"></script>
<script src="https://unpkg.com/vuefire/dist/vuefire.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.5.1/bluebird.core.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js" type="text/javascript"></script>
<script>
/* global Vue, firebase, ethers, _, Promise */
var provider = new ethers.providers.InfuraProvider('ropsten');
var config = {
apiKey: "AIzaSyCxxAe_V_G4KH60eHR79H-DVmX4sswwbB8",
authDomain: "betting-boys.firebaseapp.com",
databaseURL: "https://betting-boys.firebaseio.com",
projectId: "betting-boys",
storageBucket: "betting-boys.appspot.com",
messagingSenderId: "394601607248"
};
var db = firebase.initializeApp(config).database();
new Vue({
el: '#vue-app',
data: {
loading: true,
allContracts: undefined,
grandTotal: undefined,
selectedContract: undefined,
selectingContract: false
},
methods: {
selectContract: function (contract, event) {
this.selectedContract = contract;
this.selectingContract = false;
}
},
firebase: {
contracts: {
source: db.ref('contracts'),
readyCallback: function (snapshot) {
var that = this;
console.log('loaded contracts ref...');
console.log(snapshot.val());
this.allContracts = snapshot.val();
this.selectedContract = this.allContracts[0];
_.forEach(this.allContracts, function (contract) {
console.log('Instantiating contract at ' + contract.contract);
var ethContract = new ethers.Contract(contract.contract, contract.abi, provider);
ethContract.owner().then(function (result) {
console.log(contract.contract + ' owner ' + result[0]);
});
var callPromises = [];
contract.boys.forEach(function (entity) {
callPromises.push(ethContract.readEntry(ethers.utils.toUtf8Bytes(entity['initials'])));
});
Promise.all(callPromises).then(function (callResults) {
_.forEach(callResults, function (callRes) {
var total = parseInt(callRes[1].toString());
var initials = ethers.utils.toUtf8String(callRes[0].toString());
if (total !== 0) {
var boyObj = _.find(contract.boys, function (boy) {
return boy.initials === initials
});
boyObj.total = total;
}
});
contract.grandTotal = _.reduce(contract.boys, function (sum, n) {
if (n.total <= 0) {
return sum;
}
return sum + n.total
}, 0);
var bestObj = _.maxBy(contract.boys, 'total');
bestObj['champion'] = true;
that.loading = false;
});
});
}
}
}
})
</script>
</body>
</html>