diff --git a/src/components/footer/index.js b/src/components/footer/index.js index 4070768..4aec8f5 100644 --- a/src/components/footer/index.js +++ b/src/components/footer/index.js @@ -25,9 +25,13 @@ class Footer extends React.Component { ipfsHashLink: '' } - this.memo = new Memo({ bchWallet: props.bchWallet, bchAddr: siteConfig.memoAddr }) + this.memo = new Memo({ + bchWallet: props.bchWallet, + bchAddr: siteConfig.memoAddr + }) + // memo-get-gatsby Instance - this.memoGet = _this.instantiateMemoLib() + // this.memoGet = _this.instantiateMemoLib() } async componentDidMount () { @@ -39,131 +43,132 @@ class Footer extends React.Component { } async handleMemoService () { + // This is a hard-coded hash or 'checkpoint' to use in times when the + // connection fails. + let hash = 'QmXbaYeTMMsQnLYpthpfoUJhz8o1DWqjoUwLUhC9KFUrAW' + + // Try to retrieve the hash from the BCH blockchain. try { const hash = await this.memo.findHash() - console.log(`hash: ${hash}`) + console.log(`IPFS hash found: ${hash}`) + if (!hash) { - throw new Error('Hash not found!') + throw new Error('Hash not found! Falling back to hard coded IPFS hash.') } - 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}` - }) } + + 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) - console.log(`hash: ${hash}`) - 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}` - }) - } - - // const bchjs = new BCHJS() - // const balance = await bchjs.Blockbook.balance(addr) - // console.log(`balance: ${JSON.stringify(balance, null, 2)}`) - } + // async handleMemoGet () { + // try { + // const addr = 'bitcoincash:qq8mk8etntclfdkny2aknh4ylc0uaewalszh5eytnr' + // const hash = await _this.memoGet.read(addr) + // console.log(`hash: ${hash}`) + // + // 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}` + // }) + // } + // + // // const bchjs = new BCHJS() + // // const balance = await bchjs.Blockbook.balance(addr) + // // console.log(`balance: ${JSON.stringify(balance, null, 2)}`) + // } // Instantiate the library with the // bchjs options established in the configuration section - instantiateMemoLib () { - // Get wallet info - const localStorageInfo = getWalletInfo() - - // Get bchjs options - const jwtToken = localStorageInfo.JWT - const restURL = localStorageInfo.selectedServer - const bchjsOptions = {} - - if (jwtToken) { - bchjsOptions.apiToken = jwtToken - } - if (restURL) { - bchjsOptions.restURL = restURL - } - return new MemoGet(bchjsOptions) - } + // instantiateMemoLib () { + // // Get wallet info + // const localStorageInfo = getWalletInfo() + // + // // Get bchjs options + // const jwtToken = localStorageInfo.JWT + // const restURL = localStorageInfo.selectedServer + // const bchjsOptions = {} + // + // if (jwtToken) { + // bchjsOptions.apiToken = jwtToken + // } + // if (restURL) { + // bchjsOptions.restURL = restURL + // } + // return new MemoGet(bchjsOptions) + // } render () { return ( -