Skip to content

Commit

Permalink
fromtend renewed
Browse files Browse the repository at this point in the history
  • Loading branch information
hnamzian committed Jun 9, 2018
1 parent 9dc38aa commit 375f79a
Show file tree
Hide file tree
Showing 5 changed files with 581 additions and 111 deletions.
249 changes: 249 additions & 0 deletions html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="./style.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.2.3/milligram.min.css"> -->
<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<script language="javascript" type="text/javascript" src="./web3/dist/web3.min.js"></script>
<title>Document</title>

</head>
<body>
<!-- <div>
<div id="branding">
<h1>BountyBG</h1>
</div>
<nav>
<ul>
<li class="current"><a href="index.html">CREATE</a></li>
<li><a href="admin.html">SETTINGS</a></li>
<li><a href="token.html">TOKEN</a></li>
</ul>
</nav>
</div> -->

<div class="header">
<a href="#default" class="logo">CompanyLogo</a>
<div class="header-right">
<a class="active" href="#home">CREATE</a>
<a href="#contact">SETTINGS</a>
<a href="#about">TOKEN</a>
</div>
</div>

<!-- <section>
<div class="container">
<div class="row">
<div class="col-25">
<h3>Post Bounty</h3>
</div>
</div>
<div class="row">
<div class="col-25">
<label>Token Address</label>
</div>
<div class="col-75">
<input type="text" id="tokenAddress" placeholder="Token Address">
</div>
</div>
<div class="row">
<div class="col-25">
<label>Poster Address</label>
</div>
<div class="col-75">
<select id="posterAddress"></select>
</div>
</div>
<div class="row">
<div class="col-25">
<label>Bounty Amount</label>
</div>
<div class="col-75">
<input type="number" id="bointyAmount" placeholder="Bounty Amount">
</div>
</div>
<div class="row">
<div class="col-25">
<label>Bounty Id</label>
</div>
<div class="col-75">
<input type="number" id="bountyId" placeholder="Bounty Id">
</div>
</div>
<div class="row">
<div>
<button id="create" class="button">Create</button>
</div>
</div> -->

<!-- <div class="column">
<h3>Admin Panel</h3>
<div class="column">
<div class="row">
<div class="column">
<label>Minimum Bounty</label>
<input type="number" id="minBounty" placeholder="Minimum Bounty">
</div>
<div class="column">
<label>Token Address</label>
<input type="text" id="minFeeTokneAddress" placeholder="Token Address">
</div>
</div>
<button id="setMinBounty">Set Min Bounty</button>
<button id="getMinBounty">Get Min Bounty</button>
</div>
<div class="column">
<div class="row">
<div class="column">
<label><br /></label>
<label>Bounty Fee</label>
<input type="number" id="bountyFee" placeholder="Bounty Fee">
</div>
<div class="column">
<label><br /></label>
<label>Token Address</label>
<input type="text" id="bountyFeeTokenAddress" placeholder="Token Address">
</div>
</div>
<button id="setBountyFee">Set Bounty Fee</button>
<button id="getBountyFee">Get Bounty Fee</button>
</div>
</div> -->
<!-- </div> -->
<!-- </div>
</section> -->

<script>
var bountyABI;
var bountyAddress;
var bountyOwner;
var tokenABI;
var tokenAddress;
var tokenOwner;

var bountyBG;
var token;

var el = function (id) { return document.querySelector(id); };

web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

main()

el("#create").addEventListener("click", async function() {
await createERC20Bounty(el('#posterAddress').value, el('#tokenAddress').value, el('#bountyId').value)
})

el("#setMinBounty").addEventListener("click", async function() {
await setMinBounty(el('#minFeeTokneAddress').value, el('#minBounty').value)
})

el("#getMinBounty").addEventListener("click", async function() {
const minBounty = await getMinBounty(el('#minFeeTokneAddress').value)
console.log(minBounty)
})

el("#setBountyFee").addEventListener("click", async function() {
await setBountyFee(el('#bountyFeeTokenAddress').value, el('#bountyFee').value)
})

el("#getBountyFee").addEventListener("click", async function() {
bountyFee = await getBountyFee(el('#bountyFeeTokenAddress').value)
console.log(bountyFee)
})

function fillPosterAccounts() {
return new Promise((resolve, reject) => {
web3.eth.getAccounts()
.then((accounts) => {
accounts.forEach(address => {
posterAddress.innerHTML += '<option value="' + address + '">'
+ address + '</option>';
})
})
resolve(true);
})
}

function createERC20Bounty(_bountyPoster, _tokenAddress, _bountyId) {
return new Promise((resolve, reject) => {
bountyBG.methods
.createBountyERC20(_bountyId, _tokenAddress)
.send({from: _bountyPoster, gas: 3000000})
.then()
})
}

function readContract() {
return new Promise((resolve, reject) => {
$.getJSON('./deploy/contracts.json', function(data) {
resolve(data)
})
})
}

function setMinBounty(_tokenAddress, _minBounty) {
return new Promise((resolve, reject) => {
bountyBG.methods
.setMinBountyToken(_tokenAddress, _minBounty)
.send({from: bountyOwner, gas: 3000000})
.then()
})
}

function getMinBounty(tokenAddress) {
return new Promise((resolve, reject) => {
bountyBG.methods
.getMinBountyToken(tokenAddress)
.call()
.then(resolve)
})
}

function setBountyFee(_tokenAddress, _bountyFee) {
return new Promise((resolve, reject) => {
bountyBG.methods
.setBountyFeeToken(_tokenAddress, _bountyFee)
.send({from: bountyOwner, gas: 3000000})
.on('error', reject)
.then(resolve)
})
}

function getBountyFee(tokenAddress) {
return new Promise((resolve, reject) => {
bountyBG.methods
.getBountyFeeToken(tokenAddress)
.call()
.then(resolve)
})
}

async function main() {
const data = await readContract();
bountyABI = data['bounty abi'];
bountyAddress = data['bounty address']
bountyOwner = data['bounty owner']
tokenABI = data['token abi']
tokenAddress = data['token address']
tokenOwner = data['token owner']

bountyBG = new web3.eth.Contract(bountyABI, bountyAddress);
token = new web3.eth.Contract(tokenABI, tokenAddress);

await fillPosterAccounts();

$('#bountyFeeTokenAddress').val(tokenAddress)
$('#minFeeTokneAddress').val(tokenAddress)
$('#tokenAddress').val(tokenAddress)

}

</script>
</body>
</html>
Loading

0 comments on commit 375f79a

Please sign in to comment.