Browse Source

Minor actions cleanup

develop
Ezerous 6 years ago
parent
commit
1b112477d0
  1. 11
      app/src/orbit.js
  2. 1
      app/src/redux/actions/drizzleUtilsActions.js
  3. 6
      app/src/redux/actions/orbitActions.js
  4. 10
      app/src/redux/reducers/orbitReducer.js
  5. 6
      app/src/redux/reducers/userInterfaceReducer.js
  6. 4
      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

11
app/src/orbit.js

@ -4,13 +4,14 @@ 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,

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 }

10
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,

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

4
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!");

8
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);
}

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 { 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);

3
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);
}

Loading…
Cancel
Save