Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import {Button} from 'react-bootstrap';
  3. import Form from "react-bootstrap/Form";
  4. import crtInterface from "../interface";
  5. import {CONTRACT_ADDRESS, getAccounts} from "../App";
  6. import Web3 from 'web3'
  7.  
  8. class Create extends Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {price: 0, dex_no: 0};
  12. }
  13.  
  14. componentDidMount() {
  15. this._getAccounts = getAccounts().then(
  16. accounts => {
  17. this._getAccounts = null;
  18. this._web3 = new Web3(window.ethereum);
  19. this._account = accounts[0];
  20. }
  21. );
  22. }
  23.  
  24. componentWillUnmount() {
  25. if (this._getAccounts) {
  26. this._getAccounts.cancel();
  27. }
  28.  
  29. if (this._getCards) {
  30. this._getCards.cancel();
  31. }
  32. }
  33.  
  34. handleChange(event) {
  35. this.setState({ [event.target.name] : event.target.value });
  36. }
  37.  
  38. handleSubmit(event) {
  39. console.log('THIS HAS BEEN clicked' + this.state.price + " " + this.state.dex_no);
  40. alert('Pokemon will be created with pokedex_no: ' + this.state.dex_no + ' and price: '+ this.state.price);
  41. event.preventDefault();
  42.  
  43. const crt = new this._web3.eth.Contract(crtInterface, CONTRACT_ADDRESS, {from: this._account})
  44. console.log(crt.options);
  45. crt.methods.createCard(parseInt(this.state.dex_no), parseInt(this.state.price)).send().on('confirmation', () => {
  46. this.refreshCards();
  47. })
  48. }
  49.  
  50. render() {
  51. return (
  52. <div className="container">
  53. <div className="container">
  54. <Form onSubmit={this.handleSubmit.bind(this)}>
  55. <Form.Group controlId="formBasicEmail">
  56. <Form.Label>Pokedex Number (between 1-151)</Form.Label>
  57. <Form.Control type="number" name="dex_no" value={this.state.dex_no} onChange={this.handleChange.bind(this)} placeholder="Enter Pokedex Number"/>
  58. </Form.Group>
  59.  
  60. <Form.Group controlId="formBasicPassword">
  61. <Form.Label>Price of the Pokemon</Form.Label>
  62. <Form.Control type="number" name="price" value={this.state.price} onChange={this.handleChange.bind(this)} placeholder="Price"/>
  63. </Form.Group>
  64. <Button variant="primary" type="submit">
  65. Create
  66. </Button>
  67. </Form>
  68. </div>
  69. <div className="container" style={{'paddingTop':'40px'}}>
  70. <Button variant="primary" size="lg">
  71. Randomly Generate 100 Pokemon
  72. </Button>
  73. </div>
  74. </div>
  75. )
  76. }
  77. }
  78.  
  79. export default Create;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement