Browse Source

Refactoring

develop
Ezerous 6 years ago
parent
commit
d219e4614f
  1. 1
      app/src/redux/actions/drizzleUtilsActions.js
  2. 1
      app/src/redux/actions/web3UtilsActions.js
  3. 6
      app/src/redux/sagas/orbitSaga.js
  4. 4
      app/src/redux/sagas/rootSaga.js
  5. 4
      app/src/redux/sagas/transactionsSaga.js
  6. 6
      app/src/redux/sagas/userSaga.js
  7. 12
      app/src/redux/sagas/web3UtilsSaga.js
  8. 0
      app/src/utils/web3Utils.js

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

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

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

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

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

@ -1,12 +1,12 @@
import { all, call, put, select, take, takeEvery, takeLatest } from 'redux-saga/effects';
import isEqual from 'lodash.isequal';
import { forumContract, getCurrentAccount } from './drizzleUtilsSaga';
import { forumContract, getCurrentAccount } from './web3UtilsSaga';
import {
createTempDatabases,
loadDatabases,
orbitSagaOpen
} from '../../utils/orbitUtils';
import { DRIZZLE_UTILS_SAGA_INITIALIZED } from '../actions/drizzleUtilsActions';
import { WEB3_UTILS_SAGA_INITIALIZED } from '../actions/web3UtilsActions';
import {
ADD_PEER_DATABASE, PEER_DATABASE_ADDED,
DATABASES_CREATED,
@ -106,7 +106,7 @@ function* updatePeersState() {
function* orbitSaga() {
yield all([
take(DRIZZLE_UTILS_SAGA_INITIALIZED),
take(WEB3_UTILS_SAGA_INITIALIZED),
take(IPFS_INITIALIZED)
]);
yield takeLatest(ACCOUNT_CHANGED, getOrbitDBInfo);

4
app/src/redux/sagas/rootSaga.js

@ -1,6 +1,6 @@
import { all, fork } from 'redux-saga/effects';
import { drizzleSagas } from 'drizzle';
import drizzleUtilsSaga from './drizzleUtilsSaga';
import web3UtilsSaga from './web3UtilsSaga';
import userSaga from './userSaga';
import orbitSaga from './orbitSaga';
import transactionsSaga from './transactionsSaga';
@ -9,7 +9,7 @@ import eventSaga from './eventSaga';
export default function* root() {
const sagas = [
...drizzleSagas,
drizzleUtilsSaga,
web3UtilsSaga,
orbitSaga,
userSaga,
eventSaga,

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

@ -2,7 +2,7 @@ import { call, select, take, takeEvery } from 'redux-saga/effects';
import { drizzle } from '../../index';
import { orbitSagaPut } from '../../utils/orbitUtils';
import { DRIZZLE_UTILS_SAGA_INITIALIZED } from '../actions/drizzleUtilsActions';
import { WEB3_UTILS_SAGA_INITIALIZED } from '../actions/web3UtilsActions';
import { CONTRACT_EVENT_FIRED } from './eventSaga';
const transactionsHistory = Object.create(null);
@ -73,7 +73,7 @@ function* handleError() {
}
function* transactionsSaga() {
yield take(DRIZZLE_UTILS_SAGA_INITIALIZED);
yield take(WEB3_UTILS_SAGA_INITIALIZED);
yield takeEvery('INIT_TRANSACTION', initTransaction);
yield takeEvery(CONTRACT_EVENT_FIRED, handleEvent);
yield takeEvery('TX_ERROR', handleError);

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

@ -1,7 +1,7 @@
import { call, put, select, take, takeEvery } from 'redux-saga/effects';
import { forumContract, getCurrentAccount } from './drizzleUtilsSaga';
import { DRIZZLE_UTILS_SAGA_INITIALIZED } from '../actions/drizzleUtilsActions';
import { forumContract, getCurrentAccount } from './web3UtilsSaga';
import { WEB3_UTILS_SAGA_INITIALIZED } from '../actions/web3UtilsActions';
import {
ACCOUNT_CHANGED,
AUTH_USER_DATA_UPDATED,
@ -61,7 +61,7 @@ function* getUserState() {
}
function* userSaga() {
yield take(DRIZZLE_UTILS_SAGA_INITIALIZED);
yield take(WEB3_UTILS_SAGA_INITIALIZED);
yield takeEvery(ACCOUNTS_FETCHED, updateUserData);
}

12
app/src/redux/sagas/drizzleUtilsSaga.js → app/src/redux/sagas/web3UtilsSaga.js

@ -1,8 +1,8 @@
import { call, put, select, takeLatest } from 'redux-saga/effects';
import { getContractInstance, getWeb3 } from '../../utils/drizzleUtils';
import { getContractInstance, getWeb3 } from '../../utils/web3Utils';
import Forum from '../../contracts/Forum';
import { DRIZZLE_UTILS_SAGA_INITIALIZED } from '../actions/drizzleUtilsActions';
import { WEB3_UTILS_SAGA_INITIALIZED } from '../actions/web3UtilsActions';
import { DRIZZLE_INITIALIZED } from '../actions/drizzleActions';
const accounts = state => state.accounts;
@ -16,10 +16,10 @@ function* init() {
});
initFlag = true;
yield put({
type: DRIZZLE_UTILS_SAGA_INITIALIZED, ...[]
type: WEB3_UTILS_SAGA_INITIALIZED, ...[]
});
}
else console.warn('Attempted to reinitialize drizzleUtilsSaga!');
else console.warn('Attempted to reinitialize web3UtilsSaga!');
}
// If the method below proves to be problematic/ineffective (i.e. getting current account
@ -29,10 +29,10 @@ function* getCurrentAccount() {
return (yield select(accounts))[0];
}
function* drizzleUtilsSaga() {
function* web3UtilsSaga() {
yield takeLatest(DRIZZLE_INITIALIZED, init);
}
export { web3, forumContract, getCurrentAccount };
export default drizzleUtilsSaga;
export default web3UtilsSaga;

0
app/src/utils/drizzleUtils.js → app/src/utils/web3Utils.js

Loading…
Cancel
Save