-
Notifications
You must be signed in to change notification settings - Fork 0
/
Index.html
210 lines (206 loc) · 5.23 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<html>
<head>
<link rel='shortcut icon' type='image/x-icon' href='/favicon.ico' />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
crossorigin="anonymous">
<title>Presenting VegeMarket Banking Demo</title>
<link rel="stylesheet" href="webstyle.css">
<style>
</style>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
</head>
<body>
<script charset="utf-8" src="https://cdn.ethers.io/scripts/ethers-v4.min.js" type="text/javascript">
</script>
<div class="container">
<div class="form-group">
<h1>Vegetable Market DApp</h1>
<p> Enter Vegetable Purchase Details</p>
<div class="row">
<div class="col offset-md-4 col-md-4">
<label for="withdrawal">Good Vegetables Count:</label>
<input type="text" class="form-control" id="withdrawalSum">
<label for="deposit">Bad Vegetables Count:</label>
<input type="text" class="form-control" id="depositSum">
<label for="deposit">Price per Vegetables Piece :</label>
<input type="text" class="form-control" id="per_what">
</div>
</div>
<div class="row mt-2">
<div class="col col-md-2">
<button class="btn btn-light btn-block" onclick="submit()"> Submit </button>
</div>
<div class="col col-md-2">
<button class="btn btn-light btn-block" onclick="getBalance()"> get </button>
</div>
</div>
<h1 id="vege"></h1>
<p id="printhere"></p>
<p id="printhere1"></p>
<h2 id="iddd"></h2>
</div>
</div>
<script>
window.ethereum.enable()
var provider = new ethers.providers.Web3Provider(web3.currentProvider, 'ropsten');
//NOTE: Add your key below before runing the code
var bankContractAddress = "";
let bankContractABI = [
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "admin",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "calculateProfitOrLoss",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "goodVegetablescount",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "itemsandamountpurchased",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "netPriceSpent",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "pricepervegp",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "goodVegetables",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "badVegetables",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "priceperveg",
"type": "uint256"
}
],
"name": "receiveInput",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "totalVegetablesPurchased",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
]
provider.listAccounts().then(function (accounts) {
signer = provider.getSigner(accounts[0]);
bankContract = new ethers.Contract(bankContractAddress, bankContractABI, signer);
})
async function getBalance(balance) {
getBalancePromise =await bankContract.itemsandamountpurchased();
var balance =await getBalancePromise;
document.getElementById("vege").innerHTML ="Vegetable Purchase Report" ;
document.getElementById("printhere").innerHTML ="Total Vegetable Purchased: "+balance[0] ;
document.getElementById("printhere1").innerHTML ="Net Price Spent: "+balance[1] ;
getBalancePromise =await bankContract.calculateProfitOrLoss();
var balance1 =await getBalancePromise;
document.getElementById("iddd").innerHTML = "Status = "+balance1[0] + " Amount = "+ balance1[1] ;
}
async function submit(){
good = $("#withdrawalSum").val()
bad = $("#depositSum").val()
per = $("#per_what").val()
if (good == "" ||bad =="" || per =="" ) {
alert("Please input mood");
} else {
getSettledBalancePromise = await bankContract.receiveInput(good,bad,per);
await getSettledBalancePromise;
}
}
</script>
</body>