From cbafb3656da10b3e7683778d0517f36c00e77edd Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Sun, 1 Jul 2018 16:16:00 -0400 Subject: [PATCH] Added sellinf form --- app/js/components/ship.js | 51 ++++++++++++++++++++++++------ app/js/components/shipList.js | 4 +-- app/js/index.js | 4 +-- config/contracts.js | 2 +- contracts/SpaceshipMarketplace.sol | 2 +- 5 files changed, 47 insertions(+), 16 deletions(-) diff --git a/app/js/components/ship.js b/app/js/components/ship.js index f25d3b4..4c140d5 100644 --- a/app/js/components/ship.js +++ b/app/js/components/ship.js @@ -2,8 +2,9 @@ import React, { Component, Fragment } from 'react'; import ReactDOM from 'react-dom'; import EmbarkJS from 'Embark/EmbarkJS'; import web3 from "Embark/web3" -import { Button } from 'react-bootstrap'; +import { Button, FormControl, InputGroup } from 'react-bootstrap'; import SpaceshipToken from 'Embark/contracts/SpaceshipToken'; +import SpaceshipMarketplace from 'Embark/contracts/SpaceshipMarketplace'; import Spinner from 'react-spinkit'; @@ -13,9 +14,16 @@ class Ship extends Component { super(props); this.state = { image: '', - isSubmitting: false + isSubmitting: false, + showSellForm: false, + sellPrice: '' } } + + handleChange(fieldName, value) { + this.state[fieldName] = value; + this.setState(this.state); + } componentDidMount(){ EmbarkJS.onReady((err) => { @@ -32,7 +40,16 @@ class Ship extends Component { }); } - handleClick = () => { + showSellForm = (show) => { + this.setState({'showSellForm': show}); + } + + sellShip = () => { + this.setState({isSubmitting: true}); + this.props.onAction(); + } + + buyShip = () => { const { buySpaceship } = SpaceshipToken.methods; const toSend = buySpaceship(this.props.id) @@ -47,17 +64,14 @@ class Ship extends Component { .then(receipt => { console.log(receipt); - this.props.onBuy(); + this.props.onAction(); // TODO: show success - // TODO: hide ship - return true; }) .catch((err) => { console.error(err); // TODO: show error blockchain - }) .finally(() => { this.setState({isSubmitting: false}); @@ -66,7 +80,7 @@ class Ship extends Component { render(){ const { energy, lasers, shield, price, wallet } = this.props; - const { image, isSubmitting } = this.state; + const { image, isSubmitting, showSellForm } = this.state; const formattedPrice = !wallet ? web3.utils.fromWei(price, "ether") : ''; @@ -80,9 +94,26 @@ class Ship extends Component {
  • Escudo: {shield}
  • { !wallet - ? - : + ? + : (!showSellForm + ? + : '') } + + { showSellForm + ? + + this.handleChange('sellPrice', e.target.value)} /> + Ξ + + + + : '' + } + { isSubmitting ? : '' } ; } diff --git a/app/js/components/shipList.js b/app/js/components/shipList.js index 6118e50..4c8dfbb 100644 --- a/app/js/components/shipList.js +++ b/app/js/components/shipList.js @@ -3,10 +3,10 @@ import ReactDOM from 'react-dom'; import Ship from './ship'; const ShipList = (props) => { - const { list, title, id, wallet, onBuy } = props; + const { list, title, id, wallet, onAction } = props; return

    {title}

    - { list.map((ship, i) => ) } + { list.map((ship, i) => ) }
    ; } diff --git a/app/js/index.js b/app/js/index.js index ac5eb19..51ad31a 100644 --- a/app/js/index.js +++ b/app/js/index.js @@ -94,8 +94,8 @@ class App extends Component { : '' } - - this._loadEverything()} /> + this._loadEverything()} wallet={true} /> + this._loadEverything()} /> ); } } diff --git a/config/contracts.js b/config/contracts.js index 2efc2dc..767124b 100644 --- a/config/contracts.js +++ b/config/contracts.js @@ -39,7 +39,7 @@ module.exports = { "Ownable": { "deploy": false }, "SpaceshipToken": { }, - "SpaceshipMarketPlace": { + "SpaceshipMarketplace": { "args": ["$SpaceshipToken"] } } diff --git a/contracts/SpaceshipMarketplace.sol b/contracts/SpaceshipMarketplace.sol index 322592c..23b70e0 100644 --- a/contracts/SpaceshipMarketplace.sol +++ b/contracts/SpaceshipMarketplace.sol @@ -2,7 +2,7 @@ pragma solidity 0.4.24; import "./SpaceshipToken.sol"; -contract SpaceshipMarketPlace { +contract SpaceshipMarketplace { struct Sale { uint spaceshipId;