add trx button

This commit is contained in:
Richard Ramos 2019-08-19 15:50:58 -04:00
parent 67cad5fd47
commit 104c5fd551
1 changed files with 19 additions and 7 deletions

View File

@ -9,7 +9,7 @@ const web3 = new Web3("ws://localhost:8545");
const Escrow = ({escrow}) => {
console.log("Received new escrow property", escrow);
return <ul><li>{escrow.buyer} {escrow.seller} {escrow.escrowId}</li></ul>;
return <ul><li>{escrow.buyer} {escrow.seller} - <b>EscrowID:{escrow.escrowId}</b></li></ul>;
//return <ul>{props.escrows.map((el, i) => <li key={i}>{el.buyer} {el.seller} {el.escrowId}</li>)}</ul>
};
@ -24,20 +24,25 @@ class App extends React.Component {
escrow: null
}
constructor(props){
super(props);
this.EscrowContract = null;
}
componentDidMount(){
(async () => {
let accounts = await web3.eth.getAccounts();
var EscrowContract = await deployContract();
this.EscrowContract = await deployContract();
await EscrowContract.methods.createEscrow(1, accounts[0], accounts[1]).send({from: accounts[0]})
await EscrowContract.methods.createEscrow(1, accounts[1], accounts[2]).send({from: accounts[0]})
await EscrowContract.methods.createEscrow(1, accounts[1], accounts[0]).send({from: accounts[0]})
await EscrowContract.methods.createEscrow(1, accounts[0], accounts[2]).send({from: accounts[0]})
await this.EscrowContract.methods.createEscrow(1, accounts[0], accounts[1]).send({from: accounts[0]})
await this.EscrowContract.methods.createEscrow(1, accounts[1], accounts[2]).send({from: accounts[0]})
await this.EscrowContract.methods.createEscrow(1, accounts[1], accounts[0]).send({from: accounts[0]})
await this.EscrowContract.methods.createEscrow(1, accounts[0], accounts[2]).send({from: accounts[0]})
const eventSyncer = new Phoenix(web3);
eventSyncer.init(() => {
const replayObj = eventSyncer.trackEvent(EscrowContract, 'Created', {filter: {buyer: accounts[0]}, fromBlock: 1});
const replayObj = eventSyncer.trackEvent(this.EscrowContract, 'Created', {filter: {buyer: accounts[0]}, fromBlock: 1});
this.setState({
escrow: replayObj.asObservable()
});
@ -48,10 +53,17 @@ class App extends React.Component {
}
createTrx = async () => {
let accounts = await web3.eth.getAccounts();
await this.EscrowContract.methods.createEscrow(Date.now(), accounts[0], accounts[1]).send({from: accounts[0]})
}
render(){
if(!this.state.escrow) return null;
return <div>
<button onClick={this.createTrx}>Create Trx</button>
{this.state.escrow && <EnhancedEscrow escrow={this.state.escrow} /> }
</div>;
}