diff --git a/src/components/admin-lte/orders/index.js b/src/components/admin-lte/orders/index.js index cd457e8..85fd126 100644 --- a/src/components/admin-lte/orders/index.js +++ b/src/components/admin-lte/orders/index.js @@ -1,14 +1,14 @@ import React from 'react' -import { Row, Col, Content, Box, DataTable, Button, Inputs } from 'adminlte-2-react' +import { Row, Col, Content, Box, DataTable, Button } from 'adminlte-2-react' import Details from './details' import './orders.css' import Spinner from '../../../images/loader.gif' -const { Text } = Inputs +// const { Text } = Inputs const axios = require('axios').default const siteConfig = require('../../site-config') -let SERVER = siteConfig.bchDexUrl +const SERVER = siteConfig.bchDexUrl // const EXPLORER_URL = 'https://explorer.bitcoin.com/bch/tx/' @@ -189,8 +189,8 @@ class Orders extends React.Component { const data = [] // console.log(`dataArr: ${JSON.stringify(dataArr, null, 2)}`) - if(!this.props.bchWallet) { - console.log(`BCH wallet is not initialized. Can not calculate price of BCH or tokens.`) + if (!this.props.bchWallet) { + console.log('BCH wallet is not initialized. Can not calculate price of BCH or tokens.') return } @@ -203,7 +203,8 @@ class Orders extends React.Component { const order = dataArr[i] // console.log(`order: ${JSON.stringify(order, null, 2)}`) - const satsTotal = order.numTokens * order.rateInBaseUnit + const satsTotal = Math.ceil(order.numTokens * order.rateInBaseUnit) + console.log(`satsTotal: ${satsTotal}`) let usdTotal = bchSpotPrice * this.props.bchWallet.bchjs.BitcoinCash.toBitcoinCash(satsTotal) usdTotal = `$${this.props.bchWallet.bchjs.Util.floor8(usdTotal)}` diff --git a/src/components/admin-lte/tokens/sell-modal.js b/src/components/admin-lte/tokens/sell-modal.js index a047e6a..068013b 100644 --- a/src/components/admin-lte/tokens/sell-modal.js +++ b/src/components/admin-lte/tokens/sell-modal.js @@ -242,7 +242,7 @@ class SellModal extends React.Component { } // Update the quantity of tokens to sell - handleSellQty(event) { + handleSellQty (event) { const value = event.target.value // console.log('value: ', value) @@ -253,7 +253,7 @@ class SellModal extends React.Component { // console.log('_this.state.sellQty: ', _this.state.sellQty) } - handlePricePerToken(event) { + handlePricePerToken (event) { const value = event.target.value // console.log('value: ', value) @@ -289,11 +289,11 @@ class SellModal extends React.Component { // This is called when the user clicks the 'Sell' button to place their order. handleConfirm () { // Verify that inputs are valid. - if(isNaN(_this.state.sellQty)) { + if (isNaN(_this.state.sellQty)) { alert('Token quantity must be a number.') return } - if(isNaN(_this.state.pricePerToken)) { + if (isNaN(_this.state.pricePerToken)) { alert('Price per token must be a number.') return } @@ -317,7 +317,7 @@ class SellModal extends React.Component { }, 200) } - async sellTokens(isConfirmed) { + async sellTokens (isConfirmed) { try { // Dismiss if (!isConfirmed) { @@ -336,7 +336,7 @@ class SellModal extends React.Component { console.log('token: ', token) // Error if trying to sell more tokens than the wallet holds. - if(token.qty < _this.state.sellQty) { + if (token.qty < _this.state.sellQty) { alert(`Error: The wallet has ${token.qty} tokens, which is less than the ${_this.state.sellQty} tokens you are trying to sell.`) } @@ -345,7 +345,7 @@ class SellModal extends React.Component { // Convert the dollar amount of tokens to sats. const bchSpotPrice = await bchWallet.getUsd() console.log('bchSpotPrice: ', bchSpotPrice) - const bchPerToken = _this.state.pricePerToken/bchSpotPrice + const bchPerToken = _this.state.pricePerToken / bchSpotPrice console.log('bchPerToken: ', bchPerToken) const satsPerToken = Math.floor(bchWallet.bchjs.BitcoinCash.toSatoshi(bchPerToken)) console.log('satsPerToken: ', satsPerToken) @@ -359,12 +359,12 @@ class SellModal extends React.Component { buyOrSell: 'sell', numTokens: _this.state.sellQty, rateInBaseUnit: satsPerToken, - minUnitsToExchange: satsPerToken*_this.state.sellQty, + minUnitsToExchange: satsPerToken * _this.state.sellQty } } const result = await axios.post(`${siteConfig.bchDexUrl}/order`, orderObj) - console.log(`result.data: `, result.data) + console.log('result.data: ', result.data) // console.log('starting sleep') // await bchWallet.bchjs.Util.sleep(5000) @@ -375,7 +375,7 @@ class SellModal extends React.Component { txId: result.data.hash, inFetch: false }) - } catch(error) { + } catch (error) { console.warn(error) _this.setState({ errMsg: error.message, diff --git a/src/components/site-config.js b/src/components/site-config.js index bf1c3e2..35ae1d8 100644 --- a/src/components/site-config.js +++ b/src/components/site-config.js @@ -36,10 +36,12 @@ const config = { } // Attempt to auto-detect the URL for the bch-dex. -if(window && window.document && window.document.domain) { - if(window.document.domain.includes('192.168') || - window.document.domain.includes('localhost')) { - config.bchDexUrl = `http://${window.document.domain}:5700` +if (typeof window !== 'undefined') { + if (window && window.document && window.document.domain) { + if (window.document.domain.includes('192.168') || + window.document.domain.includes('localhost')) { + config.bchDexUrl = `http://${window.document.domain}:5700` + } } }