diff --git a/src/components/admin-lte/tokens/index.js b/src/components/admin-lte/tokens/index.js index a373655..8ee83f0 100644 --- a/src/components/admin-lte/tokens/index.js +++ b/src/components/admin-lte/tokens/index.js @@ -3,7 +3,6 @@ import PropTypes from 'prop-types' import { Content, Row, Col, Box, Button } from 'adminlte-2-react' import TokenCard from './token-card' import TokenModal from './token-modal' -import SellModal from './sell-modal' import Spinner from '../../../images/loader.gif' // import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import SendTokens from './send-tokens' @@ -22,7 +21,6 @@ class Tokens extends React.Component { tokens: [], selectedTokenToView: '', showModal: false, - showSellModal: false, inFetch: true, errMsg: '', selectedTokenToSend: '', @@ -54,7 +52,7 @@ class Tokens extends React.Component { {_this.state.txId} @@ -106,7 +104,6 @@ class Tokens extends React.Component { id={`token-${i}`} token={val} showToken={_this.showToken} - showSellModal={_this.showSellModal} selectToken={_this.selectToken} /> @@ -132,23 +129,12 @@ class Tokens extends React.Component { show={_this.state.showModal} explorerURL={_this.state.explorerURL} /> - - > ) } setTxId (txId = null) { + console.log(`Setting txid to ${txId}`) _this.setState({ txId: txId }) @@ -217,14 +203,6 @@ class Tokens extends React.Component { _this.onHandleToggleModal() } - // This is called by the token-card when the 'Sell' button is clicked. - showSellModal (selectedTokenToView) { - _this.setState({ - selectedTokenToView - }) - _this.onHandleToggleSellModal() - } - selectToken (selectedTokenToSend) { _this.setState({ selectedTokenToSend @@ -244,15 +222,6 @@ class Tokens extends React.Component { } } - onHandleToggleSellModal (refresh = null) { - _this.setState({ - showSellModal: !_this.state.showSellModal - }) - if (refresh) { - _this.handleGetTokens(true) - } - } - handleError (error) { let errMsg = '' if (error.message) { @@ -296,9 +265,9 @@ class Tokens extends React.Component { let explorerURL if (bchjs.restURL.includes('abc.fullstack')) { - explorerURL = 'https://explorer.be.cash/tx' + explorerURL = 'https://explorer.be.cash/tx/' } else { - explorerURL = 'https://blockchair.com/bitcoin-cash/transaction' + explorerURL = 'https://token.fullstack.cash/transactions/?txid=' } _this.setState({ explorerURL diff --git a/src/components/admin-lte/tokens/sell-modal.js b/src/components/admin-lte/tokens/sell-modal.js deleted file mode 100644 index 068013b..0000000 --- a/src/components/admin-lte/tokens/sell-modal.js +++ /dev/null @@ -1,429 +0,0 @@ -/* - This modal controlls the selling of tokens. - It was adapted from token-modal.js and contains references to 'burn' tokens. -*/ - -// Global npm libraries -import React from 'react' -import PropTypes from 'prop-types' -import { Content, Row, Col, Box, Button, Inputs } from 'adminlte-2-react' -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import axios from 'axios' - -// Local libraries -import './token.css' -const siteConfig = require('../../site-config') - -let _this -const { Text } = Inputs - -class SellModal extends React.Component { - constructor (props) { - super(props) - _this = this - this.state = { - copySuccess: '', - isBurnView: false, - txId: '', - errMsg: '', - inFetch: false, - sellQty: 1, - pricePerToken: 0.02 - } - - this.modalFooter = ( - <> - - - > - ) - - this.confirmFooter = ( - <> - this.sellTokens(false)} /> - this.sellTokens(true)} - /> - > - ) - - this.onDoneFooter = ( - <> - this.sellTokens(false)} - /> - > - ) - } - - render () { - const token = _this.props.token - - return ( - <> - - - - - {_this.state.isBurnView && !_this.state.txId && ( - - - Are you sure you want to sell {`${this.state.sellQty} `} - tokens at {`$${this.state.pricePerToken} `} per token? - - - )} - - {_this.state.isBurnView && _this.state.txId && ( - - Order Submitted - P2WDB entry CID: - - {_this.state.txId} - - - )} - - {_this.state.isBurnView && _this.state.errMsg && ( - - {_this.state.errMsg} - - )} - - {!_this.state.isBurnView && ( - - - - - - - - - TokenId: - - - {token.tokenId} - - - {_this.state.copySuccess === 'tokenId' - ? ( - - Copied! - - ) - : ( - - _this.copyToClipBoard('tokenId')} - icon='copy' - /> - )} - - - - - - - - - - Ticker: - - - {token.ticker} - - - - - - - - - - Balance: - - - {token.qty} - - - - - - - - - - Sell Qty: - - - - - - - - - - - - - Price PerToken (USD): - - - - - - - - - - - - )} - - - - > - ) - } - - // Update the quantity of tokens to sell - handleSellQty (event) { - const value = event.target.value - // console.log('value: ', value) - - _this.setState({ - sellQty: parseFloat(value) - }) - - // console.log('_this.state.sellQty: ', _this.state.sellQty) - } - - handlePricePerToken (event) { - const value = event.target.value - // console.log('value: ', value) - - _this.setState({ - pricePerToken: parseFloat(value) - }) - } - - // copy info to clipboard - copyToClipBoard (key) { - const val = _this.props.token[key] - const textArea = document.createElement('textarea') - textArea.value = val // copyText.textContent; - document.body.appendChild(textArea) - textArea.select() - document.execCommand('Copy') - textArea.remove() - - _this.handleCopySuccess(key) - } - - handleCopySuccess (key) { - _this.setState({ - copySuccess: key - }) - setTimeout(() => { - _this.setState({ - copySuccess: '' - }) - }, 1000) - } - - // 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)) { - alert('Token quantity must be a number.') - return - } - if (isNaN(_this.state.pricePerToken)) { - alert('Price per token must be a number.') - return - } - - _this.setState({ - isBurnView: true - }) - } - - handleModal () { - // if txId exist refresh tokens on close - _this.props.handleOnHide(_this.state.txId) - - setTimeout(() => { - _this.setState({ - isBurnView: false, - txId: '', - errMsg: '', - inFetch: false - }) - }, 200) - } - - async sellTokens (isConfirmed) { - try { - // Dismiss - if (!isConfirmed) { - _this.handleModal() - return - } - - console.log('Putting in order to sell tokens...') - - // Throw up spinny-waiting-gif - _this.setState({ - inFetch: true - }) - - const { bchWallet, token } = _this.props - console.log('token: ', token) - - // Error if trying to sell more tokens than the wallet holds. - 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.`) - } - - console.log(`bch-dex server: ${siteConfig.bchDexUrl}`) - - // Convert the dollar amount of tokens to sats. - const bchSpotPrice = await bchWallet.getUsd() - console.log('bchSpotPrice: ', bchSpotPrice) - const bchPerToken = _this.state.pricePerToken / bchSpotPrice - console.log('bchPerToken: ', bchPerToken) - const satsPerToken = Math.floor(bchWallet.bchjs.BitcoinCash.toSatoshi(bchPerToken)) - console.log('satsPerToken: ', satsPerToken) - - const orderObj = { - order: { - lokadId: 'SWP', - messageType: 1, - messageClass: 1, - tokenId: token.tokenId, - buyOrSell: 'sell', - numTokens: _this.state.sellQty, - rateInBaseUnit: satsPerToken, - minUnitsToExchange: satsPerToken * _this.state.sellQty - } - } - - const result = await axios.post(`${siteConfig.bchDexUrl}/order`, orderObj) - console.log('result.data: ', result.data) - - // console.log('starting sleep') - // await bchWallet.bchjs.Util.sleep(5000) - // console.log('ended sleep') - - // Remove spinny-waiting-gif and display the TXID of the transaction. - _this.setState({ - txId: result.data.hash, - inFetch: false - }) - } catch (error) { - console.warn(error) - _this.setState({ - errMsg: error.message, - inFetch: false - }) - } - } - - // Deprecated. This handled the burn API call. - async handleBurnAll (isConfirmed) { - try { - // Dismiss - if (!isConfirmed) { - _this.handleModal() - return - } - - /** - * BURN ALL - * - */ - _this.setState({ - inFetch: true - }) - const { bchWallet, token } = _this.props - - const result = await bchWallet.burnAll(token.tokenId) - console.log('burn txid: ', result) - _this.setState({ - txId: result, - inFetch: false - }) - } catch (error) { - console.warn(error) - _this.setState({ - errMsg: error.message, - inFetch: false - }) - } - } -} - -SellModal.propTypes = { - token: PropTypes.object.isRequired, - show: PropTypes.bool.isRequired, - handleOnHide: PropTypes.func.isRequired, - bchWallet: PropTypes.object, // get minimal-slp-wallet instance - explorerURL: PropTypes.string -} - -export default SellModal diff --git a/src/components/admin-lte/tokens/send-tokens.js b/src/components/admin-lte/tokens/send-tokens.js index 4474ede..4f616c1 100644 --- a/src/components/admin-lte/tokens/send-tokens.js +++ b/src/components/admin-lte/tokens/send-tokens.js @@ -102,7 +102,7 @@ class SendTokens extends React.Component { {_this.state.errMsg && ( {_this.state.errMsg} )} - {/* {_this.state.txId && ( + {_this.state.txId && ( Transaction ID: - )} */} + )} {name && ( Selected Token : {name} @@ -216,16 +216,16 @@ class SendTokens extends React.Component { // Send token. const result = await bchWalletLib.sendTokens(receiver, 5.0) - // console.log('result: ', result) + console.log('txid: ', result) if (siteConfig.interface === 'consumer-api') { _this.setState({ - txId: result.txid, + txId: result, inFetch: false }) // Set the transaction ID in Tokens state - _this.props.setTxId(result.txid) + _this.props.setTxId(result) } else { _this.setState({ txId: result, diff --git a/src/components/admin-lte/tokens/token-card.js b/src/components/admin-lte/tokens/token-card.js index c35d730..75578bb 100644 --- a/src/components/admin-lte/tokens/token-card.js +++ b/src/components/admin-lte/tokens/token-card.js @@ -44,7 +44,7 @@ class TokenCard extends React.Component { - + - - { - _this.props.showSellModal(token) - }} - /> - - - +
- Are you sure you want to sell {`${this.state.sellQty} `} - tokens at {`$${this.state.pricePerToken} `} per token? -
Order Submitted
P2WDB entry CID:
{_this.state.errMsg}
Transaction ID: