add trx button

This commit is contained in:
Richard Ramos 2019-08-19 15:50:58 -04:00
parent 67cad5fd47
commit 104c5fd551

View File

@ -9,7 +9,7 @@ const web3 = new Web3("ws://localhost:8545");
const Escrow = ({escrow}) => { const Escrow = ({escrow}) => {
console.log("Received new escrow property", 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> //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 escrow: null
} }
constructor(props){
super(props);
this.EscrowContract = null;
}
componentDidMount(){ componentDidMount(){
(async () => { (async () => {
let accounts = await web3.eth.getAccounts(); 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 this.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 this.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 this.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[2]).send({from: accounts[0]})
const eventSyncer = new Phoenix(web3); const eventSyncer = new Phoenix(web3);
eventSyncer.init(() => { 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({ this.setState({
escrow: replayObj.asObservable() 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(){ render(){
if(!this.state.escrow) return null; if(!this.state.escrow) return null;
return <div> return <div>
<button onClick={this.createTrx}>Create Trx</button>
{this.state.escrow && <EnhancedEscrow escrow={this.state.escrow} /> } {this.state.escrow && <EnhancedEscrow escrow={this.state.escrow} /> }
</div>; </div>;
} }