Merge pull request #9 from Permissionless-Software-Foundation/ct-unstable

Using site-config.js to switch between centralized and decentralized infra
This commit is contained in:
Chris Troutner
2022-02-03 06:55:18 -08:00
committed by GitHub
10 changed files with 148 additions and 120 deletions
+9 -10
View File
@@ -13,7 +13,7 @@ const { Text } = Inputs
let _this let _this
class JsonWebTokens extends React.Component { class JsonWebTokens extends React.Component {
constructor(props) { constructor (props) {
super(props) super(props)
_this = this _this = this
@@ -26,7 +26,7 @@ class JsonWebTokens extends React.Component {
_this.BchWallet = BchWallet _this.BchWallet = BchWallet
} }
render() { render () {
return ( return (
<Row> <Row>
<Col sm={12}> <Col sm={12}>
@@ -70,7 +70,7 @@ class JsonWebTokens extends React.Component {
) )
} }
setJwt() { setJwt () {
const { JWT } = _this.props.walletInfo const { JWT } = _this.props.walletInfo
if (JWT) { if (JWT) {
const jwtElem = document.getElementById('jwt') const jwtElem = document.getElementById('jwt')
@@ -78,30 +78,29 @@ class JsonWebTokens extends React.Component {
} }
} }
handleUpdate(event) { handleUpdate (event) {
const value = event.target.value const value = event.target.value
_this.setState({ _this.setState({
[event.target.name]: value [event.target.name]: value
}) })
} }
async handleUpdateJWT() { async handleUpdateJWT () {
try { try {
const { mnemonic, selectedServer } = _this.props.walletInfo const { mnemonic, selectedServer } = _this.props.walletInfo
const _interface = _this.props.walletInfo.interface const _interface = _this.props.walletInfo.interface
const apiToken = _this.state.JWT const apiToken = _this.state.JWT
// Update instance with JWT // Update instance with JWT
if (mnemonic) { if (mnemonic) {
let bchjsOptions = { apiToken: apiToken } const bchjsOptions = { apiToken: apiToken }
if (selectedServer) { if (selectedServer) {
bchjsOptions.restURL = selectedServer bchjsOptions.restURL = selectedServer
} }
bchjsOptions.interface = _interface bchjsOptions.interface = _interface
//console.log('bchjs options : ', bchjsOptions) // console.log('bchjs options : ', bchjsOptions)
const bchWalletLib = new _this.BchWallet(mnemonic, bchjsOptions) const bchWalletLib = new _this.BchWallet(mnemonic, bchjsOptions)
// Update bchjs instances of minimal-slp-wallet libraries // Update bchjs instances of minimal-slp-wallet libraries
@@ -124,7 +123,7 @@ class JsonWebTokens extends React.Component {
} }
// Reset form and component state // Reset form and component state
resetValues() { resetValues () {
_this.setState({ _this.setState({
JWT: '', JWT: '',
errMsg: '' errMsg: ''
@@ -133,7 +132,7 @@ class JsonWebTokens extends React.Component {
jwtElem.value = '' jwtElem.value = ''
} }
componentDidMount() { componentDidMount () {
_this.setJwt() _this.setJwt()
} }
} }
@@ -226,7 +226,7 @@ class Servers extends React.Component {
bchjsOptions.restURL = restURL bchjsOptions.restURL = restURL
bchjsOptions.interface = _interface bchjsOptions.interface = _interface
//console.log('bchjs options : ', bchjsOptions) // console.log('bchjs options : ', bchjsOptions)
const bchWalletLib = new _this.BchWallet(mnemonic, bchjsOptions) const bchWalletLib = new _this.BchWallet(mnemonic, bchjsOptions)
+12 -8
View File
@@ -132,16 +132,20 @@ class AdminLTEPage extends React.Component {
await bchWalletLib.walletInfoPromise await bchWalletLib.walletInfoPromise
const myBalance = await bchWalletLib.getBalance() 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')) { // if (bchjs.restURL.includes('abc.fullstack')) {
currentRate = (await bchjs.Price.getBchaUsd()) * 100 // currentRate = (await bchjs.Price.getBchaUsd()) * 100
} else { // } else if (siteConfig.interface === 'consumer-api') {
// BCHN price. // bchjs.restURL = `${siteConfig.restURL}/`
currentRate = (await bchjs.Price.getUsd()) * 100 // currentRate = (await bchjs.Price.getUsd()) * 100
} // } else {
// // BCHN price.
// currentRate = (await bchjs.Price.getUsd()) * 100
// }
_this.setState({ _this.setState({
currentRate: currentRate currentRate: currentRate
+49 -49
View File
@@ -31,22 +31,22 @@ class Tokens extends React.Component {
return ( return (
<> <>
<Button <Button
text="Refresh" text='Refresh'
icon="fa-redo" icon='fa-redo'
type="primary" type='primary'
className="btn-md ml-1 mt-1 mb-1" className='btn-md ml-1 mt-1 mb-1'
onClick={() => _this.handleGetTokens(true)} onClick={() => _this.handleGetTokens(true)}
/> />
{_this.state.txId && ( {_this.state.txId && (
<div className="txIdContainer"> <div className='txIdContainer'>
<button onClick={() => _this.setState({ txId: null })}> <button onClick={() => _this.setState({ txId: null })}>
&times; &times;
</button> </button>
<Col xs={12} className="text-center mt-1"> <Col xs={12} className='text-center mt-1'>
<Box title="Transaction ID" type="primary" className="p-0"> <Box title='Transaction ID' type='primary' className='p-0'>
<a <a
target="_blank" target='_blank'
rel="noopener noreferrer" rel='noopener noreferrer'
href={`${_this.state.explorerURL}/${_this.state.txId}`} href={`${_this.state.explorerURL}/${_this.state.txId}`}
> >
{_this.state.txId} {_this.state.txId}
@@ -71,46 +71,46 @@ class Tokens extends React.Component {
)} )}
{_this.state.inFetch {_this.state.inFetch
? ( ? (
<div className="spinner"> <div className='spinner'>
<img alt="Loading..." src={Spinner} width={100} /> <img alt='Loading...' src={Spinner} width={100} />
</div> </div>
) )
: ( : (
<Content> <Content>
{_this.state.errMsg && ( {_this.state.errMsg && (
<Box padding="true" className="container-nofound"> <Box padding='true' className='container-nofound'>
<Row> <Row>
<Col xs={12}> <Col xs={12}>
<em>{_this.state.errMsg}</em> <em>{_this.state.errMsg}</em>
</Col> </Col>
</Row> </Row>
</Box> </Box>
)} )}
{_this.state.tokens.length > 0 && ( {_this.state.tokens.length > 0 && (
<> <>
<Row> <Row>
{_this.state.tokens.map((val, i) => { {_this.state.tokens.map((val, i) => {
if (val.qty > 0) { if (val.qty > 0) {
return ( return (
<Col sm={4} key={`token-${i}`}> <Col sm={4} key={`token-${i}`}>
<TokenCard <TokenCard
key={`token-${i}`} key={`token-${i}`}
id={`token-${i}`} id={`token-${i}`}
token={val} token={val}
showToken={_this.showToken} showToken={_this.showToken}
selectToken={_this.selectToken} selectToken={_this.selectToken}
/> />
</Col> </Col>
) )
} else { } else {
return <span key={`token-${i}`} /> return <span key={`token-${i}`} />
} }
})} })}
</Row> </Row>
</> </>
)} )}
</Content> </Content>
)} )}
<TokenModal <TokenModal
bchWallet={_this.props.bchWallet} bchWallet={_this.props.bchWallet}
@@ -227,9 +227,9 @@ class Tokens extends React.Component {
Rate limits exceeded, increase rate limits with a JWT token from Rate limits exceeded, increase rate limits with a JWT token from
<a <a
style={{ marginLeft: '5px' }} style={{ marginLeft: '5px' }}
target="_blank" target='_blank'
href="https://fullstack.cash" href='https://fullstack.cash'
rel="noopener noreferrer" rel='noopener noreferrer'
> >
FullStack.cash FullStack.cash
</a> </a>
+18 -5
View File
@@ -6,6 +6,8 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import ScannerModal from '../../qr-scanner/modal' import ScannerModal from '../../qr-scanner/modal'
const { Text } = Inputs const { Text } = Inputs
const siteConfig = require('../../site-config')
const BchWallet = typeof window !== 'undefined' ? window.SlpWallet : null const BchWallet = typeof window !== 'undefined' ? window.SlpWallet : null
let _this let _this
@@ -216,12 +218,23 @@ class SendTokens extends React.Component {
const result = await bchWalletLib.sendTokens(receiver, 5.0) const result = await bchWalletLib.sendTokens(receiver, 5.0)
// console.log('result: ', result) // console.log('result: ', result)
_this.setState({ if (siteConfig.interface === 'consumer-api') {
txId: result, _this.setState({
inFetch: false 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() _this.resetValues()
+11 -10
View File
@@ -4,10 +4,9 @@ import { Row, Col, Box, Button } from 'adminlte-2-react'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
// import BchWallet from 'minimal-slp-wallet' // import BchWallet from 'minimal-slp-wallet'
const BchWallet = const siteConfig = require('../../site-config')
typeof window !== 'undefined'
? window.SlpWallet const BchWallet = typeof window !== 'undefined' ? window.SlpWallet : null
: null
let _this let _this
class NewWallet extends React.Component { class NewWallet extends React.Component {
@@ -103,7 +102,7 @@ class NewWallet extends React.Component {
let currentRate let currentRate
if (bchjs.restURL.includes('abc.fullstack')) { if (bchjs.restURL.includes('abc.fullstack')) {
currentRate = await bchjs.Price.getBchaUsd() * 100 currentRate = (await bchjs.Price.getBchaUsd()) * 100
} else { } else {
// BCHN price. // BCHN price.
currentRate = (await bchjs.Price.getUsd()) * 100 currentRate = (await bchjs.Price.getUsd()) * 100
@@ -123,28 +122,29 @@ class NewWallet extends React.Component {
_this.handleError(error) _this.handleError(error)
} }
} }
getBchjsOptions (){
getBchjsOptions () {
try { try {
const currentWallet = _this.props.walletInfo const currentWallet = _this.props.walletInfo
// force interface from props // force interface from props
if(_this.props.interface){ if (_this.props.interface) {
currentWallet.interface = _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 jwtToken = currentWallet.JWT
const restURL = currentWallet.selectedServer const restURL = currentWallet.selectedServer
const bchjsOptions = {} const bchjsOptions = {}
if(_interface === 'consumer-api'){ if (_interface === 'consumer-api') {
bchjsOptions.interface = _interface bchjsOptions.interface = _interface
bchjsOptions.restURL = siteConfig.restURL
return bchjsOptions return bchjsOptions
} }
if (jwtToken) { if (jwtToken) {
bchjsOptions.apiToken = jwtToken bchjsOptions.apiToken = jwtToken
} }
if (restURL) { if (restURL) {
@@ -160,6 +160,7 @@ class NewWallet extends React.Component {
console.warn(error) console.warn(error)
} }
} }
handleError (error) { handleError (error) {
// console.error(error) // console.error(error)
let errMsg = '' let errMsg = ''
+9 -6
View File
@@ -4,6 +4,8 @@ import { Row, Col, Box, Button, Inputs } from 'adminlte-2-react'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
// import BchWallet from 'minimal-slp-wallet' // import BchWallet from 'minimal-slp-wallet'
const siteConfig = require('../../site-config')
const BchWallet = typeof window !== 'undefined' ? window.SlpWallet : null const BchWallet = typeof window !== 'undefined' ? window.SlpWallet : null
const { Text } = Inputs const { Text } = Inputs
@@ -115,7 +117,6 @@ class ImportWallet extends React.Component {
const bchjsOptions = _this.getBchjsOptions() const bchjsOptions = _this.getBchjsOptions()
const bchWalletLib = new _this.BchWallet( const bchWalletLib = new _this.BchWallet(
_this.state.mnemonic, _this.state.mnemonic,
bchjsOptions bchjsOptions
@@ -162,28 +163,29 @@ class ImportWallet extends React.Component {
_this.handleError(error) _this.handleError(error)
} }
} }
getBchjsOptions (){
getBchjsOptions () {
try { try {
const currentWallet = _this.props.walletInfo const currentWallet = _this.props.walletInfo
// force interface from props // force interface from props
if(_this.props.interface){ if (_this.props.interface) {
currentWallet.interface = _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 jwtToken = currentWallet.JWT
const restURL = currentWallet.selectedServer const restURL = currentWallet.selectedServer
const bchjsOptions = {} const bchjsOptions = {}
if(_interface === 'consumer-api'){ if (_interface === 'consumer-api') {
bchjsOptions.interface = _interface bchjsOptions.interface = _interface
bchjsOptions.restURL = siteConfig.restURL
return bchjsOptions return bchjsOptions
} }
if (jwtToken) { if (jwtToken) {
bchjsOptions.apiToken = jwtToken bchjsOptions.apiToken = jwtToken
} }
if (restURL) { if (restURL) {
@@ -199,6 +201,7 @@ class ImportWallet extends React.Component {
console.warn(error) console.warn(error)
} }
} }
// Reset form and component state // Reset form and component state
resetValues () { resetValues () {
_this.setState({ _this.setState({
+11 -11
View File
@@ -59,28 +59,28 @@ class Footer extends React.Component {
render () { render () {
return ( return (
<section id="footer"> <section id='footer'>
<Row className="footer-container"> <Row className='footer-container'>
<Col md={12} className="footer-section"> <Col md={12} className='footer-section'>
<Row> <Row>
<Col md={12} className="mb-1"> <Col md={12} className='mb-1'>
<p className="section-tittle">Produced By</p> <p className='section-tittle'>Produced By</p>
<a <a
href={siteConfig.hostUrl} href={siteConfig.hostUrl}
target="_blank" target='_blank'
rel="noopener noreferrer" rel='noopener noreferrer'
> >
{siteConfig.hostText} {siteConfig.hostText}
</a> </a>
</Col> </Col>
<Col md={12}> <Col md={12}>
<p className="section-tittle">Source Code</p> <p className='section-tittle'>Source Code</p>
<FontAwesomeIcon className="" size="lg" icon={faGithub} /> <FontAwesomeIcon className='' size='lg' icon={faGithub} />
<a <a
href={siteConfig.sourceCode} href={siteConfig.sourceCode}
target="_blank" target='_blank'
rel="noopener noreferrer" rel='noopener noreferrer'
> >
Github Github
</a> </a>
+8 -1
View File
@@ -19,7 +19,14 @@ const config = {
sourceCode: sourceCode:
'https://github.com/Permissionless-Software-Foundation/gatsby-theme-bch-wallet', 'https://github.com/Permissionless-Software-Foundation/gatsby-theme-bch-wallet',
torUrl: '2egutot63q765ciwsenlcy5zdyxwxt7olzbldr5dx5i3ixsef2nvrzid.onion', torUrl: '2egutot63q765ciwsenlcy5zdyxwxt7olzbldr5dx5i3ixsef2nvrzid.onion',
clearWebUrl: 'https://gatsby-ipfs-web-wallet.fullstack.cash' clearWebUrl: 'https://gatsby-ipfs-web-wallet.fullstack.cash',
// Interface used by minial-slp-wallet
interface: 'consumer-api',
restURL: 'https://free-bch.fullstack.cash'
// restURL: 'http://localhost:5005'
// interface: 'rest-api',
// restURL: 'https://bchn.fullstack.cash/v5/'
} }
module.exports = config module.exports = config
+6 -5
View File
@@ -4,6 +4,8 @@ import { getWalletInfo, setWalletInfo } from '../components/localWallet'
// import BchWallet from 'minimal-slp-wallet' // import BchWallet from 'minimal-slp-wallet'
const BchWallet = typeof window !== 'undefined' ? window.SlpWallet : null const BchWallet = typeof window !== 'undefined' ? window.SlpWallet : null
const siteConfig = require('../components/site-config')
const reducer = (state, action) => { const reducer = (state, action) => {
// Update walletInfo state property // Update walletInfo state property
if (action.type === 'SET_WALLET_INFO') { if (action.type === 'SET_WALLET_INFO') {
@@ -90,22 +92,22 @@ const instanceWallet = () => {
} }
} }
const getBchjsOptions = ()=> { const getBchjsOptions = () => {
try { try {
const _interface = localStorageInfo.interface || 'consumer-api' const _interface = localStorageInfo.interface || siteConfig.interface
const jwtToken = localStorageInfo.JWT const jwtToken = localStorageInfo.JWT
const restURL = localStorageInfo.selectedServer const restURL = localStorageInfo.selectedServer
const bchjsOptions = {} const bchjsOptions = {}
if(_interface === 'consumer-api'){ if (_interface === 'consumer-api') {
bchjsOptions.interface = _interface bchjsOptions.interface = _interface
bchjsOptions.restURL = siteConfig.restURL
return bchjsOptions return bchjsOptions
} }
if (jwtToken) { if (jwtToken) {
bchjsOptions.apiToken = jwtToken bchjsOptions.apiToken = jwtToken
} }
if (restURL) { if (restURL) {
@@ -121,7 +123,6 @@ const getBchjsOptions = ()=> {
bchjsOptions.fee = FEE bchjsOptions.fee = FEE
console.log(`Using ${bchjsOptions.fee} sats per byte for tx fees.`) console.log(`Using ${bchjsOptions.fee} sats per byte for tx fees.`)
return bchjsOptions return bchjsOptions
} catch (error) { } catch (error) {
console.warn(error) console.warn(error)