Skip to content

Commit

Permalink
Merge pull request #11 from ryjo1026/feature-bidding
Browse files Browse the repository at this point in the history
Completed Bid Button
  • Loading branch information
ryjo1026 authored Jun 18, 2018
2 parents 45f687a + 6f35990 commit 87cfbaa
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
keys.json
yarn-error.log

### macOS ###
Expand Down
6 changes: 3 additions & 3 deletions build/contracts/AssetTracker.json
Original file line number Diff line number Diff line change
Expand Up @@ -24190,10 +24190,10 @@
"1515": {
"events": {},
"links": {},
"address": "0x8b78cd6b7aae0b56e924d261497cccfb066433a3",
"transactionHash": "0x6f4774c833e1ffc74fdbf33dd18d38adbd381028b1b93218eb93fee5aaffdb86"
"address": "0x533e7693b92e0c77cd6c148dcbcc92f47ebbf980",
"transactionHash": "0x03afccd571c9f823b5e9567fe99e0f03a814b9416f80ad5280bc1f29c02dda64"
}
},
"schemaVersion": "2.0.0",
"updatedAt": "2018-06-15T14:16:05.675Z"
"updatedAt": "2018-06-18T08:54:52.197Z"
}
6 changes: 3 additions & 3 deletions build/contracts/Migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -1378,10 +1378,10 @@
"1515": {
"events": {},
"links": {},
"address": "0xb81c028f0e1bc95acd1eef13ebc85eddf1576717",
"transactionHash": "0x66bb05af885252d081b2890bed721730336a1f25e62e7d0fa538cabb307e65ab"
"address": "0x2681c87b84ef4106f664d946e1b9d05d0362642c",
"transactionHash": "0xa9659801f3d61b69cae7484a270a95d9e69f2dd1d8736bed9e7cbf13eac8f400"
}
},
"schemaVersion": "2.0.0",
"updatedAt": "2018-06-15T14:16:05.665Z"
"updatedAt": "2018-06-18T08:54:52.185Z"
}
2 changes: 1 addition & 1 deletion src/components/Common/Loading.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ export default function Loading({error}) {
);
}
Loading.propTypes = {
error: PropTypes.string.isRequired,
error: PropTypes.object.isRequired,
};
2 changes: 1 addition & 1 deletion src/components/Common/WithWeb3.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function withWeb3(Component) {
checkConnectionStatus() {
let network = web3.currentProvider.publicConfigStore._state.networkVersion;
if (network === '1515') {
contractAddress = '0x8b78cd6b7aae0b56e924d261497cccfb066433a3';
contractAddress = '0x533e7693b92e0c77cd6c148dcbcc92f47ebbf980';
} else {
contractAddress = '0xf02989fe46646f6c45d22d08d5384ae6c515673d';
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/Manage/ManageContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ class ManageContiner extends React.Component {
}

getDataFromDevice(device, id) {
// Conver minPrice out of Wei
// Conver amounts out of Wei
let minPriceEther = device[3] / 1000000000000000000;
let highestBidEther = device[4] / 1000000000000000000;
return {
id: id,
name: device[0],
useLength: device[1].toString(),
location: device[2],
minPrice: minPriceEther.toString(),
highestBid: device[4].toString(),
highestBid: highestBidEther.toString(),
status: device[5],
};
}
Expand Down
11 changes: 9 additions & 2 deletions src/components/Register/RegisterLocationPicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import PropTypes from 'prop-types';
import {compose, withProps, lifecycle} from 'recompose';
import {withScriptjs, withGoogleMap, GoogleMap, Marker} from 'react-google-maps';

let keys = {};
try {
keys = require('./keys.json');
} catch (error) {
keys['GOOGLE_MAPS'] =
'https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,drawing,places';
}

// TODO use best practices instead of recompose (react-google-maps docs are very sloppy)
export default class RegisterLocationPicker extends React.Component {
constructor(props, context) {
Expand All @@ -16,8 +24,7 @@ export default class RegisterLocationPicker extends React.Component {

this.MapComponent = compose(
withProps({
googleMapURL:
'https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,drawing,places',
googleMapURL: keys.GOOGLE_MAPS,
loadingElement: <div style={{height: '100%'}}/>,
containerElement: <div style={{height: '600px'}}/>,
mapElement: <div style={{height: '100%'}}/>,
Expand Down
23 changes: 18 additions & 5 deletions src/components/Search/SearchContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ export default class SearchContainer extends React.Component {
}

handleBidAmountChange = (event, device) => {
if (event.target.value >= device.minPrice &&
device.status) {
if (event.target.value >= device.minPrice
&& event.target.value >= device.highestBid
&& device.status) {
this.setState({
bidAmount: event.target.value,
submitDisabled: false,
Expand All @@ -106,17 +107,29 @@ export default class SearchContainer extends React.Component {
}
}

handleSubmitClicked = () => {
const {account, contract, contractAddress} = this.props;
contract.at(contractAddress).then((at) => {
let device = this.getSelectedDevice();
let bidAmountWei = this.state.bidAmount * 1000000000000000000;
at.makeBid(device.name, {
from: account,
value: bidAmountWei});
});
}

// Takes the array returned from the solidity function an turns it into an object
getDataFromDevice(device, id) {
// Conver minPrice out of Wei
// Conver amounts out of Wei
let minPriceEther = device[3] / 1000000000000000000;
let highestBidEther = device[4] / 1000000000000000000;
return {
id: id,
name: device[0],
useLength: device[1].toString(),
location: device[2],
minPrice: minPriceEther.toString(),
highestBid: device[4].toString(),
highestBid: highestBidEther.toString(),
status: device[5],
};
}
Expand All @@ -138,7 +151,6 @@ export default class SearchContainer extends React.Component {
this.setState({
data: data,
});
console.log(data);
});
});
}
Expand Down Expand Up @@ -167,6 +179,7 @@ export default class SearchContainer extends React.Component {
deviceData = {this.getSelectedDevice()}
shortAccount = {this.getShortAccount()}
onBidAmountChange = {this.handleBidAmountChange}
onSubmitClicked = {this.handleSubmitClicked}
submitDisabled = {this.state.submitDisabled}
bidDisabled = {this.state.bidDisabled}
bidAmount = {this.state.bidAmount}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Search/SearchDeviceInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class SearchDeviceInfo extends React.Component {
{device.name}
</Typography>
<Typography variant="subheading" color="textSecondary" align="left">
Minimum Bid Price: {device.minPrice} ether
Current Bid: {device.highestBid} ether
</Typography>
<TextField
id="ticket-amount"
Expand All @@ -57,6 +57,7 @@ export default class SearchDeviceInfo extends React.Component {
<CardActions style={{marginLeft: '25px', marginBottom: '25px'}}>
<Button variant="raised" color="primary"
disabled = {this.props.submitDisabled}
onClick ={this.props.onSubmitClicked}
style={{marginTop: '25px', textTransform: 'none'}}>
Bid {this.props.bidAmount} ether
with account {this.props.shortAccount}
Expand All @@ -67,6 +68,7 @@ export default class SearchDeviceInfo extends React.Component {
}
}
SearchDeviceInfo.propTypes = {
onSubmitClicked: PropTypes.func.isRequired,
submitDisabled: PropTypes.bool.isRequired,
bidDisabled: PropTypes.bool.isRequired,
shortAccount: PropTypes.string.isRequired,
Expand Down
4 changes: 4 additions & 0 deletions src/components/Search/SearchTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default class SearchTable extends React.Component {
this.columnData = [
{id: 'deviceName', numeric: false, disablePadding: false, label: 'Device Name'},
{id: 'minPrice', numeric: true, disablePadding: false, label: 'Minimum Bid (ether)'},
{id: 'highestBid', numeric: true, disablePadding: false, label: 'Current Bid (ether)'},
{id: 'status', numeric: false, disablePadding: false, label: 'Status'},
];

Expand Down Expand Up @@ -93,6 +94,9 @@ export default class SearchTable extends React.Component {
<TableCell numeric>
{n.minPrice}
</TableCell>
<TableCell numeric>
{n.highestBid}
</TableCell>
<TableCell >
<div style={statusStyle}>{statusText}</div>
</TableCell>
Expand Down

0 comments on commit 87cfbaa

Please sign in to comment.