diff --git a/app/src/assets/css/App.css b/app/src/assets/css/App.css index 91b623f..ee2aedf 100644 --- a/app/src/assets/css/App.css +++ b/app/src/assets/css/App.css @@ -72,6 +72,7 @@ strong { position: absolute; left: calc(50% - 596px); text-align: center; + z-index: -1; /* Temporary (?) */ } .navBarText span { @@ -183,4 +184,4 @@ a { .fill { width: 100%; height: 100%; -} \ No newline at end of file +} diff --git a/app/src/containers/UsernameFormContainer.js b/app/src/containers/UsernameFormContainer.js index 2fb295d..a7d115c 100644 --- a/app/src/containers/UsernameFormContainer.js +++ b/app/src/containers/UsernameFormContainer.js @@ -4,7 +4,7 @@ import { connect } from "react-redux"; import { Button, Message, Form, Dimmer, Loader, Header } from 'semantic-ui-react'; import { drizzle } from '../index'; -import { createDatabases } from '../orbit'; +import { createDatabases } from '../utils/orbitUtils'; import { updateUsername } from '../redux/actions/transactionsActions'; const contract = "Forum"; @@ -84,7 +84,7 @@ class UsernameFormContainer extends Component { componentDidUpdate() { if (this.state.signingUp) { const txHash = this.props.transactionStack[this.stackId]; - if (txHash && + if (txHash && this.props.transactions[txHash] && this.props.transactions[txHash].status === "error") { this.setState({signingUp: false}); @@ -95,7 +95,7 @@ class UsernameFormContainer extends Component { usernameChecked: checked.args[0], isTaken: checked.value }}); - + if (this.checkedUsernames.length > 0){ this.checkedUsernames.forEach( checked => { if (checked.usernameChecked === this.state.usernameInput && diff --git a/app/src/index.js b/app/src/index.js index 20f273b..e547bd2 100644 --- a/app/src/index.js +++ b/app/src/index.js @@ -6,7 +6,7 @@ import { Drizzle } from 'drizzle'; import store, {history} from './redux/store'; import routes from './router/routes' -import { initIPFS } from './orbit' +import { initIPFS } from './utils/orbitUtils' import * as serviceWorker from './utils/serviceWorker'; import './assets/css/index.css'; diff --git a/app/src/redux/actions/orbitActions.js b/app/src/redux/actions/orbitActions.js index 7716122..0f9e6c9 100644 --- a/app/src/redux/actions/orbitActions.js +++ b/app/src/redux/actions/orbitActions.js @@ -3,4 +3,14 @@ const DATABASES_CREATED = 'DATABASES_CREATED'; const DATABASES_LOADED = 'DATABASES_LOADED'; const DATABASES_NOT_READY = 'DATABASES_NOT_READY'; -export { DATABASES_CREATED, DATABASES_LOADED, DATABASES_NOT_READY, IPFS_INITIALIZED } +function updateDatabases(type, orbitdb, topicsDB, postsDB){ + return { + type, + orbitdb, + topicsDB, + postsDB, + id: orbitdb.id + }; +} + +export { DATABASES_CREATED, DATABASES_LOADED, DATABASES_NOT_READY, IPFS_INITIALIZED, updateDatabases } diff --git a/app/src/redux/reducers/orbitReducer.js b/app/src/redux/reducers/orbitReducer.js index a9f49b6..35df3ec 100644 --- a/app/src/redux/reducers/orbitReducer.js +++ b/app/src/redux/reducers/orbitReducer.js @@ -1,6 +1,7 @@ import { IPFS_INITIALIZED, DATABASES_CREATED, DATABASES_LOADED, DATABASES_NOT_READY } from "../actions/orbitActions"; const initialState = { + ipfs: null, ipfsInitialized: false, ready: false, orbitdb: null, @@ -14,6 +15,7 @@ const orbitReducer = (state = initialState, action) => { case IPFS_INITIALIZED: return { ...state, + ipfs: action.ipfs, ipfsInitialized: true }; case DATABASES_CREATED: diff --git a/app/src/redux/sagas/orbitSaga.js b/app/src/redux/sagas/orbitSaga.js index 472b46a..4e3349f 100644 --- a/app/src/redux/sagas/orbitSaga.js +++ b/app/src/redux/sagas/orbitSaga.js @@ -1,8 +1,8 @@ -import { all, call, put, take, takeLatest } from 'redux-saga/effects' +import {all, call, put, take, takeLatest} from 'redux-saga/effects' import { contract, getCurrentAccount} from './drizzleUtilsSaga'; -import { loadDatabases } from '../../orbit' -import { DRIZZLE_UTILS_SAGA_INITIALIZED } from "../actions/drizzleUtilsActions"; -import { IPFS_INITIALIZED, DATABASES_NOT_READY } from "../actions/orbitActions"; +import { loadDatabases } from '../../utils/orbitUtils' +import { DRIZZLE_UTILS_SAGA_INITIALIZED } from '../actions/drizzleUtilsActions'; +import { IPFS_INITIALIZED, DATABASES_NOT_READY } from '../actions/orbitActions'; let latestAccount; @@ -21,7 +21,7 @@ function* getOrbitDBInfo() { const txObj3 = yield call(contract.methods["getOrbitDBInfo"], ...[account]); const orbitDBInfo = yield call(txObj3.call, {address: account}); yield call(loadDatabases, orbitIdentityInfo[0], orbitIdentityInfo[1], orbitIdentityInfo[2], - orbitDBInfo[0], orbitDBInfo[1], orbitDBInfo[2],orbitDBInfo[3], orbitDBInfo[4]); + orbitDBInfo[0], orbitDBInfo[1], orbitDBInfo[2], orbitDBInfo[3], orbitDBInfo[4]); } else yield put({type: DATABASES_NOT_READY, ...[]}); @@ -32,7 +32,6 @@ function* getOrbitDBInfo() { console.error(error); yield put({type: 'ORBIT_SAGA_ERROR', ...[]}); } - } } diff --git a/app/src/redux/sagas/transactionsSaga.js b/app/src/redux/sagas/transactionsSaga.js index 92499a6..a79eade 100644 --- a/app/src/redux/sagas/transactionsSaga.js +++ b/app/src/redux/sagas/transactionsSaga.js @@ -1,8 +1,8 @@ import {call, select, take, takeEvery} from 'redux-saga/effects' import { drizzle } from '../../index' -import { orbitSagaPut } from '../../orbit' -import { DRIZZLE_UTILS_SAGA_INITIALIZED } from "../actions/drizzleUtilsActions"; +import { orbitSagaPut } from '../../utils/orbitUtils' +import { DRIZZLE_UTILS_SAGA_INITIALIZED } from '../actions/drizzleUtilsActions'; let transactionsHistory = Object.create(null); diff --git a/app/src/orbit.js b/app/src/utils/orbitUtils.js similarity index 71% rename from app/src/orbit.js rename to app/src/utils/orbitUtils.js index fe7836d..91fc2e6 100644 --- a/app/src/orbit.js +++ b/app/src/utils/orbitUtils.js @@ -1,32 +1,26 @@ -import IPFS from 'ipfs'; import OrbitDB from 'orbit-db'; import Keystore from 'orbit-db-keystore'; import path from 'path'; -import store from './redux/store'; -import ipfsOptions from './config/ipfsOptions' -import { IPFS_INITIALIZED, DATABASES_CREATED, DATABASES_LOADED } from './redux/actions/orbitActions'; - -let ipfs; +import store from '../redux/store'; +import { DATABASES_CREATED, DATABASES_LOADED, IPFS_INITIALIZED, updateDatabases } from '../redux/actions/orbitActions'; +import IPFS from "ipfs"; +import ipfsOptions from "../config/ipfsOptions"; function initIPFS(){ - ipfs = new IPFS(ipfsOptions); + const ipfs = new IPFS(ipfsOptions); ipfs.on('ready', async () => { - store.dispatch({type: IPFS_INITIALIZED}); + store.dispatch({type: IPFS_INITIALIZED, ipfs}); + console.log("IPFS initialized."); }); } async function createDatabases() { console.log("Creating databases..."); + const ipfs = getIPFS(); const orbitdb = await new OrbitDB(ipfs); const topicsDB = await orbitdb.keyvalue('topics'); const postsDB = await orbitdb.keyvalue('posts'); - store.dispatch({ - type: DATABASES_CREATED, - orbitdb: orbitdb, - topicsDB: topicsDB, - postsDB: postsDB, - id: orbitdb.id - }); + store.dispatch(updateDatabases(DATABASES_CREATED, orbitdb, topicsDB, postsDB)); const orbitKey = orbitdb.keystore.getKey(orbitdb.id); @@ -53,6 +47,7 @@ async function loadDatabases(identityId, identityPublicKey, identityPrivateKey, privateKey: orbitPrivateKey })); + const ipfs = getIPFS(); const orbitdb = await new OrbitDB(ipfs, directory, { peerId:orbitId, keystore:keystore}); const topicsDB = await orbitdb.keyvalue('/orbitdb/' + topicsDBId +'/topics'); const postsDB = await orbitdb.keyvalue('/orbitdb/' + postsDBId +'/posts'); @@ -60,13 +55,13 @@ async function loadDatabases(identityId, identityPublicKey, identityPrivateKey, await topicsDB.load(); await postsDB.load(); - store.dispatch({ - type: DATABASES_LOADED, - orbitdb: orbitdb, - topicsDB: topicsDB, - postsDB: postsDB, - id: orbitdb.id - }); + updateDatabases(DATABASES_LOADED, orbitdb, topicsDB, postsDB); + + return { orbitdb, topicsDB, postsDB }; +} + +function getIPFS(){ + return store.getState().orbit.ipfs; } async function orbitSagaPut(db, key, value) {