Skip to content

Commit

Permalink
Add "add funds" section
Browse files Browse the repository at this point in the history
  • Loading branch information
potomak committed Sep 14, 2017
1 parent b448302 commit 2ccde96
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
49 changes: 49 additions & 0 deletions add-funds.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>issuehunter</title>
<link rel="stylesheet" type="text/css" href="http://issuehunter.github.io/stylesheets/github-markdown.css">
<link rel="stylesheet" type="text/css" href="http://issuehunter.github.io/stylesheets/style.css" />
<script src="https://rawgit.com/ethereum/web3.js/develop/dist/web3.js"></script>
<script src="/src/contract-abi.js"></script>
<script src="/src/app.js"></script>
<script src="/src/add-funds.js"></script>
</head>
<body>
<article class="markdown-body">
<header class="logo">
<h1><span class="blue">issue</span><span class="red">hunter</span></h1>
</header>

<p><a href="/">Back</a></p>

<div>
<label for="account">Account</label>
<select id="account"></select>
</div>
<div>
<label for="issueId">Issue id</label>
<input id="issueId" type="text" placeholder="issue id">
</div>
<div>
<label for="amount">Amount (in Ether)</label>
<input id="amount" type="text" placeholder="0.001">
</div>
<div>
<button onclick="addFunds()">Add funds</button>
</div>

<h3>Campaign</h3>
<p class="add-funds">
Status: <strong id="status"></strong></br>
Block: <strong id="block"></strong></br>
Txn: <strong id="txn"></strong></br>
Issue id: <strong id="infoIssueId"></strong></br>
Funded by: <strong id="funder"></strong></br>
Timestamp: <strong id="timestamp"></strong></br>
Value: <strong id="infoAmount"></strong></br>
</p>
</article>
</body>
</html>
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ <h1><span class="blue">issue</span><span class="red">hunter</span></h1>

<ul>
<li><a href="/create-campaign.html">Create campaign</a></li>
<li><a href="/add-funds.html">Add funds</a></li>
</ul>
</article>
</body>
Expand Down
39 changes: 39 additions & 0 deletions src/add-funds.js
Original file line number Diff line number Diff line change
@@ -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)
})

0 comments on commit 2ccde96

Please sign in to comment.