mirror of
https://github.com/fullstack-cash/fullstack-gatsby-theme-bch-wallet.git
synced 2026-09-21 16:52:06 -07:00
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:
@@ -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 (
|
||||
<Row>
|
||||
<Col sm={12}>
|
||||
@@ -70,7 +70,7 @@ class JsonWebTokens extends React.Component {
|
||||
)
|
||||
}
|
||||
|
||||
setJwt() {
|
||||
setJwt () {
|
||||
const { JWT } = _this.props.walletInfo
|
||||
if (JWT) {
|
||||
const jwtElem = document.getElementById('jwt')
|
||||
@@ -78,30 +78,29 @@ 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
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -31,22 +31,22 @@ class Tokens extends React.Component {
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
text="Refresh"
|
||||
icon="fa-redo"
|
||||
type="primary"
|
||||
className="btn-md ml-1 mt-1 mb-1"
|
||||
text='Refresh'
|
||||
icon='fa-redo'
|
||||
type='primary'
|
||||
className='btn-md ml-1 mt-1 mb-1'
|
||||
onClick={() => _this.handleGetTokens(true)}
|
||||
/>
|
||||
{_this.state.txId && (
|
||||
<div className="txIdContainer">
|
||||
<div className='txIdContainer'>
|
||||
<button onClick={() => _this.setState({ txId: null })}>
|
||||
×
|
||||
</button>
|
||||
<Col xs={12} className="text-center mt-1">
|
||||
<Box title="Transaction ID" type="primary" className="p-0">
|
||||
<Col xs={12} className='text-center mt-1'>
|
||||
<Box title='Transaction ID' type='primary' className='p-0'>
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
target='_blank'
|
||||
rel='noopener noreferrer'
|
||||
href={`${_this.state.explorerURL}/${_this.state.txId}`}
|
||||
>
|
||||
{_this.state.txId}
|
||||
@@ -71,46 +71,46 @@ class Tokens extends React.Component {
|
||||
)}
|
||||
{_this.state.inFetch
|
||||
? (
|
||||
<div className="spinner">
|
||||
<img alt="Loading..." src={Spinner} width={100} />
|
||||
</div>
|
||||
<div className='spinner'>
|
||||
<img alt='Loading...' src={Spinner} width={100} />
|
||||
</div>
|
||||
)
|
||||
: (
|
||||
<Content>
|
||||
{_this.state.errMsg && (
|
||||
<Box padding="true" className="container-nofound">
|
||||
<Row>
|
||||
<Col xs={12}>
|
||||
<em>{_this.state.errMsg}</em>
|
||||
</Col>
|
||||
</Row>
|
||||
</Box>
|
||||
)}
|
||||
<Content>
|
||||
{_this.state.errMsg && (
|
||||
<Box padding='true' className='container-nofound'>
|
||||
<Row>
|
||||
<Col xs={12}>
|
||||
<em>{_this.state.errMsg}</em>
|
||||
</Col>
|
||||
</Row>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{_this.state.tokens.length > 0 && (
|
||||
<>
|
||||
<Row>
|
||||
{_this.state.tokens.map((val, i) => {
|
||||
if (val.qty > 0) {
|
||||
return (
|
||||
<Col sm={4} key={`token-${i}`}>
|
||||
<TokenCard
|
||||
key={`token-${i}`}
|
||||
id={`token-${i}`}
|
||||
token={val}
|
||||
showToken={_this.showToken}
|
||||
selectToken={_this.selectToken}
|
||||
/>
|
||||
</Col>
|
||||
)
|
||||
} else {
|
||||
return <span key={`token-${i}`} />
|
||||
}
|
||||
})}
|
||||
</Row>
|
||||
</>
|
||||
)}
|
||||
</Content>
|
||||
{_this.state.tokens.length > 0 && (
|
||||
<>
|
||||
<Row>
|
||||
{_this.state.tokens.map((val, i) => {
|
||||
if (val.qty > 0) {
|
||||
return (
|
||||
<Col sm={4} key={`token-${i}`}>
|
||||
<TokenCard
|
||||
key={`token-${i}`}
|
||||
id={`token-${i}`}
|
||||
token={val}
|
||||
showToken={_this.showToken}
|
||||
selectToken={_this.selectToken}
|
||||
/>
|
||||
</Col>
|
||||
)
|
||||
} else {
|
||||
return <span key={`token-${i}`} />
|
||||
}
|
||||
})}
|
||||
</Row>
|
||||
</>
|
||||
)}
|
||||
</Content>
|
||||
)}
|
||||
<TokenModal
|
||||
bchWallet={_this.props.bchWallet}
|
||||
@@ -227,9 +227,9 @@ class Tokens extends React.Component {
|
||||
Rate limits exceeded, increase rate limits with a JWT token from
|
||||
<a
|
||||
style={{ marginLeft: '5px' }}
|
||||
target="_blank"
|
||||
href="https://fullstack.cash"
|
||||
rel="noopener noreferrer"
|
||||
target='_blank'
|
||||
href='https://fullstack.cash'
|
||||
rel='noopener noreferrer'
|
||||
>
|
||||
FullStack.cash
|
||||
</a>
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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 {
|
||||
@@ -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,28 +122,29 @@ 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) {
|
||||
@@ -160,6 +160,7 @@ class NewWallet extends React.Component {
|
||||
console.warn(error)
|
||||
}
|
||||
}
|
||||
|
||||
handleError (error) {
|
||||
// console.error(error)
|
||||
let errMsg = ''
|
||||
|
||||
@@ -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,28 +163,29 @@ 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) {
|
||||
@@ -199,6 +201,7 @@ class ImportWallet extends React.Component {
|
||||
console.warn(error)
|
||||
}
|
||||
}
|
||||
|
||||
// Reset form and component state
|
||||
resetValues () {
|
||||
_this.setState({
|
||||
|
||||
@@ -59,28 +59,28 @@ class Footer extends React.Component {
|
||||
|
||||
render () {
|
||||
return (
|
||||
<section id="footer">
|
||||
<Row className="footer-container">
|
||||
<Col md={12} className="footer-section">
|
||||
<section id='footer'>
|
||||
<Row className='footer-container'>
|
||||
<Col md={12} className='footer-section'>
|
||||
<Row>
|
||||
<Col md={12} className="mb-1">
|
||||
<p className="section-tittle">Produced By</p>
|
||||
<Col md={12} className='mb-1'>
|
||||
<p className='section-tittle'>Produced By</p>
|
||||
|
||||
<a
|
||||
href={siteConfig.hostUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
target='_blank'
|
||||
rel='noopener noreferrer'
|
||||
>
|
||||
{siteConfig.hostText}
|
||||
</a>
|
||||
</Col>
|
||||
<Col md={12}>
|
||||
<p className="section-tittle">Source Code</p>
|
||||
<FontAwesomeIcon className="" size="lg" icon={faGithub} />
|
||||
<p className='section-tittle'>Source Code</p>
|
||||
<FontAwesomeIcon className='' size='lg' icon={faGithub} />
|
||||
<a
|
||||
href={siteConfig.sourceCode}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
target='_blank'
|
||||
rel='noopener noreferrer'
|
||||
>
|
||||
Github
|
||||
</a>
|
||||
|
||||
@@ -19,7 +19,14 @@ const config = {
|
||||
sourceCode:
|
||||
'https://github.com/Permissionless-Software-Foundation/gatsby-theme-bch-wallet',
|
||||
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
|
||||
|
||||
@@ -4,6 +4,8 @@ import { getWalletInfo, setWalletInfo } from '../components/localWallet'
|
||||
// import BchWallet from 'minimal-slp-wallet'
|
||||
const BchWallet = typeof window !== 'undefined' ? window.SlpWallet : null
|
||||
|
||||
const siteConfig = require('../components/site-config')
|
||||
|
||||
const reducer = (state, action) => {
|
||||
// Update walletInfo state property
|
||||
if (action.type === 'SET_WALLET_INFO') {
|
||||
@@ -90,22 +92,22 @@ const instanceWallet = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const getBchjsOptions = ()=> {
|
||||
const getBchjsOptions = () => {
|
||||
try {
|
||||
const _interface = localStorageInfo.interface || 'consumer-api'
|
||||
const _interface = localStorageInfo.interface || siteConfig.interface
|
||||
|
||||
const jwtToken = localStorageInfo.JWT
|
||||
const restURL = localStorageInfo.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) {
|
||||
@@ -121,7 +123,6 @@ const getBchjsOptions = ()=> {
|
||||
bchjsOptions.fee = FEE
|
||||
console.log(`Using ${bchjsOptions.fee} sats per byte for tx fees.`)
|
||||
|
||||
|
||||
return bchjsOptions
|
||||
} catch (error) {
|
||||
console.warn(error)
|
||||
|
||||
Reference in New Issue
Block a user