2018-10-03 09:36:13 -04:00
import React , { Fragment } from 'react' ;
import ReactDOM from 'react-dom' ;
2018-10-03 08:45:56 -04:00
import EmbarkJS from 'Embark/EmbarkJS' ;
2018-10-03 09:36:13 -04:00
import web3 from 'Embark/web3'
2018-10-03 10:13:40 -04:00
import merkleData from './merkle' ;
const { sha3 } = require ( 'ethereumjs-util' ) ;
2018-10-03 12:03:22 -04:00
import SNTGiveaway from 'Embark/contracts/SNTGiveaway' ;
2018-10-03 14:28:33 -04:00
import SNT from 'Embark/contracts/SNT' ;
2018-10-03 12:03:22 -04:00
window . SNTGiveaway = SNTGiveaway ;
2018-10-03 14:28:33 -04:00
window . SNT = SNT ;
2018-10-03 12:03:22 -04:00
2018-10-03 09:36:13 -04:00
class App extends React . Component {
constructor ( props ) {
super ( props ) ;
}
2018-10-03 10:13:40 -04:00
componentDidMount ( ) {
EmbarkJS . onReady ( async ( error ) => {
if ( error ) {
alert ( "Error loading the DAPP" ) ;
return ;
}
2018-10-03 12:03:22 -04:00
const code = location . hash . replace ( "#" ) ; // QR code value, i.e.: a8cd4b33bc
2018-10-03 10:13:40 -04: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 12:03:22 -04:00
2018-10-03 10:13:40 -04: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
// TODO: if result is true the code hasn't been processed. Proceed to verify if the background service will process that transaction
2018-10-03 12:03:22 -04:00
// 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 10:13:40 -04: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,
2018-10-03 12:03:22 -04:00
// 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 10:13:40 -04: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 09:36:13 -04:00
render ( ) {
return < h1 > Hello World < / h 1 >
}
}
2018-10-03 08:45:56 -04:00
2018-10-03 09:36:13 -04:00
ReactDOM . render ( < App > < / A p p > , d o c u m e n t . g e t E l e m e n t B y I d ( ' a p p ' ) ) ;