From 1b112477d065e25e1e1d0771fd69bf998546a209 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Tue, 12 Mar 2019 14:22:53 +0200 Subject: [PATCH] Minor actions cleanup --- app/src/orbit.js | 13 ++++++------- app/src/redux/actions/drizzleUtilsActions.js | 1 + app/src/redux/actions/orbitActions.js | 6 ++++++ app/src/redux/reducers/orbitReducer.js | 12 +++++++----- app/src/redux/reducers/userInterfaceReducer.js | 6 ++---- app/src/redux/sagas/drizzleUtilsSaga.js | 6 ++++-- app/src/redux/sagas/orbitSaga.js | 8 +++++--- app/src/redux/sagas/transactionsSaga.js | 3 ++- app/src/redux/sagas/userSaga.js | 3 ++- 9 files changed, 35 insertions(+), 23 deletions(-) create mode 100644 app/src/redux/actions/drizzleUtilsActions.js create mode 100644 app/src/redux/actions/orbitActions.js diff --git a/app/src/orbit.js b/app/src/orbit.js index 6983430..21ede05 100644 --- a/app/src/orbit.js +++ b/app/src/orbit.js @@ -1,16 +1,17 @@ import IPFS from 'ipfs'; import OrbitDB from 'orbit-db'; -import Keystore from 'orbit-db-keystore'; +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, orbitdb, topicsDB, postsDB; function initIPFS(){ ipfs = new IPFS(ipfsOptions); ipfs.on('ready', async () => { - store.dispatch({type: "IPFS_INITIALIZED"}); + store.dispatch({type: IPFS_INITIALIZED}); }); } @@ -20,7 +21,7 @@ async function createDatabases() { topicsDB = await orbitdb.keyvalue('topics'); postsDB = await orbitdb.keyvalue('posts'); store.dispatch({ - type: "DATABASES_CREATED", + type: DATABASES_CREATED, orbitdb: orbitdb, topicsDB: topicsDB, postsDB: postsDB, @@ -29,7 +30,7 @@ async function createDatabases() { const orbitKey = orbitdb.keystore.getKey(orbitdb.id); - const returnValue = { + return { identityId: "Tempus", identityPublicKey: "edax", identityPrivateKey: "rerum", @@ -39,8 +40,6 @@ async function createDatabases() { topicsDB: topicsDB.address.root, postsDB: postsDB.address.root }; - - return returnValue; } async function loadDatabases(identityId, identityPublicKey, identityPrivateKey, @@ -62,7 +61,7 @@ async function loadDatabases(identityId, identityPublicKey, identityPrivateKey, await postsDB.load(); store.dispatch({ - type: "DATABASES_LOADED", + type: DATABASES_LOADED, orbitdb: orbitdb, topicsDB: topicsDB, postsDB: postsDB, diff --git a/app/src/redux/actions/drizzleUtilsActions.js b/app/src/redux/actions/drizzleUtilsActions.js new file mode 100644 index 0000000..2581b2a --- /dev/null +++ b/app/src/redux/actions/drizzleUtilsActions.js @@ -0,0 +1 @@ +export const DRIZZLE_UTILS_SAGA_INITIALIZED = 'DRIZZLE_UTILS_SAGA_INITIALIZED'; diff --git a/app/src/redux/actions/orbitActions.js b/app/src/redux/actions/orbitActions.js new file mode 100644 index 0000000..7716122 --- /dev/null +++ b/app/src/redux/actions/orbitActions.js @@ -0,0 +1,6 @@ +const IPFS_INITIALIZED = 'IPFS_INITIALIZED'; +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 } diff --git a/app/src/redux/reducers/orbitReducer.js b/app/src/redux/reducers/orbitReducer.js index 5bd3583..a9f49b6 100644 --- a/app/src/redux/reducers/orbitReducer.js +++ b/app/src/redux/reducers/orbitReducer.js @@ -1,3 +1,5 @@ +import { IPFS_INITIALIZED, DATABASES_CREATED, DATABASES_LOADED, DATABASES_NOT_READY } from "../actions/orbitActions"; + const initialState = { ipfsInitialized: false, ready: false, @@ -9,12 +11,12 @@ const initialState = { const orbitReducer = (state = initialState, action) => { switch (action.type) { - case 'IPFS_INITIALIZED': + case IPFS_INITIALIZED: return { ...state, ipfsInitialized: true }; - case 'DATABASES_CREATED': + case DATABASES_CREATED: return { ...state, ready: true, @@ -23,7 +25,7 @@ const orbitReducer = (state = initialState, action) => { postsDB: action.postsDB, id: action.id }; - case 'DATABASES_LOADED': + case DATABASES_LOADED: return { ...state, ready: true, @@ -32,7 +34,7 @@ const orbitReducer = (state = initialState, action) => { postsDB: action.postsDB, id: action.id }; - case 'DATABASES_NOT_READY': + case DATABASES_NOT_READY: return { ...state, ready: false, @@ -46,4 +48,4 @@ const orbitReducer = (state = initialState, action) => { } }; -export default orbitReducer; \ No newline at end of file +export default orbitReducer; diff --git a/app/src/redux/reducers/userInterfaceReducer.js b/app/src/redux/reducers/userInterfaceReducer.js index f95f8c3..6a887bc 100644 --- a/app/src/redux/reducers/userInterfaceReducer.js +++ b/app/src/redux/reducers/userInterfaceReducer.js @@ -1,6 +1,4 @@ -import { - SET_NAVBAR_TITLE -} from '../actions/userInterfaceActions'; +import { SET_NAVBAR_TITLE } from '../actions/userInterfaceActions'; const initialState = { navBarTitle: '' @@ -11,7 +9,7 @@ const userInterfaceReducer = (state = initialState, action) => { case SET_NAVBAR_TITLE: return { navBarTitle: action.title - } + }; default: return state; } diff --git a/app/src/redux/sagas/drizzleUtilsSaga.js b/app/src/redux/sagas/drizzleUtilsSaga.js index 0278ade..9b8bc65 100644 --- a/app/src/redux/sagas/drizzleUtilsSaga.js +++ b/app/src/redux/sagas/drizzleUtilsSaga.js @@ -2,6 +2,8 @@ import { getContractInstance, getWeb3 } from "../../utils/drizzleUtils"; import { call, put, takeLatest, select } from 'redux-saga/effects' import Forum from '../../contracts/Forum'; +import { DRIZZLE_UTILS_SAGA_INITIALIZED } from "../actions/drizzleUtilsActions"; + const accounts = (state) => state.accounts; let initFlag, web3, contract; @@ -14,7 +16,7 @@ function* init() { artifact: Forum }); initFlag=true; - yield put({type: 'DRIZZLE_UTILS_SAGA_INITIALIZED', ...[]}); + yield put({type: DRIZZLE_UTILS_SAGA_INITIALIZED, ...[]}); } else console.warn("Attempted to reinitialize drizzleUtilsSaga!"); @@ -33,4 +35,4 @@ function* drizzleUtilsSaga() { export { web3, contract, getCurrentAccount } -export default drizzleUtilsSaga; \ No newline at end of file +export default drizzleUtilsSaga; diff --git a/app/src/redux/sagas/orbitSaga.js b/app/src/redux/sagas/orbitSaga.js index 8b20e98..472b46a 100644 --- a/app/src/redux/sagas/orbitSaga.js +++ b/app/src/redux/sagas/orbitSaga.js @@ -1,6 +1,8 @@ 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"; let latestAccount; @@ -22,7 +24,7 @@ function* getOrbitDBInfo() { orbitDBInfo[0], orbitDBInfo[1], orbitDBInfo[2],orbitDBInfo[3], orbitDBInfo[4]); } else - yield put({type: 'DATABASES_NOT_READY', ...[]}); + yield put({type: DATABASES_NOT_READY, ...[]}); latestAccount=account; } @@ -36,8 +38,8 @@ function* getOrbitDBInfo() { function* orbitSaga() { yield all([ - take("DRIZZLE_UTILS_SAGA_INITIALIZED"), - take("IPFS_INITIALIZED") + take(DRIZZLE_UTILS_SAGA_INITIALIZED), + take(IPFS_INITIALIZED) ]); yield takeLatest("ACCOUNT_CHANGED", getOrbitDBInfo); } diff --git a/app/src/redux/sagas/transactionsSaga.js b/app/src/redux/sagas/transactionsSaga.js index ae02122..92499a6 100644 --- a/app/src/redux/sagas/transactionsSaga.js +++ b/app/src/redux/sagas/transactionsSaga.js @@ -2,6 +2,7 @@ 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"; let transactionsHistory = Object.create(null); @@ -63,7 +64,7 @@ function* handleError() { } function* transactionsSaga() { - yield take("DRIZZLE_UTILS_SAGA_INITIALIZED"); + yield take(DRIZZLE_UTILS_SAGA_INITIALIZED); yield takeEvery("INIT_TRANSACTION", initTransaction); yield takeEvery("EVENT_FIRED", handleEvent); yield takeEvery("TX_ERROR", handleError); diff --git a/app/src/redux/sagas/userSaga.js b/app/src/redux/sagas/userSaga.js index f1c7e83..6e96fa1 100644 --- a/app/src/redux/sagas/userSaga.js +++ b/app/src/redux/sagas/userSaga.js @@ -1,6 +1,7 @@ import {call, put, select, take, takeEvery} from 'redux-saga/effects' import { contract, getCurrentAccount } from './drizzleUtilsSaga'; +import { DRIZZLE_UTILS_SAGA_INITIALIZED } from "../actions/drizzleUtilsActions"; let account; @@ -45,7 +46,7 @@ function* getUserState(){ } function* userSaga() { - yield take("DRIZZLE_UTILS_SAGA_INITIALIZED"); + yield take(DRIZZLE_UTILS_SAGA_INITIALIZED); yield takeEvery("ACCOUNTS_FETCHED", updateUserData); }