forked from UMAprotocol/protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,562 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Vote Coin</title> | ||
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'> | ||
<script src="./app.js"></script> | ||
</head> | ||
<body> | ||
<h1>US to ETH</h1> | ||
<p>The current ETH to USD conversion is listed at <span id="price"></span></p> | ||
|
||
<br> | ||
<h1>Vote</h1> | ||
<br><br><button id="send" onclick="App.voteYes()">This is correct</button> | ||
<br><br><button id="send" onclick="App.voteNo()">This is incorrect</button> | ||
<br><br> | ||
<span id="status"></span> | ||
<br> | ||
<span class="hint"><strong>Hint:</strong> open the browser developer console to view any errors and warnings.</span> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Import the page's CSS. Webpack will know what to do with it. | ||
import '../styles/app.css' | ||
|
||
// Import libraries we need. | ||
import { | ||
default as Web3 | ||
} from 'web3' | ||
import { | ||
default as contract | ||
} from 'truffle-contract' | ||
|
||
// Import our contract artifacts and turn them into usable abstractions. | ||
import voteCoinArtifact from '../../build/contracts/VoteCoin.json' | ||
|
||
// MetaCoin is our usable abstraction, which we'll use through the code below. | ||
const VoteCoin = contract(voteCoinArtifact) | ||
|
||
// The following code is simple to show off interacting with your contracts. | ||
// As your needs grow you will likely need to change its form and structure. | ||
// For application bootstrapping, check out window.addEventListener below. | ||
let accounts | ||
let account | ||
|
||
const App = { | ||
start: function() { | ||
const self = this | ||
// Bootstrap the MetaCoin abstraction for Use. | ||
VoteCoin.setProvider(web3.currentProvider) | ||
|
||
// Get the initial account balance so it can be displayed. | ||
web3.eth.getAccounts(function(err, accs) { | ||
if (err != null) { | ||
alert('There was an error fetching your accounts.') | ||
return | ||
} | ||
|
||
if (accs.length === 0) { | ||
alert("Couldn't get any accounts! Make sure your Ethereum client is configured correctly.") | ||
return | ||
} | ||
|
||
accounts = accs | ||
account = accounts[0] | ||
|
||
self.fetchPrice() | ||
// Also need call to function that updates prices on page here | ||
}) | ||
}, | ||
|
||
setStatus: function(message) { | ||
const status = document.getElementById('status') | ||
status.innerHTML = message | ||
}, | ||
|
||
fetchPrice: function() { | ||
VoteCoin.deployed().then(function(instance) { | ||
return instance.ETHUSD.call() | ||
}).then(function(value) { | ||
const balanceElement = document.getElementById('price') | ||
balanceElement.innerHTML = value | ||
console.log("We have a new price!", value) | ||
}).catch(function(e) { | ||
console.log(e) | ||
this.setStatus('Error getting balance; see log.') | ||
}) | ||
}, | ||
|
||
voteYes: function() { | ||
VoteCoin.deployed().then(function(instance) { | ||
return instance.currVoteId.call() | ||
}).then(function(value) {return value.toNumber()}).then(function(voteId) { | ||
VoteCoin.deployed().then(function(instance) { | ||
instance.vote(voteId, 1, {from: account}) | ||
}) | ||
}).catch(function(e) { | ||
console.log(e) | ||
}) | ||
}, | ||
|
||
voteNo: function() { | ||
VoteCoin.deployed().then(function(instance) { | ||
return instance.currVoteId.call() | ||
}).then(function(value) {return value.toNumber()}).then(function(voteId) { | ||
VoteCoin.deployed().then(function(instance) { | ||
instance.vote(voteId, 0, {from: account}) | ||
}) | ||
}).catch(function(e) { | ||
console.log(e) | ||
}) | ||
}, | ||
|
||
} | ||
|
||
window.App = App | ||
|
||
window.addEventListener('load', function() { | ||
// Checking if Web3 has been injected by the browser (Mist/MetaMask) | ||
if (typeof web3 !== 'undefined') { | ||
console.warn( | ||
'Using web3 detected from external source.' + | ||
' If you find that your accounts don\'t appear or you have 0 MetaCoin,' + | ||
' ensure you\'ve configured that source properly.' + | ||
' If using MetaMask, see the following link.' + | ||
' Feel free to delete this warning. :)' + | ||
' http://truffleframework.com/tutorials/truffle-and-metamask' | ||
) | ||
// Use Mist/MetaMask's provider | ||
window.web3 = new Web3(web3.currentProvider) | ||
} else { | ||
console.warn( | ||
'No web3 detected. Falling back to http://127.0.0.1:9545.' + | ||
' You should remove this fallback when you deploy live, as it\'s inherently insecure.' + | ||
' Consider switching to Metamask for development.' + | ||
' More info here: http://truffleframework.com/tutorials/truffle-and-metamask' | ||
) | ||
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail) | ||
window.web3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:9545')) | ||
} | ||
|
||
App.start() | ||
}) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.