mirror of
https://github.com/fullstack-cash/fullstack-gatsby-theme-bch-wallet.git
synced 2026-09-21 16:52:06 -07:00
fix(config): Setting API interface in site-config.js
This commit is contained in:
@@ -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 {
|
||||
@@ -29,31 +28,31 @@ class NewWallet extends React.Component {
|
||||
<Col sm={2} />
|
||||
<Col sm={8}>
|
||||
<Box
|
||||
className='hover-shadow border-none mt-2'
|
||||
className="hover-shadow border-none mt-2"
|
||||
loaded={!_this.state.inFetch}
|
||||
>
|
||||
<Row>
|
||||
<Col sm={12} className='text-center'>
|
||||
<Col sm={12} className="text-center">
|
||||
<h1>
|
||||
<FontAwesomeIcon
|
||||
className='title-icon'
|
||||
size='xs'
|
||||
icon='plus'
|
||||
className="title-icon"
|
||||
size="xs"
|
||||
icon="plus"
|
||||
/>
|
||||
<span>New Wallet</span>
|
||||
</h1>
|
||||
</Col>
|
||||
<Col sm={12} className='text-center mt-2 mb-2'>
|
||||
<Col sm={12} className="text-center mt-2 mb-2">
|
||||
<Button
|
||||
text='Create Wallet'
|
||||
type='primary'
|
||||
className='btn-lg'
|
||||
text="Create Wallet"
|
||||
type="primary"
|
||||
className="btn-lg"
|
||||
onClick={_this.handleCreateWallet}
|
||||
/>
|
||||
</Col>
|
||||
<Col sm={12} className='text-center '>
|
||||
<Col sm={12} className="text-center ">
|
||||
{_this.state.errMsg && (
|
||||
<p className='error-color mt-2'>{_this.state.errMsg}</p>
|
||||
<p className="error-color mt-2">{_this.state.errMsg}</p>
|
||||
)}
|
||||
</Col>
|
||||
</Row>
|
||||
@@ -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 = ''
|
||||
@@ -173,9 +174,9 @@ class NewWallet 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>
|
||||
|
||||
@@ -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
|
||||
@@ -26,51 +28,51 @@ class ImportWallet extends React.Component {
|
||||
|
||||
render () {
|
||||
return (
|
||||
<Row className=''>
|
||||
<Row className="">
|
||||
<Col sm={2} />
|
||||
<Col sm={8}>
|
||||
<Box
|
||||
className='hover-shadow border-none mt-2'
|
||||
className="hover-shadow border-none mt-2"
|
||||
loaded={!_this.state.inFetch}
|
||||
>
|
||||
<Row>
|
||||
<Col sm={12} className='text-center'>
|
||||
<Col sm={12} className="text-center">
|
||||
<h1>
|
||||
<FontAwesomeIcon
|
||||
className='title-icon'
|
||||
size='xs'
|
||||
icon='file-import'
|
||||
className="title-icon"
|
||||
size="xs"
|
||||
icon="file-import"
|
||||
/>
|
||||
<span>Import Wallet</span>
|
||||
</h1>
|
||||
</Col>
|
||||
<Col sm={12} className='text-center mt-2 mb-2'>
|
||||
<Row className='flex justify-content-center'>
|
||||
<Col sm={12} className="text-center mt-2 mb-2">
|
||||
<Row className="flex justify-content-center">
|
||||
<Col sm={8}>
|
||||
<form autoComplete='off'>
|
||||
<form autoComplete="off">
|
||||
<Text
|
||||
id='import-mnemonic'
|
||||
name='mnemonic'
|
||||
placeholder='12 word mnemonic'
|
||||
label='12 word mnemonic'
|
||||
labelPosition='above'
|
||||
id="import-mnemonic"
|
||||
name="mnemonic"
|
||||
placeholder="12 word mnemonic"
|
||||
label="12 word mnemonic"
|
||||
labelPosition="above"
|
||||
onChange={_this.handleUpdate}
|
||||
/>
|
||||
</form>
|
||||
</Col>
|
||||
</Row>
|
||||
</Col>
|
||||
<Col sm={12} className='text-center mb-2'>
|
||||
<Col sm={12} className="text-center mb-2">
|
||||
<Button
|
||||
text='Import'
|
||||
type='primary'
|
||||
className='btn-lg'
|
||||
text="Import"
|
||||
type="primary"
|
||||
className="btn-lg"
|
||||
onClick={_this.handleImportWallet}
|
||||
/>
|
||||
</Col>
|
||||
<Col sm={12} className='text-center'>
|
||||
<Col sm={12} className="text-center">
|
||||
{_this.state.errMsg && (
|
||||
<p className='error-color'>{_this.state.errMsg}</p>
|
||||
<p className="error-color">{_this.state.errMsg}</p>
|
||||
)}
|
||||
</Col>
|
||||
</Row>
|
||||
@@ -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({
|
||||
@@ -237,9 +240,9 @@ class ImportWallet 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>
|
||||
|
||||
@@ -19,7 +19,13 @@ 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/'
|
||||
// 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') {
|
||||
@@ -79,7 +81,7 @@ const instanceWallet = () => {
|
||||
const bchjsOptions = getBchjsOptions()
|
||||
|
||||
const bchWalletLib = new BchWallet(localStorageInfo.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)
|
||||
@@ -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