diff --git a/src/components/admin-lte/configure/jwt.js b/src/components/admin-lte/configure/jwt.js index 262a70c..747a019 100644 --- a/src/components/admin-lte/configure/jwt.js +++ b/src/components/admin-lte/configure/jwt.js @@ -13,7 +13,7 @@ const { Text } = Inputs let _this class JsonWebTokens extends React.Component { - constructor(props) { + constructor (props) { super(props) _this = this @@ -26,7 +26,7 @@ class JsonWebTokens extends React.Component { _this.BchWallet = BchWallet } - render() { + render () { return ( @@ -70,7 +70,7 @@ class JsonWebTokens extends React.Component { ) } - setJwt() { + setJwt () { const { JWT } = _this.props.walletInfo if (JWT) { const jwtElem = document.getElementById('jwt') @@ -78,36 +78,35 @@ class JsonWebTokens extends React.Component { } } - handleUpdate(event) { + handleUpdate (event) { const value = event.target.value _this.setState({ [event.target.name]: value }) } - async handleUpdateJWT() { + async handleUpdateJWT () { try { const { mnemonic, selectedServer } = _this.props.walletInfo const _interface = _this.props.walletInfo.interface - const apiToken = _this.state.JWT // Update instance with JWT if (mnemonic) { - let bchjsOptions = { apiToken: apiToken } + const bchjsOptions = { apiToken: apiToken } if (selectedServer) { bchjsOptions.restURL = selectedServer } bchjsOptions.interface = _interface - //console.log('bchjs options : ', bchjsOptions) + // console.log('bchjs options : ', bchjsOptions) const bchWalletLib = new _this.BchWallet(mnemonic, bchjsOptions) // Update bchjs instances of minimal-slp-wallet libraries bchWalletLib.tokens.sendBch.bchjs = new bchWalletLib.BCHJS(bchjsOptions) bchWalletLib.tokens.utxos.bchjs = new bchWalletLib.BCHJS(bchjsOptions) - + _this.props.setBchWallet(bchWalletLib) } @@ -124,7 +123,7 @@ class JsonWebTokens extends React.Component { } // Reset form and component state - resetValues() { + resetValues () { _this.setState({ JWT: '', errMsg: '' @@ -133,7 +132,7 @@ class JsonWebTokens extends React.Component { jwtElem.value = '' } - componentDidMount() { + componentDidMount () { _this.setJwt() } } diff --git a/src/components/admin-lte/configure/servers.js b/src/components/admin-lte/configure/servers.js index 172fcd2..56e335f 100644 --- a/src/components/admin-lte/configure/servers.js +++ b/src/components/admin-lte/configure/servers.js @@ -226,7 +226,7 @@ class Servers extends React.Component { bchjsOptions.restURL = restURL bchjsOptions.interface = _interface - //console.log('bchjs options : ', bchjsOptions) + // console.log('bchjs options : ', bchjsOptions) const bchWalletLib = new _this.BchWallet(mnemonic, bchjsOptions) diff --git a/src/components/admin-lte/index.js b/src/components/admin-lte/index.js index 85c5a09..8c4b1a4 100644 --- a/src/components/admin-lte/index.js +++ b/src/components/admin-lte/index.js @@ -132,16 +132,20 @@ class AdminLTEPage extends React.Component { await bchWalletLib.walletInfoPromise const myBalance = await bchWalletLib.getBalance() - const bchjs = bchWalletLib.bchjs + // const bchjs = bchWalletLib.bchjs - let currentRate + const currentRate = (await bchWalletLib.getUsd()) * 100 + console.log('currentRate: ', currentRate) - if (bchjs.restURL.includes('abc.fullstack')) { - currentRate = (await bchjs.Price.getBchaUsd()) * 100 - } else { - // BCHN price. - currentRate = (await bchjs.Price.getUsd()) * 100 - } + // if (bchjs.restURL.includes('abc.fullstack')) { + // currentRate = (await bchjs.Price.getBchaUsd()) * 100 + // } else if (siteConfig.interface === 'consumer-api') { + // bchjs.restURL = `${siteConfig.restURL}/` + // currentRate = (await bchjs.Price.getUsd()) * 100 + // } else { + // // BCHN price. + // currentRate = (await bchjs.Price.getUsd()) * 100 + // } _this.setState({ currentRate: currentRate diff --git a/src/components/admin-lte/tokens/index.js b/src/components/admin-lte/tokens/index.js index 5525a25..8531486 100644 --- a/src/components/admin-lte/tokens/index.js +++ b/src/components/admin-lte/tokens/index.js @@ -31,22 +31,22 @@ class Tokens extends React.Component { return ( <> - - + + {_this.state.txId} @@ -71,46 +71,46 @@ class Tokens extends React.Component { )} {_this.state.inFetch ? ( -
- Loading... -
+
+ Loading... +
) : ( - - {_this.state.errMsg && ( - - - - {_this.state.errMsg} - - - - )} + + {_this.state.errMsg && ( + + + + {_this.state.errMsg} + + + + )} - {_this.state.tokens.length > 0 && ( - <> - - {_this.state.tokens.map((val, i) => { - if (val.qty > 0) { - return ( - - - - ) - } else { - return - } - })} - - - )} - + {_this.state.tokens.length > 0 && ( + <> + + {_this.state.tokens.map((val, i) => { + if (val.qty > 0) { + return ( + + + + ) + } else { + return + } + })} + + + )} + )} FullStack.cash
diff --git a/src/components/admin-lte/tokens/send-tokens.js b/src/components/admin-lte/tokens/send-tokens.js index 5d6b36a..4474ede 100644 --- a/src/components/admin-lte/tokens/send-tokens.js +++ b/src/components/admin-lte/tokens/send-tokens.js @@ -6,6 +6,8 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import ScannerModal from '../../qr-scanner/modal' const { Text } = Inputs +const siteConfig = require('../../site-config') + const BchWallet = typeof window !== 'undefined' ? window.SlpWallet : null let _this @@ -216,12 +218,23 @@ class SendTokens extends React.Component { const result = await bchWalletLib.sendTokens(receiver, 5.0) // console.log('result: ', result) - _this.setState({ - txId: result, - inFetch: false - }) + if (siteConfig.interface === 'consumer-api') { + _this.setState({ + txId: result.txid, + inFetch: false + }) - _this.props.setTxId(result) /* Set the transaction ID in Tokens state */ + // Set the transaction ID in Tokens state + _this.props.setTxId(result.txid) + } else { + _this.setState({ + txId: result, + inFetch: false + }) + + // Set the transaction ID in Tokens state + _this.props.setTxId(result) + } _this.resetValues() diff --git a/src/components/admin-lte/wallet/create.js b/src/components/admin-lte/wallet/create.js index 1c1eb06..d2d41f3 100644 --- a/src/components/admin-lte/wallet/create.js +++ b/src/components/admin-lte/wallet/create.js @@ -4,10 +4,9 @@ import { Row, Col, Box, Button } from 'adminlte-2-react' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' // import BchWallet from 'minimal-slp-wallet' -const BchWallet = - typeof window !== 'undefined' - ? window.SlpWallet - : null +const siteConfig = require('../../site-config') + +const BchWallet = typeof window !== 'undefined' ? window.SlpWallet : null let _this class NewWallet extends React.Component { @@ -79,7 +78,7 @@ class NewWallet extends React.Component { _this.setState({ inFetch: true }) - + const bchjsOptions = _this.getBchjsOptions() const bchWalletLib = new _this.BchWallet(null, bchjsOptions) @@ -103,7 +102,7 @@ class NewWallet extends React.Component { let currentRate if (bchjs.restURL.includes('abc.fullstack')) { - currentRate = await bchjs.Price.getBchaUsd() * 100 + currentRate = (await bchjs.Price.getBchaUsd()) * 100 } else { // BCHN price. currentRate = (await bchjs.Price.getUsd()) * 100 @@ -123,43 +122,45 @@ class NewWallet extends React.Component { _this.handleError(error) } } - getBchjsOptions (){ + + getBchjsOptions () { try { const currentWallet = _this.props.walletInfo // force interface from props - if(_this.props.interface){ + if (_this.props.interface) { currentWallet.interface = _this.props.interface } - const _interface = currentWallet.interface || 'consumer-api' + const _interface = currentWallet.interface || siteConfig.interface const jwtToken = currentWallet.JWT const restURL = currentWallet.selectedServer const bchjsOptions = {} - - if(_interface === 'consumer-api'){ + + if (_interface === 'consumer-api') { bchjsOptions.interface = _interface + bchjsOptions.restURL = siteConfig.restURL return bchjsOptions } - + if (jwtToken) { bchjsOptions.apiToken = jwtToken - } - + if (restURL) { bchjsOptions.restURL = restURL } - + if (_interface === 'rest-api') { bchjsOptions.interface = _interface } - + return bchjsOptions } catch (error) { console.warn(error) } } + handleError (error) { // console.error(error) let errMsg = '' diff --git a/src/components/admin-lte/wallet/import.js b/src/components/admin-lte/wallet/import.js index 9000090..72afb83 100644 --- a/src/components/admin-lte/wallet/import.js +++ b/src/components/admin-lte/wallet/import.js @@ -4,6 +4,8 @@ import { Row, Col, Box, Button, Inputs } from 'adminlte-2-react' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' // import BchWallet from 'minimal-slp-wallet' +const siteConfig = require('../../site-config') + const BchWallet = typeof window !== 'undefined' ? window.SlpWallet : null const { Text } = Inputs @@ -115,7 +117,6 @@ class ImportWallet extends React.Component { const bchjsOptions = _this.getBchjsOptions() - const bchWalletLib = new _this.BchWallet( _this.state.mnemonic, bchjsOptions @@ -162,43 +163,45 @@ class ImportWallet extends React.Component { _this.handleError(error) } } - getBchjsOptions (){ + + getBchjsOptions () { try { const currentWallet = _this.props.walletInfo // force interface from props - if(_this.props.interface){ + if (_this.props.interface) { currentWallet.interface = _this.props.interface } - const _interface = currentWallet.interface || 'consumer-api' + const _interface = currentWallet.interface || siteConfig.interface const jwtToken = currentWallet.JWT const restURL = currentWallet.selectedServer const bchjsOptions = {} - - if(_interface === 'consumer-api'){ + + if (_interface === 'consumer-api') { bchjsOptions.interface = _interface + bchjsOptions.restURL = siteConfig.restURL return bchjsOptions } - + if (jwtToken) { bchjsOptions.apiToken = jwtToken - } - + if (restURL) { bchjsOptions.restURL = restURL } - + if (_interface === 'rest-api') { bchjsOptions.interface = _interface } - + return bchjsOptions } catch (error) { console.warn(error) } } + // Reset form and component state resetValues () { _this.setState({ diff --git a/src/components/footer/index.js b/src/components/footer/index.js index 2b1d520..b390639 100644 --- a/src/components/footer/index.js +++ b/src/components/footer/index.js @@ -59,28 +59,28 @@ class Footer extends React.Component { render () { return ( -