Browse Source

Cleanup

develop
Ezerous 6 years ago
parent
commit
3d6e18d15c
  1. 6
      app/package.json
  2. 6
      app/src/redux/actions/drizzleActions.js
  3. 4
      app/src/redux/actions/orbitActions.js
  4. 6
      app/src/redux/actions/userActions.js
  5. 6
      app/src/redux/reducers/userReducer.js
  6. 3
      app/src/redux/sagas/drizzleUtilsSaga.js
  7. 6
      app/src/redux/sagas/eventSaga.js
  8. 12
      app/src/redux/sagas/orbitSaga.js
  9. 17
      app/src/redux/sagas/userSaga.js
  10. 2
      contracts/Forum.sol
  11. 2
      contracts/Migrations.sol
  12. 2
      truffle-config.js

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

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

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

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

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

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

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

12
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;

17
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;

2
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 {

2
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;

2
truffle-config.js

@ -13,7 +13,7 @@ module.exports = {
},
compilers: {
solc: {
version: '0.5.6',
version: '0.5.7',
settings: {
optimizer: {
enabled: true,

Loading…
Cancel
Save