From 3d6e18d15c6925c41764687f64f35af30a87d1c7 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Fri, 29 Mar 2019 13:58:27 +0200 Subject: [PATCH] Cleanup --- app/package.json | 6 +++--- app/src/redux/actions/drizzleActions.js | 6 ++++++ app/src/redux/actions/orbitActions.js | 4 ++++ app/src/redux/actions/userActions.js | 6 ++++++ app/src/redux/reducers/userReducer.js | 6 ++++-- app/src/redux/sagas/drizzleUtilsSaga.js | 3 ++- app/src/redux/sagas/eventSaga.js | 6 +++--- app/src/redux/sagas/orbitSaga.js | 12 +++++++----- app/src/redux/sagas/userSaga.js | 17 ++++++++++++----- contracts/Forum.sol | 2 +- contracts/Migrations.sol | 2 +- truffle-config.js | 2 +- 12 files changed, 50 insertions(+), 22 deletions(-) create mode 100644 app/src/redux/actions/drizzleActions.js create mode 100644 app/src/redux/actions/userActions.js diff --git a/app/package.json b/app/package.json index 7e13969..3fe27e7 100644 --- a/app/package.json +++ b/app/package.json @@ -15,9 +15,9 @@ "orbit-db": "0.19.9", "orbit-db-keystore": "0.1.0", "prop-types": "15.7.2", - "react": "16.8.5", + "react": "16.8.6", "react-content-loader": "4.2.1", - "react-dom": "16.8.5", + "react-dom": "16.8.6", "react-markdown": "4.0.6", "react-redux": "6.0.1", "react-router-dom": "5.0.0", @@ -28,7 +28,7 @@ "redux-saga": "0.16.2", "semantic-ui-react": "0.86.0", "uuid": "3.3.2", - "web3": "1.0.0-beta.50" + "web3": "1.0.0-beta.51" }, "devDependencies": { "libp2p-websocket-star-rendezvous": "0.3.0" diff --git a/app/src/redux/actions/drizzleActions.js b/app/src/redux/actions/drizzleActions.js new file mode 100644 index 0000000..4e159d9 --- /dev/null +++ b/app/src/redux/actions/drizzleActions.js @@ -0,0 +1,6 @@ +// Actions that are fired internally by Drizzle +const DRIZZLE_INITIALIZED = 'DRIZZLE_INITIALIZED'; +const ACCOUNTS_FETCHED = 'ACCOUNTS_FETCHED'; +const EVENT_FIRED = 'EVENT_FIRED'; + +export { ACCOUNTS_FETCHED, DRIZZLE_INITIALIZED, EVENT_FIRED } diff --git a/app/src/redux/actions/orbitActions.js b/app/src/redux/actions/orbitActions.js index 16ed151..45b3907 100644 --- a/app/src/redux/actions/orbitActions.js +++ b/app/src/redux/actions/orbitActions.js @@ -5,6 +5,8 @@ const DATABASES_NOT_READY = 'DATABASES_NOT_READY'; const ADD_PEER_DATABASE = 'ADD_PEER_DATABASE'; const PEER_DATABASE_ADDED = 'PEER_DATABASE_ADDED'; const UPDATE_PEERS = 'UPDATE_PEERS'; +const ORRBIT_GETTING_INFO = 'ORRBIT_GETTING_INFO'; +const ORBIT_SAGA_ERROR = 'ORBIT_SAGA_ERROR'; function updateDatabases(type, orbitdb, topicsDB, postsDB) { return { @@ -30,6 +32,8 @@ export { DATABASES_CREATED, UPDATE_PEERS, ADD_PEER_DATABASE, PEER_DATABASE_ADDED, + ORRBIT_GETTING_INFO, + ORBIT_SAGA_ERROR, addPeerDatabase, updateDatabases }; diff --git a/app/src/redux/actions/userActions.js b/app/src/redux/actions/userActions.js new file mode 100644 index 0000000..f32cf14 --- /dev/null +++ b/app/src/redux/actions/userActions.js @@ -0,0 +1,6 @@ +const ACCOUNT_CHANGED = 'ACCOUNT_CHANGED'; +const AUTH_USER_DATA_UPDATED = 'AUTH_USER_DATA_UPDATED'; +const GUEST_USER_DATA_UPDATED = 'GUEST_USER_DATA_UPDATED'; +const USER_FETCHING_ERROR = 'USER_FETCHING_ERROR'; + +export { ACCOUNT_CHANGED, AUTH_USER_DATA_UPDATED, GUEST_USER_DATA_UPDATED, USER_FETCHING_ERROR }; diff --git a/app/src/redux/reducers/userReducer.js b/app/src/redux/reducers/userReducer.js index 0e855d8..24ef96b 100644 --- a/app/src/redux/reducers/userReducer.js +++ b/app/src/redux/reducers/userReducer.js @@ -1,3 +1,5 @@ +import { AUTH_USER_DATA_UPDATED, GUEST_USER_DATA_UPDATED } from '../actions/userActions'; + const initialState = { username: '', address: '0x0', @@ -7,13 +9,13 @@ const initialState = { const userReducer = (state = initialState, action) => { switch (action.type) { - case 'USER_DATA_UPDATED_(AUTHENTICATED)': + case AUTH_USER_DATA_UPDATED: return { username: action.username, address: action.address, hasSignedUp: true }; - case 'USER_DATA_UPDATED_(GUEST)': + case GUEST_USER_DATA_UPDATED: return { username: '', address: action.address, diff --git a/app/src/redux/sagas/drizzleUtilsSaga.js b/app/src/redux/sagas/drizzleUtilsSaga.js index e1988f5..3e6bab4 100644 --- a/app/src/redux/sagas/drizzleUtilsSaga.js +++ b/app/src/redux/sagas/drizzleUtilsSaga.js @@ -3,6 +3,7 @@ import { getContractInstance, getWeb3 } from '../../utils/drizzleUtils'; import Forum from '../../contracts/Forum'; import { DRIZZLE_UTILS_SAGA_INITIALIZED } from '../actions/drizzleUtilsActions'; +import { DRIZZLE_INITIALIZED } from '../actions/drizzleActions'; const accounts = state => state.accounts; let initFlag, web3, forumContract; @@ -29,7 +30,7 @@ function* getCurrentAccount() { } function* drizzleUtilsSaga() { - yield takeLatest('DRIZZLE_INITIALIZED', init); + yield takeLatest(DRIZZLE_INITIALIZED, init); } export { web3, forumContract, getCurrentAccount }; diff --git a/app/src/redux/sagas/eventSaga.js b/app/src/redux/sagas/eventSaga.js index f9fd9ef..84f6189 100644 --- a/app/src/redux/sagas/eventSaga.js +++ b/app/src/redux/sagas/eventSaga.js @@ -1,12 +1,12 @@ import { put, takeEvery } from 'redux-saga/effects'; +import { EVENT_FIRED } from '../actions/drizzleActions'; -const EVENT_FIRED = 'EVENT_FIRED'; // This is fired internally by drizzle const CONTRACT_EVENT_FIRED = 'CONTRACT_EVENT_FIRED'; let eventSet = new Set(); -// Entire purpose of this saga is to bypass a strange bug where EVENT_FIRED is called -// multiple times for the same event +// Entire purpose of this saga is to bypass a strange bug where EVENT_FIRED is called multiple times +// for the same event function* sanitizeEvent(action) { const size = eventSet.size; eventSet.add(action.event.transactionHash + action.name); diff --git a/app/src/redux/sagas/orbitSaga.js b/app/src/redux/sagas/orbitSaga.js index 74d6ad8..0e52ca9 100644 --- a/app/src/redux/sagas/orbitSaga.js +++ b/app/src/redux/sagas/orbitSaga.js @@ -7,14 +7,16 @@ import { ADD_PEER_DATABASE, PEER_DATABASE_ADDED, DATABASES_NOT_READY, IPFS_INITIALIZED, - UPDATE_PEERS + UPDATE_PEERS, ORRBIT_GETTING_INFO, ORBIT_SAGA_ERROR } from '../actions/orbitActions'; +import { ACCOUNT_CHANGED } from '../actions/userActions'; +import { ACCOUNTS_FETCHED } from '../actions/drizzleActions'; let latestAccount; function* getOrbitDBInfo() { yield put({ - type: 'ORRBIT_GETTING_INFO', ...[] + type: ORRBIT_GETTING_INFO, ...[] }); const account = yield call(getCurrentAccount); if (account !== latestAccount) { @@ -49,7 +51,7 @@ function* getOrbitDBInfo() { } catch (error) { console.error(error); yield put({ - type: 'ORBIT_SAGA_ERROR', ...[] + type: ORBIT_SAGA_ERROR, ...[] }); } } @@ -95,9 +97,9 @@ function* orbitSaga() { take(DRIZZLE_UTILS_SAGA_INITIALIZED), take(IPFS_INITIALIZED) ]); - yield takeLatest('ACCOUNT_CHANGED', getOrbitDBInfo); + yield takeLatest(ACCOUNT_CHANGED, getOrbitDBInfo); yield takeEvery(ADD_PEER_DATABASE, addPeerDatabase); - yield takeEvery('ACCOUNTS_FETCHED', updatePeersState); + yield takeEvery(ACCOUNTS_FETCHED, updatePeersState); } export default orbitSaga; diff --git a/app/src/redux/sagas/userSaga.js b/app/src/redux/sagas/userSaga.js index 703ec68..d3edcf5 100644 --- a/app/src/redux/sagas/userSaga.js +++ b/app/src/redux/sagas/userSaga.js @@ -2,6 +2,13 @@ import { call, put, select, take, takeEvery } from 'redux-saga/effects'; import { forumContract, getCurrentAccount } from './drizzleUtilsSaga'; import { DRIZZLE_UTILS_SAGA_INITIALIZED } from '../actions/drizzleUtilsActions'; +import { + ACCOUNT_CHANGED, + AUTH_USER_DATA_UPDATED, + GUEST_USER_DATA_UPDATED, + USER_FETCHING_ERROR +} from '../actions/userActions'; +import { ACCOUNTS_FETCHED } from '../actions/drizzleActions'; let account; @@ -10,7 +17,7 @@ function* updateUserData() { if (currentAccount !== account) { account = currentAccount; yield put({ - type: 'ACCOUNT_CHANGED', ...[] + type: ACCOUNT_CHANGED, ...[] }); } const txObj1 = yield call(forumContract.methods.hasUserSignedUp, ...[account]); @@ -30,7 +37,7 @@ function* updateUserData() { username }; yield put({ - type: 'USER_DATA_UPDATED_(AUTHENTICATED)', ...dispatchArgs + type: AUTH_USER_DATA_UPDATED, ...dispatchArgs }); } } else if (account !== userState.address) { @@ -38,13 +45,13 @@ function* updateUserData() { address: account }; yield put({ - type: 'USER_DATA_UPDATED_(GUEST)', ...dispatchArgs + type: GUEST_USER_DATA_UPDATED, ...dispatchArgs }); } } catch (error) { console.error(error); yield put({ - type: 'USER_FETCHING_ERROR', ...[] + type: USER_FETCHING_ERROR, ...[] }); } } @@ -55,7 +62,7 @@ function* getUserState() { function* userSaga() { yield take(DRIZZLE_UTILS_SAGA_INITIALIZED); - yield takeEvery('ACCOUNTS_FETCHED', updateUserData); + yield takeEvery(ACCOUNTS_FETCHED, updateUserData); } export default userSaga; diff --git a/contracts/Forum.sol b/contracts/Forum.sol index 5bb6fcf..b81fa59 100644 --- a/contracts/Forum.sol +++ b/contracts/Forum.sol @@ -1,4 +1,4 @@ -pragma solidity >=0.5.6 <0.6.0; +pragma solidity >=0.5.7 <0.6.0; contract Forum { diff --git a/contracts/Migrations.sol b/contracts/Migrations.sol index f0af7df..c2f001e 100644 --- a/contracts/Migrations.sol +++ b/contracts/Migrations.sol @@ -1,4 +1,4 @@ -pragma solidity >=0.5.6 <0.6.0; +pragma solidity >=0.5.7 <0.6.0; contract Migrations { address public owner; diff --git a/truffle-config.js b/truffle-config.js index e7c33db..9d4e039 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -13,7 +13,7 @@ module.exports = { }, compilers: { solc: { - version: '0.5.6', + version: '0.5.7', settings: { optimizer: { enabled: true,