{_this.renderNewViewItems(_this.props)}
diff --git a/src/components/footer/index.js b/src/components/footer/index.js
index cde6f29..4070768 100644
--- a/src/components/footer/index.js
+++ b/src/components/footer/index.js
@@ -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
diff --git a/src/components/layout.js b/src/components/layout.js
index 044d140..f430793 100644
--- a/src/components/layout.js
+++ b/src/components/layout.js
@@ -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 (
<>
{children}
- {Footer && }{' '}
+ {Footer && }{' '}
>
)
}
Layout.propTypes = {
- children: PropTypes.node.isRequired
+ children: PropTypes.node.isRequired,
+ bchWallet: PropTypes.object // get minimal-slp-wallet instance
+
}
export default Layout
diff --git a/src/components/site-config.js b/src/components/site-config.js
index 34b6703..67a7f94 100644
--- a/src/components/site-config.js
+++ b/src/components/site-config.js
@@ -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
diff --git a/src/services/memo-hash.js b/src/services/memo-hash.js
index 4e0300c..d52da67 100644
--- a/src/services/memo-hash.js
+++ b/src/services/memo-hash.js
@@ -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