Browse Source

Minor actions cleanup

develop
Ezerous 6 years ago
parent
commit
1b112477d0
  1. 13
      app/src/orbit.js
  2. 1
      app/src/redux/actions/drizzleUtilsActions.js
  3. 6
      app/src/redux/actions/orbitActions.js
  4. 12
      app/src/redux/reducers/orbitReducer.js
  5. 6
      app/src/redux/reducers/userInterfaceReducer.js
  6. 6
      app/src/redux/sagas/drizzleUtilsSaga.js
  7. 8
      app/src/redux/sagas/orbitSaga.js
  8. 3
      app/src/redux/sagas/transactionsSaga.js
  9. 3
      app/src/redux/sagas/userSaga.js

13
app/src/orbit.js

@ -1,16 +1,17 @@
import IPFS from 'ipfs'; import IPFS from 'ipfs';
import OrbitDB from 'orbit-db'; import OrbitDB from 'orbit-db';
import Keystore from 'orbit-db-keystore'; import Keystore from 'orbit-db-keystore';
import path from 'path'; import path from 'path';
import store from './redux/store'; import store from './redux/store';
import ipfsOptions from './config/ipfsOptions' import ipfsOptions from './config/ipfsOptions'
import { IPFS_INITIALIZED, DATABASES_CREATED, DATABASES_LOADED } from './redux/actions/orbitActions';
let ipfs, orbitdb, topicsDB, postsDB; let ipfs, orbitdb, topicsDB, postsDB;
function initIPFS(){ function initIPFS(){
ipfs = new IPFS(ipfsOptions); ipfs = new IPFS(ipfsOptions);
ipfs.on('ready', async () => { 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'); topicsDB = await orbitdb.keyvalue('topics');
postsDB = await orbitdb.keyvalue('posts'); postsDB = await orbitdb.keyvalue('posts');
store.dispatch({ store.dispatch({
type: "DATABASES_CREATED", type: DATABASES_CREATED,
orbitdb: orbitdb, orbitdb: orbitdb,
topicsDB: topicsDB, topicsDB: topicsDB,
postsDB: postsDB, postsDB: postsDB,
@ -29,7 +30,7 @@ async function createDatabases() {
const orbitKey = orbitdb.keystore.getKey(orbitdb.id); const orbitKey = orbitdb.keystore.getKey(orbitdb.id);
const returnValue = { return {
identityId: "Tempus", identityId: "Tempus",
identityPublicKey: "edax", identityPublicKey: "edax",
identityPrivateKey: "rerum", identityPrivateKey: "rerum",
@ -39,8 +40,6 @@ async function createDatabases() {
topicsDB: topicsDB.address.root, topicsDB: topicsDB.address.root,
postsDB: postsDB.address.root postsDB: postsDB.address.root
}; };
return returnValue;
} }
async function loadDatabases(identityId, identityPublicKey, identityPrivateKey, async function loadDatabases(identityId, identityPublicKey, identityPrivateKey,
@ -62,7 +61,7 @@ async function loadDatabases(identityId, identityPublicKey, identityPrivateKey,
await postsDB.load(); await postsDB.load();
store.dispatch({ store.dispatch({
type: "DATABASES_LOADED", type: DATABASES_LOADED,
orbitdb: orbitdb, orbitdb: orbitdb,
topicsDB: topicsDB, topicsDB: topicsDB,
postsDB: postsDB, postsDB: postsDB,

1
app/src/redux/actions/drizzleUtilsActions.js

@ -0,0 +1 @@
export const DRIZZLE_UTILS_SAGA_INITIALIZED = 'DRIZZLE_UTILS_SAGA_INITIALIZED';

6
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 }

12
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 = { const initialState = {
ipfsInitialized: false, ipfsInitialized: false,
ready: false, ready: false,
@ -9,12 +11,12 @@ const initialState = {
const orbitReducer = (state = initialState, action) => { const orbitReducer = (state = initialState, action) => {
switch (action.type) { switch (action.type) {
case 'IPFS_INITIALIZED': case IPFS_INITIALIZED:
return { return {
...state, ...state,
ipfsInitialized: true ipfsInitialized: true
}; };
case 'DATABASES_CREATED': case DATABASES_CREATED:
return { return {
...state, ...state,
ready: true, ready: true,
@ -23,7 +25,7 @@ const orbitReducer = (state = initialState, action) => {
postsDB: action.postsDB, postsDB: action.postsDB,
id: action.id id: action.id
}; };
case 'DATABASES_LOADED': case DATABASES_LOADED:
return { return {
...state, ...state,
ready: true, ready: true,
@ -32,7 +34,7 @@ const orbitReducer = (state = initialState, action) => {
postsDB: action.postsDB, postsDB: action.postsDB,
id: action.id id: action.id
}; };
case 'DATABASES_NOT_READY': case DATABASES_NOT_READY:
return { return {
...state, ...state,
ready: false, ready: false,
@ -46,4 +48,4 @@ const orbitReducer = (state = initialState, action) => {
} }
}; };
export default orbitReducer; export default orbitReducer;

6
app/src/redux/reducers/userInterfaceReducer.js

@ -1,6 +1,4 @@
import { import { SET_NAVBAR_TITLE } from '../actions/userInterfaceActions';
SET_NAVBAR_TITLE
} from '../actions/userInterfaceActions';
const initialState = { const initialState = {
navBarTitle: '' navBarTitle: ''
@ -11,7 +9,7 @@ const userInterfaceReducer = (state = initialState, action) => {
case SET_NAVBAR_TITLE: case SET_NAVBAR_TITLE:
return { return {
navBarTitle: action.title navBarTitle: action.title
} };
default: default:
return state; return state;
} }

6
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 { call, put, takeLatest, select } from 'redux-saga/effects'
import Forum from '../../contracts/Forum'; import Forum from '../../contracts/Forum';
import { DRIZZLE_UTILS_SAGA_INITIALIZED } from "../actions/drizzleUtilsActions";
const accounts = (state) => state.accounts; const accounts = (state) => state.accounts;
let initFlag, web3, contract; let initFlag, web3, contract;
@ -14,7 +16,7 @@ function* init() {
artifact: Forum artifact: Forum
}); });
initFlag=true; initFlag=true;
yield put({type: 'DRIZZLE_UTILS_SAGA_INITIALIZED', ...[]}); yield put({type: DRIZZLE_UTILS_SAGA_INITIALIZED, ...[]});
} }
else else
console.warn("Attempted to reinitialize drizzleUtilsSaga!"); console.warn("Attempted to reinitialize drizzleUtilsSaga!");
@ -33,4 +35,4 @@ function* drizzleUtilsSaga() {
export { web3, contract, getCurrentAccount } export { web3, contract, getCurrentAccount }
export default drizzleUtilsSaga; export default drizzleUtilsSaga;

8
app/src/redux/sagas/orbitSaga.js

@ -1,6 +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 { contract, getCurrentAccount} from './drizzleUtilsSaga';
import { loadDatabases } from '../../orbit' import { loadDatabases } from '../../orbit'
import { DRIZZLE_UTILS_SAGA_INITIALIZED } from "../actions/drizzleUtilsActions";
import { IPFS_INITIALIZED, DATABASES_NOT_READY } from "../actions/orbitActions";
let latestAccount; let latestAccount;
@ -22,7 +24,7 @@ function* getOrbitDBInfo() {
orbitDBInfo[0], orbitDBInfo[1], orbitDBInfo[2],orbitDBInfo[3], orbitDBInfo[4]); orbitDBInfo[0], orbitDBInfo[1], orbitDBInfo[2],orbitDBInfo[3], orbitDBInfo[4]);
} }
else else
yield put({type: 'DATABASES_NOT_READY', ...[]}); yield put({type: DATABASES_NOT_READY, ...[]});
latestAccount=account; latestAccount=account;
} }
@ -36,8 +38,8 @@ function* getOrbitDBInfo() {
function* orbitSaga() { function* orbitSaga() {
yield all([ yield all([
take("DRIZZLE_UTILS_SAGA_INITIALIZED"), take(DRIZZLE_UTILS_SAGA_INITIALIZED),
take("IPFS_INITIALIZED") take(IPFS_INITIALIZED)
]); ]);
yield takeLatest("ACCOUNT_CHANGED", getOrbitDBInfo); yield takeLatest("ACCOUNT_CHANGED", getOrbitDBInfo);
} }

3
app/src/redux/sagas/transactionsSaga.js

@ -2,6 +2,7 @@ import {call, select, take, takeEvery} from 'redux-saga/effects'
import { drizzle } from '../../index' import { drizzle } from '../../index'
import { orbitSagaPut } from '../../orbit' import { orbitSagaPut } from '../../orbit'
import { DRIZZLE_UTILS_SAGA_INITIALIZED } from "../actions/drizzleUtilsActions";
let transactionsHistory = Object.create(null); let transactionsHistory = Object.create(null);
@ -63,7 +64,7 @@ function* handleError() {
} }
function* transactionsSaga() { function* transactionsSaga() {
yield take("DRIZZLE_UTILS_SAGA_INITIALIZED"); yield take(DRIZZLE_UTILS_SAGA_INITIALIZED);
yield takeEvery("INIT_TRANSACTION", initTransaction); yield takeEvery("INIT_TRANSACTION", initTransaction);
yield takeEvery("EVENT_FIRED", handleEvent); yield takeEvery("EVENT_FIRED", handleEvent);
yield takeEvery("TX_ERROR", handleError); yield takeEvery("TX_ERROR", handleError);

3
app/src/redux/sagas/userSaga.js

@ -1,6 +1,7 @@
import {call, put, select, take, takeEvery} from 'redux-saga/effects' import {call, put, select, take, takeEvery} from 'redux-saga/effects'
import { contract, getCurrentAccount } from './drizzleUtilsSaga'; import { contract, getCurrentAccount } from './drizzleUtilsSaga';
import { DRIZZLE_UTILS_SAGA_INITIALIZED } from "../actions/drizzleUtilsActions";
let account; let account;
@ -45,7 +46,7 @@ function* getUserState(){
} }
function* userSaga() { function* userSaga() {
yield take("DRIZZLE_UTILS_SAGA_INITIALIZED"); yield take(DRIZZLE_UTILS_SAGA_INITIALIZED);
yield takeEvery("ACCOUNTS_FETCHED", updateUserData); yield takeEvery("ACCOUNTS_FETCHED", updateUserData);
} }

Loading…
Cancel
Save