hackathon-registration-dapp/app/js/index.js

70 lines
3.0 KiB
JavaScript
Raw Normal View History

2018-10-03 13:36:13 +00:00
import React, { Fragment } from 'react';
import ReactDOM from 'react-dom';
2018-10-03 12:45:56 +00:00
import EmbarkJS from 'Embark/EmbarkJS';
2018-10-03 13:36:13 +00:00
import web3 from 'Embark/web3'
2018-10-03 14:13:40 +00:00
import merkleData from './merkle';
const { sha3 } = require('ethereumjs-util');
import SNTGiveaway from 'Embark/contracts/SNTGiveaway';
2018-10-03 18:28:33 +00:00
import SNT from 'Embark/contracts/SNT';
window.SNTGiveaway = SNTGiveaway;
2018-10-03 18:28:33 +00:00
window.SNT = SNT;
2018-10-03 13:36:13 +00:00
class App extends React.Component {
constructor(props) {
super(props);
}
2018-10-03 14:13:40 +00:00
componentDidMount(){
EmbarkJS.onReady(async (error) => {
if(error){
alert("Error loading the DAPP");
return;
}
const code = location.hash.replace("#"); // QR code value, i.e.: a8cd4b33bc
2018-10-03 14:13:40 +00:00
const hashedCode = sha3(code); // Code converted to format used on merkletree
const accounts = await web3.eth.getAccounts();
web3.eth.defaultAccount = accounts[0];
2018-10-03 14:13:40 +00:00
// TODO: if code is empty show error or something
// TODO: Build merkle tree using merkledata.elements (see https://github.com/ameensol/merkle-tree-solidity)
// TODO: Call the contract function validRequest(bytes32[] _proof, bytes5 _code, address _dest)
// The values to send are, a merkle proof, code, and the web3.eth.defaultAccount.
// The merkle proof function uses a bytes32 hash, so you need to use hashedCode
// TODO: if result is false, show error or something because the code is invalid or has been used
2018-10-03 18:31:30 +00:00
// TODO: you may use the sentToAddress(web3.eth.defaultAddress) or codeUsed("0x" + code) to identify as well if the code / address has been used before, and redirect dierctly to ENS
2018-10-03 14:13:40 +00:00
// TODO: if result is true the code hasn't been processed. Proceed to verify if the background service will process that transaction
// TODO: use orbit db, check if exist a value in a orbitdb keyvalue store `status-hackathon-transactions2` Address of db can be seen by executing node server/main.js
2018-10-03 14:13:40 +00:00
// the key to use is the code
// TODO: if a value exists, the background service will process this code, show a message indicating that transaction is being processed
// TODO: if it doesnt,
// let's add a value to the status-fund-requests2 orbitdb log store, with a json containing the data used to invoke the validRequest contract function (all values must be strings): {code, proof: proof: proof.map(x => '0x' + x.toString('hex')), address}
2018-10-03 14:13:40 +00:00
// show a message indicating that transaction is being processed
//
// We'll deal with the redirect to ENS Registration after the previous code is implemented, and the background service is done processing the transaction
});
}
2018-10-03 13:36:13 +00:00
render(){
return <h1>Hello World</h1>
}
}
2018-10-03 12:45:56 +00:00
2018-10-03 13:36:13 +00:00
ReactDOM.render(<App></App>, document.getElementById('app'));