From 2ccde962dc8b29974ec1583f59939d0325a45118 Mon Sep 17 00:00:00 2001 From: Giovanni Cappellotto Date: Wed, 13 Sep 2017 20:08:47 -0400 Subject: [PATCH] Add "add funds" section --- add-funds.html | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 1 + src/add-funds.js | 39 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 add-funds.html create mode 100644 src/add-funds.js diff --git a/add-funds.html b/add-funds.html new file mode 100644 index 0000000..3f37b81 --- /dev/null +++ b/add-funds.html @@ -0,0 +1,49 @@ + + + + + issuehunter + + + + + + + + +
+ + +

Back

+ +
+ + +
+
+ + +
+
+ + +
+
+ +
+ +

Campaign

+

+ Status:
+ Block:
+ Txn:
+ Issue id:
+ Funded by:
+ Timestamp:
+ Value:
+

+
+ + diff --git a/index.html b/index.html index 7910db5..6c4e1b7 100644 --- a/index.html +++ b/index.html @@ -27,6 +27,7 @@

issuehunter

diff --git a/src/add-funds.js b/src/add-funds.js new file mode 100644 index 0000000..c8499f5 --- /dev/null +++ b/src/add-funds.js @@ -0,0 +1,39 @@ +web3.eth.getAccounts(function (err, accounts) { + if (accounts && accounts.length > 0) { + accounts.forEach(function (account) { + var accountOption = document.createElement("option") + accountOption.innerHTML = account + accountOption.value = account + document.getElementById("account").appendChild(accountOption) + }) + } else { + alert("Connect an account") + } +}) + +function addFunds() { + var account = document.querySelector("#account").value + var issueId = document.querySelector("#issueId").value + var amount = document.querySelector("#amount").value + issueHunter.fund(issueId, {from: account, value: web3.toWei(amount)}, function (err, res) { + if (err) { + alert("Error: " + err) + } else { + document.querySelector("#issueId").value = "" + document.querySelector("#amount").value = "" + document.querySelector(".add-funds #status").innerText = "Waiting for confirmation..." + } + }) +} + +// TODO: listen for CampaignFunded events for a specific issue id +issueHunter.CampaignFunded().watch(function (err, event) { + console.log(event) + document.querySelector(".add-funds #status").innerText = "Confirmed" + document.querySelector(".add-funds #block").innerText = event.blockHash + document.querySelector(".add-funds #txn").innerText = event.transactionHash + document.querySelector(".add-funds #infoIssueId").innerText = web3.toAscii(event.args.issueId) + document.querySelector(".add-funds #funder").innerText = event.args.funder + document.querySelector(".add-funds #timestamp").innerText = Date(event.args.timestamp) + document.querySelector(".add-funds #infoAmount").innerText = web3.fromWei(event.args.amount) +})