mirror of https://gitlab.com/ecentrics/concordia
Ezerous
7 years ago
11 changed files with 183 additions and 11 deletions
@ -0,0 +1,96 @@ |
|||||
|
import { drizzleConnect } from 'drizzle-react' |
||||
|
import React, { Children, Component } from 'react' |
||||
|
import PropTypes from 'prop-types' |
||||
|
|
||||
|
import ipfs_logo from './../resources/ipfs_logo.png'; |
||||
|
|
||||
|
/* |
||||
|
* Create component. |
||||
|
*/ |
||||
|
|
||||
|
class LoadingContainer extends Component { |
||||
|
render() { |
||||
|
if (this.props.web3.status === 'failed') |
||||
|
{ |
||||
|
if (this.props.errorComp) { |
||||
|
return this.props.errorComp |
||||
|
} |
||||
|
|
||||
|
return( |
||||
|
<main className="container loading-screen"> |
||||
|
<div className="pure-g"> |
||||
|
<div className="pure-u-1-1"> |
||||
|
<h1>⚠️</h1> |
||||
|
<p>This browser has no connection to the Ethereum network. Please use the Chrome/FireFox extension MetaMask, or dedicated Ethereum browsers Mist or Parity.</p> |
||||
|
</div> |
||||
|
</div> |
||||
|
</main> |
||||
|
) |
||||
|
} |
||||
|
|
||||
|
if (this.props.web3.status === 'initialized' && Object.keys(this.props.accounts).length === 0) |
||||
|
{ |
||||
|
return( |
||||
|
<main className="container loading-screen"> |
||||
|
<div className="pure-g"> |
||||
|
<div className="pure-u-1-1"> |
||||
|
<h1>🦊</h1> |
||||
|
<p><strong>We can't find any Ethereum accounts!</strong> Please check and make sure Metamask or you browser are pointed at the correct network and your account is unlocked.</p> |
||||
|
</div> |
||||
|
</div> |
||||
|
</main> |
||||
|
) |
||||
|
} |
||||
|
|
||||
|
if (!this.props.orbitDB.initialized) |
||||
|
{ |
||||
|
return( |
||||
|
<main className="container loading-screen"> |
||||
|
<div className="pure-g"> |
||||
|
<div className="pure-u-1-1"> |
||||
|
<img src={ipfs_logo} alt="ipfs_logo" height="50"/> |
||||
|
<p><strong>Initializing IPFS...</strong></p> |
||||
|
</div> |
||||
|
</div> |
||||
|
</main> |
||||
|
) |
||||
|
} |
||||
|
|
||||
|
if (this.props.drizzleStatus.initialized) |
||||
|
return Children.only(this.props.children); |
||||
|
|
||||
|
if (this.props.loadingComp) |
||||
|
return this.props.loadingComp; |
||||
|
|
||||
|
|
||||
|
return( |
||||
|
<main className="container loading-screen"> |
||||
|
<div className="pure-g"> |
||||
|
<div className="pure-u-1-1"> |
||||
|
<h1>⚙️</h1> |
||||
|
<p>Loading dapp...</p> |
||||
|
</div> |
||||
|
</div> |
||||
|
</main> |
||||
|
) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
LoadingContainer.contextTypes = { |
||||
|
drizzle: PropTypes.object |
||||
|
}; |
||||
|
|
||||
|
/* |
||||
|
* Export connected component. |
||||
|
*/ |
||||
|
|
||||
|
const mapStateToProps = state => { |
||||
|
return { |
||||
|
accounts: state.accounts, |
||||
|
drizzleStatus: state.drizzleStatus, |
||||
|
web3: state.web3, |
||||
|
orbitDB: state.orbitDB |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
export default drizzleConnect(LoadingContainer, mapStateToProps) |
After Width: | Height: | Size: 1.6 KiB |
@ -1,4 +1,4 @@ |
|||||
import Forum from './build/contracts/Forum.json' |
import Forum from './../build/contracts/Forum.json' |
||||
|
|
||||
const drizzleOptions = { |
const drizzleOptions = { |
||||
web3: { |
web3: { |
@ -0,0 +1,32 @@ |
|||||
|
import IPFS from 'ipfs'; |
||||
|
import OrbitDB from 'orbit-db'; |
||||
|
|
||||
|
import store from './../store'; |
||||
|
|
||||
|
// OrbitDB uses Pubsub which is an experimental feature
|
||||
|
// and need to be turned on manually.
|
||||
|
// Note that these options need to be passed to IPFS in
|
||||
|
// all examples in this document even if not specified so.
|
||||
|
const ipfsOptions = { |
||||
|
EXPERIMENTAL: { |
||||
|
pubsub: true |
||||
|
}, |
||||
|
}; |
||||
|
|
||||
|
// Create IPFS instance
|
||||
|
const ipfs = new IPFS(ipfsOptions); |
||||
|
|
||||
|
ipfs.on('ready', async () => { |
||||
|
store.dispatch({type: "IPFS_READY"}); |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
async function createDatabases() { |
||||
|
const orbitdb = new OrbitDB(ipfs); |
||||
|
const topicsDB = await orbitdb.keyvalue('topics'); |
||||
|
const postsDB = await orbitdb.keyvalue('posts'); |
||||
|
console.log("OrbitDBs created successfully!"); |
||||
|
return {mainDB: orbitdb.id, topicsDB: topicsDB.address.toString(), postsDB: postsDB.address.toString()}; //TODO: regex in the latter two
|
||||
|
} |
||||
|
|
||||
|
export { createDatabases } |
@ -0,0 +1,21 @@ |
|||||
|
const initialState = { |
||||
|
initialized: false, |
||||
|
databasesReady: false |
||||
|
}; |
||||
|
|
||||
|
const orbitReducer = (state = initialState, action) => { |
||||
|
switch (action.type) { |
||||
|
case 'IPFS_READY': |
||||
|
return { |
||||
|
initialized: true |
||||
|
}; |
||||
|
case 'DATABASES_CREATED': |
||||
|
return { |
||||
|
databasesReady: true |
||||
|
}; |
||||
|
default: |
||||
|
return state |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
export default orbitReducer |
Loading…
Reference in new issue