From 571bf7b7a2d6573f26dd3e758e4bc4bfadf14dfd Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Sat, 28 May 2022 12:46:28 -0700 Subject: [PATCH] fix(dex): Removing dex features that made it into main repo --- src/components/admin-lte/orders/details.js | 188 ------------ src/components/admin-lte/orders/index.js | 322 --------------------- src/components/admin-lte/orders/orders.css | 29 -- src/components/menu-components.js | 6 - 4 files changed, 545 deletions(-) delete mode 100644 src/components/admin-lte/orders/details.js delete mode 100644 src/components/admin-lte/orders/index.js delete mode 100644 src/components/admin-lte/orders/orders.css diff --git a/src/components/admin-lte/orders/details.js b/src/components/admin-lte/orders/details.js deleted file mode 100644 index e70f009..0000000 --- a/src/components/admin-lte/orders/details.js +++ /dev/null @@ -1,188 +0,0 @@ -import React from 'react' -import PropTypes from 'prop-types' -import { Row, Col, Box, Button } from 'adminlte-2-react' -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -// import JSONPretty from "react-json-pretty" - -let _this -class Details extends React.Component { - constructor (props) { - super(props) - - _this = this - - this.state = { - order: {} - } - } - - render () { - const { order } = _this.state - return ( - <> - - - - - -

- - Details -

- {order._id && ( - -

- Message Type: - {order.messageType} -

-

- Message Class: - {order.messageClass} -

-

- Create At: - {new Date(order.localTimestamp).toLocaleString()} -

-

- ID: - {order._id} -

-

- Token Id: - {order.tokenId} - -

-

- Order Type : - {order.buyOrSell} - -

-

- Rate in Stats : - {order.rateInSats} - -

-

- Min. Sats to Exchange : - {order.minSatsToExchange} - -

-

- Num Tokens: - {order.numTokens} - -

-

- Utxo TxId: - {order.utxoTxid} - -

-

- Utxo Vout: - {order.utxoVout} - -

-

- Tx Hex : - {order.txHex} - -

- -

- Timestamp : - {order.timestamp} - -

-

- LocalTimestamp : - {order.localTimestamp} - -

-

- p2wdbHash : - {order.p2wdbHash} - -

-

- Offer Hash : - {order.offerHash} - -

-

- Address References : - {order.addrReferences} - -

-
- )} - - -
-
- -
-
- -
- - ) - } - - componentDidMount () { - _this.handleData() - } - - componentDidUpdate () { - if (_this.props.order._id !== _this.state.order._id) { - _this.handleData() - } - } - - handleData () { - try { - const { order } = _this.props - console.log('order', order) - _this.setState({ - order: order.data - }) - } catch (err) { - console.warn('Error in handleData()', err) - } - } - - handleClose () { - _this.props.onClose() - } - - // Detects if the input is a string and converts to json object - isJson (data) { - try { - JSON.parse(data) - return true - } catch (error) { - return false - } - } -} -Details.propTypes = { - order: PropTypes.object, - onClose: PropTypes.func, - onTake: PropTypes.func -} -export default Details diff --git a/src/components/admin-lte/orders/index.js b/src/components/admin-lte/orders/index.js deleted file mode 100644 index 85fd126..0000000 --- a/src/components/admin-lte/orders/index.js +++ /dev/null @@ -1,322 +0,0 @@ -import React from '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 axios = require('axios').default -const siteConfig = require('../../site-config') - -const SERVER = siteConfig.bchDexUrl - -// const EXPLORER_URL = 'https://explorer.bitcoin.com/bch/tx/' - -let _this -class Orders extends React.Component { - constructor (props) { - super(props) - _this = this - this.state = { - showEntry: false, - data: [], - orders: [], - orderData: null, - showTakeModal: false, - takeInput: '' - } - - this.firstColumns = [ - { title: 'Ticker', data: 'ticker' }, - { - title: 'Token Id', - data: 'tokenId', - render: id => ( - {id.subString} - ) - }, - { - title: 'Type', - data: 'buyOrSell' - }, - { - title: 'Offer hash', - data: 'offerHash', - render: hash => ( - {hash.subString} - ) - }, - { title: 'Qty', data: 'qty' }, - { title: 'Sats Each', data: 'satsEach' }, - { title: 'Sats Total', data: 'satsTotal' }, - { title: 'USD Total', data: 'usdTotal' }, - { - title: '', - data: 'take', - // render: order => (order.data.orderStatus === 'posted' - // ? ( - //
- //
- // ) - // :

- // ) - render: order => ( -

-
- ) - } - ] - } - - render () { - const { data, orderData } = _this.state - return ( - <> - - - {orderData && ( - -
- - )} - - - { - console.log(data) - if (data.key === 'hashHandler') { _this.handleHashClick(data) } - - if (data.key === 'takeHandler') { _this.handleTake(data) } - } - }} - /> - - - - - { - _this.state.showTakeModal && ( - -
-
- Loading...
-

Taking the other side of the trade...

-
-
-
- ) - } - - ) - } - - async componentDidMount () { - _this.handleOrders() - - // Get data and update the table - // every 20 seconds - setInterval(() => { - _this.handleOrders() - }, 30000) - } - - async handleOrders () { - const orders = await _this.getOrders() - await _this.generateDataTable(orders) - } - - // REST petition to Get data fron the pw2db - async getOrders () { - try { - // console.log('SERVER: ', SERVER) - - const options = { - method: 'GET', - url: `${SERVER}/offer/list/`, - data: {} - } - const result = await axios.request(options) - // console.log('result.data', result.data) - - _this.setState({ - orders: result.data - }) - - return result.data - } catch (err) { - console.warn('Error in getOrders() ', err) - } - } - - // Generate table content - async generateDataTable (dataArr = []) { - try { - 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.') - return - } - - // Get the spot price for BCH. - const bchSpotPrice = await this.props.bchWallet.getUsd() - - // console.log('bchSpotPrice: ', bchSpotPrice) - - for (let i = 0; i < dataArr.length; i++) { - const order = dataArr[i] - // console.log(`order: ${JSON.stringify(order, null, 2)}`) - - 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)}` - - const row = { - ticker: order.ticker, - tokenId: { - tokenId: order.tokenId, - subString: _this.cutString(order.tokenId) - }, - // createdAt row data - createdAt: new Date(order.timestamp).toLocaleString(), - // Transaction id row data - buyOrSell: order.buyOrSell, - // Hash row data - offerHash: { - key: 'hashHandler', - subString: _this.cutString(order.p2wdbHash), - order: order.p2wdbHash, - data: order - }, - qty: order.numTokens, - satsEach: order.rateInBaseUnit, - satsTotal, - usdTotal, - orderStatus: order.offerStatus, - take: { - key: 'takeHandler', - data: order - } - } - data.push(row) - } - - _this.setState({ data }) - } catch (err) { - console.warn('Error in generateDataTable() ', err) - } - } - - cutString (txid) { - try { - const subTxid = txid.slice(0, 4) - const subTxid2 = txid.slice(-4) - return `${subTxid}...${subTxid2}` - } catch (err) { - console.warn('Error in cutString() ', err) - } - } - - handleHashClick (data) { - try { - // data.isValid = data.isValid.toString() - _this.setState({ - orderData: data - }) - } catch (err) { - _this.setState({ - orderData: null - }) - console.warn('Error in handleHashClick() ', err) - } - } - - handleClose () { - _this.setState({ - orderData: null, - showTakeModal: false - }) - } - - async handleTake (order) { - console.log('handleTake() order: ', order) - - const offerCid = order.data.p2wdbHash - console.log('offerCid: ', offerCid) - - // if (!order.data.status === 'posted') return - - // TODO: Future functionality. - // Throw up a modal to query how much they want to take. - // _this.setState({ - // tankenInput: '', - // showTakeModal: true - // }) - - // Show the modal - _this.setState({ - showTakeModal: true - }) - - const options = { - method: 'POST', - url: `${SERVER}/offer/take/`, - data: { - offerCid - } - } - const result = await axios.request(options) - console.log('result of taking offer: ', result) - - // Hide the modal - _this.setState({ - showTakeModal: false - }) - } - - handleModalInputs (event) { - const value = event.target.value - _this.setState({ - [event.target.name]: value - }) - } -} - -export default Orders diff --git a/src/components/admin-lte/orders/orders.css b/src/components/admin-lte/orders/orders.css deleted file mode 100644 index c102b42..0000000 --- a/src/components/admin-lte/orders/orders.css +++ /dev/null @@ -1,29 +0,0 @@ -.btn-close-entry{ - width: 150px; -} -.action-handler{ - color: #3c8dbc; - cursor: pointer; -} -.details-data-content{ - text-align: left; -} -.take-form-wrapper{ - /* display: flex; - justify-content: center; - flex-direction: column; */ - text-align: center; -} -#OrdersTable> tbody >.odd{ - height: 55px!important; -} -#OrdersTable> tbody > .even{ - height: 55px!important; -} -.take-btn-lg{ - width: 150px; -} -.take-btn-table-wrapper{ - text-align: end; - padding-right: 10px; -} \ No newline at end of file diff --git a/src/components/menu-components.js b/src/components/menu-components.js index c225663..c4c5d0a 100644 --- a/src/components/menu-components.js +++ b/src/components/menu-components.js @@ -5,7 +5,6 @@ import Wallet from './admin-lte/wallet' import Tokens from './admin-lte/tokens' import Configure from './admin-lte/configure' import SendReceive from './admin-lte/send-receive' -import Orders from './admin-lte/orders' const { Item } = Sidebar @@ -13,11 +12,6 @@ const MenuComponents = props => { return [ { active: true, - key: 'Orders', - component: , - menuItem: - }, - { key: 'Tokens', component: , menuItem: (