|
15 | 15 | } else { |
16 | 16 | createWeb3(); |
17 | 17 | } |
| 18 | + document.getElementById("setNet").addEventListener("click", setNetwork); |
| 19 | + document.getElementById("loginButton").addEventListener("click", Login); |
| 20 | + document.getElementById("completeFields").addEventListener("click", CompleteFields); |
| 21 | + document.getElementById("submitButton").addEventListener("click", SubmitToBlockchain); |
| 22 | + document.getElementById("checkButton").addEventListener("click", CheckIntegrity); |
| 23 | + |
18 | 24 |
|
19 | 25 | function SubmitToBlockchain (){ |
20 | 26 |
|
|
56 | 62 | var nonce = "0x" + (nonceValue).toString(16); |
57 | 63 | rawtx = { |
58 | 64 | nonce: nonce, |
59 | | - gasPrice: this.web3.utils.toHex(estimatedGas), |
60 | | - gasLimit: this.web3.utils.toHex(GasLimit), |
| 65 | + gasPrice: web3.utils.toHex(estimatedGas), |
| 66 | + gasLimit: web3.utils.toHex(GasLimit), |
61 | 67 | to: contractAddress, |
62 | 68 | data: bytecodeData |
63 | 69 | }; |
|
67 | 73 | tx.sign(privateKey); |
68 | 74 | var raw = "0x" + tx.serialize().toString("hex"); |
69 | 75 |
|
70 | | - this.web3.eth.sendSignedTransaction(raw) |
| 76 | + web3.eth.sendSignedTransaction(raw) |
71 | 77 | .once('transactionHash', function(hash){ |
72 | 78 | document.getElementById("comment").innerHTML = "Transaction sent, please wait til' it is mined" |
73 | 79 | //Arranco el spin y el boton |
|
217 | 223 | var nonce = "0x" + (nonceValue).toString(16); |
218 | 224 | rawtx = { |
219 | 225 | nonce: nonce, |
220 | | - gasPrice: this.web3.utils.toHex(estimatedGas), |
221 | | - gasLimit: this.web3.utils.toHex(GasLimit), |
| 226 | + gasPrice: web3.utils.toHex(estimatedGas), |
| 227 | + gasLimit: web3.utils.toHex(GasLimit), |
222 | 228 | to: contractAddress, |
223 | 229 | data: bytecodeData |
224 | 230 | }; |
|
227 | 233 |
|
228 | 234 | tx.sign(privateKey); |
229 | 235 | var raw = "0x" + tx.serialize().toString("hex"); |
230 | | - this.web3.eth.sendSignedTransaction(raw) |
| 236 | + web3.eth.sendSignedTransaction(raw) |
231 | 237 | .once('transactionHash', function(hash){ |
232 | 238 | document.getElementById("comment").innerHTML = "Transaction sent, please wait til' it is mined"; |
233 | 239 | //Arranco el spin y oculto el boton |
234 | 240 | document.getElementById("spin").style.display = "block"; |
235 | 241 | document.getElementById("loginButton").style.display = "none"; |
236 | 242 | }) |
237 | 243 | .on('error', function(error){ |
238 | | - //console.log(error); |
239 | 244 | document.getElementById("comment").innerHTML = ""; |
240 | 245 | document.getElementById("error").innerHTML = "Error in transaction"; |
241 | 246 | document.getElementById("spin").style.display = "none" |
|
291 | 296 |
|
292 | 297 | function CompleteFields(){ |
293 | 298 | var pathArray; |
| 299 | + browser.runtime.getBackgroundPage().then((get)=>{ |
| 300 | + console.log(get.message); |
| 301 | + document.getElementById("msg").value = get.message; |
| 302 | + }); |
294 | 303 | browser.tabs.query({active: true, currentWindow: true}).then((tabs)=>{ |
295 | 304 | pathArray = tabs[0].url.split('/'); |
296 | 305 | if(pathArray[2] == "twitter.com"){ |
|
345 | 354 |
|
346 | 355 | } |
347 | 356 | } |
348 | | - |
| 357 | + |
349 | 358 | function onError(e) { |
350 | 359 | console.error(e); |
351 | 360 | } |
|
370 | 379 | } |
371 | 380 |
|
372 | 381 | function createWeb3(){ |
373 | | - console.log("func createweb3"); |
374 | 382 | switch (selectedNetwork) { |
375 | 383 | case "Ropsten": |
376 | 384 | web3 = new Web3(); |
|
391 | 399 | var URL = "http://localhost:7545"; |
392 | 400 | web3 = new Web3(new Web3.providers.HttpProvider(URL)); |
393 | 401 | Web3.providers.HttpProvider.prototype.sendAsync = Web3.providers.HttpProvider.prototype.send |
394 | | - contractAddress = "0xd002c4f91e4ad8650455ea5949c6cc1dd2ca0140"; |
| 402 | + contractAddress = "0x9ab56344fd3033d8339eb0b9a6723442adfab3a7"; |
395 | 403 | break; |
396 | 404 | } |
397 | 405 |
|
|
0 commit comments