mirror of
https://github.com/fullstack-cash/fullstack-gatsby-theme-bch-wallet.git
synced 2026-09-21 16:52:06 -07:00
fix(bchjs): Get instance of bch-js to memo-hash.js
This commit is contained in:
@@ -101,7 +101,7 @@ class AdminLTEPage extends React.Component {
|
||||
<Navbar.Core>
|
||||
<VersionStatus />
|
||||
</Navbar.Core>
|
||||
<Layout path='/'>
|
||||
<Layout path='/' {..._this.props}>
|
||||
<div className='components-container'>
|
||||
{_this.renderNewViewItems(_this.props)}
|
||||
</div>
|
||||
|
||||
@@ -4,12 +4,14 @@ import { Row, Col } from 'adminlte-2-react'
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||
import { faGithub } from '@fortawesome/free-brands-svg-icons'
|
||||
import { getWalletInfo } from '../localWallet'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
// Get the IPFS hash from the BCH Blockchain.
|
||||
import MemoGet from 'memo-get-gatsby'
|
||||
|
||||
// Get the IPFS hash from the BCH Blockchain.
|
||||
import Memo from '../../services/memo-hash'
|
||||
const siteConfig = require('../site-config')
|
||||
|
||||
let _this
|
||||
|
||||
@@ -23,14 +25,44 @@ class Footer extends React.Component {
|
||||
ipfsHashLink: ''
|
||||
}
|
||||
|
||||
this.memoAddr = 'bitcoincash:qr7u857krgsvq0dwe8rzlt5rcx35r6hnmu6glavtx0'
|
||||
this.memo = new Memo({ bchAddr: this.memoAddr })
|
||||
|
||||
this.memo = new Memo({ bchWallet: props.bchWallet, bchAddr: siteConfig.memoAddr })
|
||||
// memo-get-gatsby Instance
|
||||
this.memoGet = _this.instantiateMemoLib()
|
||||
}
|
||||
|
||||
async componentDidMount () {
|
||||
// Get hash using memo service
|
||||
await this.handleMemoService()
|
||||
|
||||
// Get hash using memo-get-gatsby library
|
||||
// await this.handleMemoGet()
|
||||
}
|
||||
|
||||
async handleMemoService () {
|
||||
try {
|
||||
const hash = await this.memo.findHash()
|
||||
console.log(`hash: ${hash}`)
|
||||
if (!hash) {
|
||||
throw new Error('Hash not found!')
|
||||
}
|
||||
this.setState({
|
||||
ipfsHash: hash,
|
||||
ipfsHashLink: `https://ipfs-gateway.fullstack.cash/ipfs/${hash}`
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('Error trying to retrieve IPFS hash for the site: ', err)
|
||||
|
||||
// Manually set an old hash.
|
||||
const hash = 'QmVm1y1MX4YPzmgQiAafY96Pq7j6GTNMFNuvHki1jAwxYg'
|
||||
this.setState({
|
||||
ipfsHash: hash,
|
||||
ipfsHashLink: `https://ipfs-gateway.fullstack.cash/ipfs/${hash}`
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Get hash using memo-get-gatsby
|
||||
async handleMemoGet () {
|
||||
try {
|
||||
const addr = 'bitcoincash:qq8mk8etntclfdkny2aknh4ylc0uaewalszh5eytnr'
|
||||
const hash = await _this.memoGet.read(addr)
|
||||
@@ -172,5 +204,8 @@ class Footer extends React.Component {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Props prvided by redux
|
||||
Footer.propTypes = {
|
||||
bchWallet: PropTypes.object // get minimal-slp-wallet instance
|
||||
}
|
||||
export default Footer
|
||||
|
||||
@@ -16,7 +16,7 @@ import './layout.css'
|
||||
const Footer = typeof window !== 'undefined' ? require('./footer').default : null
|
||||
// import Footer from "./footer"
|
||||
|
||||
const Layout = ({ children }) => {
|
||||
const Layout = ({ children, bchWallet }) => {
|
||||
/* const data = useStaticQuery(graphql`
|
||||
query SiteTitleQuery {
|
||||
site {
|
||||
@@ -30,12 +30,14 @@ const Layout = ({ children }) => {
|
||||
return (
|
||||
<>
|
||||
<main>{children}</main>
|
||||
{Footer && <Footer />}{' '}
|
||||
{Footer && <Footer bchWallet={bchWallet} />}{' '}
|
||||
</>
|
||||
)
|
||||
}
|
||||
Layout.propTypes = {
|
||||
children: PropTypes.node.isRequired
|
||||
children: PropTypes.node.isRequired,
|
||||
bchWallet: PropTypes.object // get minimal-slp-wallet instance
|
||||
|
||||
}
|
||||
|
||||
export default Layout
|
||||
|
||||
@@ -7,7 +7,8 @@ const config = {
|
||||
title: 'FullStack.cash',
|
||||
titleShort: 'PSF',
|
||||
balanceText: 'BCH Balance',
|
||||
balanceIcon: 'fab-bitcoin'
|
||||
balanceIcon: 'fab-bitcoin',
|
||||
memoAddr: 'bitcoincash:qr7u857krgsvq0dwe8rzlt5rcx35r6hnmu6glavtx0'
|
||||
}
|
||||
|
||||
module.exports = config
|
||||
|
||||
+26
-11
@@ -7,31 +7,46 @@
|
||||
// These libraries are retrieved in /src/html.js
|
||||
// minimal-slp-wallet-web
|
||||
const BchWallet = typeof window !== 'undefined' ? window.SlpWallet : null
|
||||
|
||||
// bch-message-lib
|
||||
// const BchMessage = typeof window !== 'undefined' ? window.BchMessage : null
|
||||
const BchMessage = typeof window !== 'undefined' ? window.BchMessage : null
|
||||
|
||||
class Memo {
|
||||
constructor (config) {
|
||||
console.log('Memo config', config)
|
||||
// Throw an error if this class is instantiated without passing a BCH address.
|
||||
if (!config || !config.bchAddr) {
|
||||
throw new Error('Must pass a BCH address to Memo constructor.')
|
||||
} else this.bchAddr = config.bchAddr
|
||||
|
||||
if (BchWallet) {
|
||||
// Note: Uncommenting the line below will throw an error. I think it's
|
||||
// a collision in the name space?
|
||||
// this.wallet = new BchWallet()
|
||||
// Use the bchWallet instance if already exists otherwise
|
||||
// creates a new one with default values
|
||||
if (config && config.bchWallet) {
|
||||
this.wallet = config.bchWallet
|
||||
this.bchjs = this.wallet.bchjs
|
||||
|
||||
// this.bchjs = this.wallet.bchjs
|
||||
// The way bchjs is used on the previous line
|
||||
// contains the configuration stablished by
|
||||
// the user ( apiToken, restURL )
|
||||
// for a new instance we could use the folowing code
|
||||
// const BCHJS = props.bchWallet.BCHJS
|
||||
// this.bchjs = new BCHJS()
|
||||
|
||||
// debugger
|
||||
} else if (BchWallet) {
|
||||
this.wallet = new BchWallet()
|
||||
// bchjs instance with default values
|
||||
this.bchjs = this.wallet.bchjs
|
||||
// debugger
|
||||
} else {
|
||||
console.error('Could not access minimal-slp-wallet library.')
|
||||
}
|
||||
|
||||
// if (BchMessage) {
|
||||
// this.bchMessage = new BchMessage({ bchjs: this.bchjs })
|
||||
// } else {
|
||||
// console.error('Could not access bch-message-lib library.')
|
||||
// }
|
||||
if (BchMessage) {
|
||||
this.bchMessage = new BchMessage({ bchjs: this.bchjs })
|
||||
} else {
|
||||
console.error('Could not access bch-message-lib library.')
|
||||
}
|
||||
}
|
||||
|
||||
// Walk the transactions associated with an address until a proper IPFS hash is
|
||||
|
||||
Reference in New Issue
Block a user