Browse Source

Refactor configuration, move all configs to env vars files and provide default values

develop
Apostolos Fanakis 4 years ago
parent
commit
740ae09aad
  1. 12
      packages/concordia-app/.env.development.example
  2. 2
      packages/concordia-app/src/components/InitializationScreen/index.jsx
  3. 10
      packages/concordia-app/src/components/PostCreate/index.jsx
  4. 8
      packages/concordia-app/src/components/PostList/PostListRow/index.jsx
  5. 2
      packages/concordia-app/src/components/PostList/index.jsx
  6. 8
      packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx
  7. 2
      packages/concordia-app/src/components/TopicList/index.jsx
  8. 2
      packages/concordia-app/src/constants/PlaceholderTypes.js
  9. 7
      packages/concordia-app/src/constants/configuration/defaults.js
  10. 0
      packages/concordia-app/src/constants/contracts/ContractNames.js
  11. 0
      packages/concordia-app/src/constants/contracts/events/ForumContractEvents.js
  12. 8
      packages/concordia-app/src/constants/contracts/events/index.js
  13. 0
      packages/concordia-app/src/constants/orbit/OrbitDatabases.js
  14. 0
      packages/concordia-app/src/constants/orbit/PostsDatabaseKeys.js
  15. 0
      packages/concordia-app/src/constants/orbit/TopicsDatabaseKeys.js
  16. 0
      packages/concordia-app/src/constants/orbit/UserDatabaseKeys.js
  17. 11
      packages/concordia-app/src/options/breezeOptions.js
  18. 13
      packages/concordia-app/src/options/drizzleOptions.js
  19. 27
      packages/concordia-app/src/options/web3Options.js
  20. 2
      packages/concordia-app/src/redux/actions/contractEventActions.js
  21. 8
      packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js
  22. 2
      packages/concordia-app/src/redux/sagas/userSaga.js
  23. 2
      packages/concordia-app/src/views/Home/index.jsx
  24. 4
      packages/concordia-app/src/views/Profile/GeneralTab/index.jsx
  25. 2
      packages/concordia-app/src/views/Profile/index.jsx
  26. 4
      packages/concordia-app/src/views/Register/PersonalInformationStep/index.jsx
  27. 2
      packages/concordia-app/src/views/Register/SignUpStep/index.jsx
  28. 10
      packages/concordia-app/src/views/Topic/TopicCreate/index.jsx
  29. 8
      packages/concordia-app/src/views/Topic/TopicView/index.jsx

12
packages/concordia-app/.env.development.example

@ -0,0 +1,12 @@
# This is an example development configuration for the app
# To create your own configuration, copy this one and ommit the ".example" from the filename, then change the
# environment cariables to the prefered values.
# Node dev-server host & port
HOST=localhost
PORT=7000
# Variables needed in runtime (in browser)
# Carefull, IPFS won't accept localhost as a valid hostname
REACT_APP_RENDEZVOUS_HOST=localhost
REACT_APP_RENDEZVOUS_PORT=9090

2
packages/concordia-app/src/components/InitializationScreen/index.jsx

@ -5,7 +5,7 @@ import CustomLoader from './CustomLoader';
// CSS
import '../../assets/css/loading-component.css';
import { FORUM_CONTRACT } from '../../constants/ContractNames';
import { FORUM_CONTRACT } from '../../constants/contracts/ContractNames';
const InitializationLoader = ({ children }) => {
const initializing = useSelector((state) => state.drizzleStatus.initializing);

10
packages/concordia-app/src/components/PostCreate/index.jsx

@ -8,15 +8,15 @@ import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
import determineKVAddress from '../../utils/orbitUtils';
import { POSTS_DATABASE, USER_DATABASE } from '../../constants/OrbitDatabases';
import { POSTS_DATABASE, USER_DATABASE } from '../../constants/orbit/OrbitDatabases';
import { FETCH_USER_DATABASE } from '../../redux/actions/peerDbReplicationActions';
import { USER_PROFILE_PICTURE } from '../../constants/UserDatabaseKeys';
import { USER_PROFILE_PICTURE } from '../../constants/orbit/UserDatabaseKeys';
import { breeze, drizzle } from '../../redux/store';
import './styles.css';
import { TRANSACTION_ERROR, TRANSACTION_SUCCESS } from '../../constants/TransactionStatus';
import { POST_CONTENT, POST_SUBJECT } from '../../constants/PostsDatabaseKeys';
import { FORUM_CONTRACT } from '../../constants/ContractNames';
import { POST_CREATED_EVENT } from '../../constants/ForumContractEvents';
import { POST_CONTENT, POST_SUBJECT } from '../../constants/orbit/PostsDatabaseKeys';
import { FORUM_CONTRACT } from '../../constants/contracts/ContractNames';
import { POST_CREATED_EVENT } from '../../constants/contracts/events/ForumContractEvents';
const { contracts: { [FORUM_CONTRACT]: { methods: { createPost } } } } = drizzle;
const { orbit } = breeze;

8
packages/concordia-app/src/components/PostList/PostListRow/index.jsx

@ -12,11 +12,11 @@ import { Link } from 'react-router-dom';
import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions';
import { breeze } from '../../../redux/store';
import './styles.css';
import { POSTS_DATABASE, USER_DATABASE } from '../../../constants/OrbitDatabases';
import { POSTS_DATABASE, USER_DATABASE } from '../../../constants/orbit/OrbitDatabases';
import determineKVAddress from '../../../utils/orbitUtils';
import { USER_PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys';
import { POST_CONTENT, POST_SUBJECT } from '../../../constants/PostsDatabaseKeys';
import { FORUM_CONTRACT } from '../../../constants/ContractNames';
import { USER_PROFILE_PICTURE } from '../../../constants/orbit/UserDatabaseKeys';
import { POST_CONTENT, POST_SUBJECT } from '../../../constants/orbit/PostsDatabaseKeys';
import { FORUM_CONTRACT } from '../../../constants/contracts/ContractNames';
const { orbit } = breeze;

2
packages/concordia-app/src/components/PostList/index.jsx

@ -6,7 +6,7 @@ import { useSelector } from 'react-redux';
import { Dimmer, Feed, Loader } from 'semantic-ui-react';
import PostListRow from './PostListRow';
import { drizzle } from '../../redux/store';
import { FORUM_CONTRACT } from '../../constants/ContractNames';
import { FORUM_CONTRACT } from '../../constants/contracts/ContractNames';
const { contracts: { [FORUM_CONTRACT]: { methods: { getPost: { cacheCall: getPostChainData } } } } } = drizzle;

8
packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx

@ -13,11 +13,11 @@ import { Link } from 'react-router-dom';
import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions';
import { breeze } from '../../../redux/store';
import './styles.css';
import { TOPICS_DATABASE, USER_DATABASE } from '../../../constants/OrbitDatabases';
import { TOPICS_DATABASE, USER_DATABASE } from '../../../constants/orbit/OrbitDatabases';
import determineKVAddress from '../../../utils/orbitUtils';
import { USER_PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys';
import { TOPIC_SUBJECT } from '../../../constants/TopicsDatabaseKeys';
import { FORUM_CONTRACT } from '../../../constants/ContractNames';
import { USER_PROFILE_PICTURE } from '../../../constants/orbit/UserDatabaseKeys';
import { TOPIC_SUBJECT } from '../../../constants/orbit/TopicsDatabaseKeys';
import { FORUM_CONTRACT } from '../../../constants/contracts/ContractNames';
const { orbit } = breeze;

2
packages/concordia-app/src/components/TopicList/index.jsx

@ -6,7 +6,7 @@ import { useSelector } from 'react-redux';
import { List } from 'semantic-ui-react';
import TopicListRow from './TopicListRow';
import { drizzle } from '../../redux/store';
import { FORUM_CONTRACT } from '../../constants/ContractNames';
import { FORUM_CONTRACT } from '../../constants/contracts/ContractNames';
const { contracts: { [FORUM_CONTRACT]: { methods: { getTopic: { cacheCall: getTopicChainData } } } } } = drizzle;

2
packages/concordia-app/src/constants/PlaceholderTypes.js

@ -1,2 +0,0 @@
export const PLACEHOLDER_TYPE_TOPIC = 'PLACEHOLDER_TYPE_TOPIC';
export const PLACEHOLDER_TYPE_POST = 'PLACEHOLDER_TYPE_POST';

7
packages/concordia-app/src/constants/configuration/defaults.js

@ -0,0 +1,7 @@
export const WEB3_HOST_DEFAULT = '127.0.0.1';
export const WEB3_PORT_DEFAULT = '8545';
export const WEB3_PORT_SOCKET_TIMEOUT_DEFAULT = 30000;
export const WEB3_PORT_SOCKET_CONNECT_MAX_ATTEMPTS_DEFAULT = 3;
export const REACT_APP_RENDEZVOUS_HOST_DEFAULT = '127.0.0.1';
export const REACT_APP_RENDEZVOUS_PORT_DEFAULT = '9090';

0
packages/concordia-app/src/constants/ContractNames.js → packages/concordia-app/src/constants/contracts/ContractNames.js

0
packages/concordia-app/src/constants/ForumContractEvents.js → packages/concordia-app/src/constants/contracts/events/ForumContractEvents.js

8
packages/concordia-app/src/constants/contracts/events/index.js

@ -0,0 +1,8 @@
import { FORUM_CONTRACT } from '../ContractNames';
import forumContractEvents from './ForumContractEvents';
const appEvents = {
[FORUM_CONTRACT]: forumContractEvents,
};
export default appEvents;

0
packages/concordia-app/src/constants/OrbitDatabases.js → packages/concordia-app/src/constants/orbit/OrbitDatabases.js

0
packages/concordia-app/src/constants/PostsDatabaseKeys.js → packages/concordia-app/src/constants/orbit/PostsDatabaseKeys.js

0
packages/concordia-app/src/constants/TopicsDatabaseKeys.js → packages/concordia-app/src/constants/orbit/TopicsDatabaseKeys.js

0
packages/concordia-app/src/constants/UserDatabaseKeys.js → packages/concordia-app/src/constants/orbit/UserDatabaseKeys.js

11
packages/concordia-app/src/options/breezeOptions.js

@ -1,5 +1,12 @@
import { EthereumContractIdentityProvider } from '@ezerous/eth-identity-provider';
import databases from '../constants/OrbitDatabases';
import databases from '../constants/orbit/OrbitDatabases';
import {
REACT_APP_RENDEZVOUS_HOST_DEFAULT,
REACT_APP_RENDEZVOUS_PORT_DEFAULT,
} from '../constants/configuration/defaults';
const REACT_APP_RENDEZVOUS_HOST = process.env.REACT_APP_RENDEZVOUS_HOST || REACT_APP_RENDEZVOUS_HOST_DEFAULT;
const REACT_APP_RENDEZVOUS_PORT = process.env.REACT_APP_RENDEZVOUS_PORT || REACT_APP_RENDEZVOUS_PORT_DEFAULT;
const breezeOptions = {
ipfs: {
@ -8,7 +15,7 @@ const breezeOptions = {
Swarm: [
// Use local signaling server (see also rendezvous script in package.json)
// For more information: https://github.com/libp2p/js-libp2p-webrtc-star
'/ip4/127.0.0.1/tcp/9090/wss/p2p-webrtc-star',
`/ip4/${REACT_APP_RENDEZVOUS_HOST}/tcp/${REACT_APP_RENDEZVOUS_PORT}/wss/p2p-webrtc-star`,
// Use the following public servers if needed
// '/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star',

13
packages/concordia-app/src/options/drizzleOptions.js

@ -1,17 +1,12 @@
// See also: https://truffleframework.com/docs/drizzle/reference/drizzle-options
// Check out the documentation: https://truffleframework.com/docs/drizzle/reference/drizzle-options
import { contracts } from 'concordia-contracts';
import web3Options from './web3Options';
import forumContractEvents from '../constants/ForumContractEvents';
import { FORUM_CONTRACT } from '../constants/ContractNames';
import appEvents from '../constants/contracts/events';
const drizzleOptions = {
web3: {
customProvider: web3Options.web3,
},
web3: web3Options,
contracts,
events: {
[FORUM_CONTRACT]: forumContractEvents,
},
events: { ...appEvents },
reloadWindowOnNetworkChange: true,
reloadWindowOnAccountChange: true, // We need it to reinitialize breeze and create new Orbit databases
};

27
packages/concordia-app/src/options/web3Options.js

@ -1,14 +1,29 @@
import Web3 from 'web3';
import {
WEB3_HOST_DEFAULT,
WEB3_PORT_DEFAULT,
WEB3_PORT_SOCKET_CONNECT_MAX_ATTEMPTS_DEFAULT,
WEB3_PORT_SOCKET_TIMEOUT_DEFAULT,
} from '../constants/configuration/defaults';
const { WEB3_URL, WEB3_PORT } = process.env;
const { WEB3_HOST, WEB3_PORT, WEBSOCKET_TIMEOUT } = process.env;
// We need fallback ws://127.0.0.1:8545 because drizzle has not the patched web3 we use here
const web3 = (WEB3_URL && WEB3_PORT)
? `ws://${WEB3_URL}:${WEB3_PORT}`
: new Web3(Web3.givenProvider || new Web3.providers.WebsocketProvider('ws://127.0.0.1:8545'));
const web3WebsocketOptions = {
keepAlive: true,
timeout: WEBSOCKET_TIMEOUT !== undefined ? WEBSOCKET_TIMEOUT : WEB3_PORT_SOCKET_TIMEOUT_DEFAULT,
reconnect: {
maxAttempts: WEB3_PORT_SOCKET_CONNECT_MAX_ATTEMPTS_DEFAULT,
},
};
const web3 = (WEB3_HOST !== undefined && WEB3_PORT !== undefined)
? `ws://${WEB3_HOST}:${WEB3_PORT}`
: new Web3(Web3.givenProvider || new Web3.providers.WebsocketProvider(
`ws://${WEB3_HOST_DEFAULT}:${WEB3_PORT_DEFAULT}`, web3WebsocketOptions,
));
const web3Options = {
web3,
customProvider: web3,
};
export default web3Options;

2
packages/concordia-app/src/redux/actions/contractEventActions.js

@ -3,7 +3,7 @@ import {
TOPIC_CREATED_EVENT,
USER_SIGNED_UP_EVENT,
USERNAME_UPDATED_EVENT,
} from '../../constants/ForumContractEvents';
} from '../../constants/contracts/events/ForumContractEvents';
export const FORUM_EVENT_USER_SIGNED_UP = 'FORUM_EVENT_USER_SIGNED_UP';
export const FORUM_EVENT_USERNAME_UPDATED = 'FORUM_EVENT_USERNAME_UPDATED';

8
packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js

@ -9,10 +9,10 @@ import {
} from '@ezerous/breeze/src/orbit/orbitActions';
import determineKVAddress from '../../utils/orbitUtils';
import { FETCH_USER_DATABASE, UPDATE_ORBIT_DATA } from '../actions/peerDbReplicationActions';
import { POSTS_DATABASE, TOPICS_DATABASE, USER_DATABASE } from '../../constants/OrbitDatabases';
import userDatabaseKeys from '../../constants/UserDatabaseKeys';
import { TOPIC_SUBJECT } from '../../constants/TopicsDatabaseKeys';
import { POST_CONTENT, POST_SUBJECT } from '../../constants/PostsDatabaseKeys';
import { POSTS_DATABASE, TOPICS_DATABASE, USER_DATABASE } from '../../constants/orbit/OrbitDatabases';
import userDatabaseKeys from '../../constants/orbit/UserDatabaseKeys';
import { TOPIC_SUBJECT } from '../../constants/orbit/TopicsDatabaseKeys';
import { POST_CONTENT, POST_SUBJECT } from '../../constants/orbit/PostsDatabaseKeys';
function* fetchUserDb({ orbit, userAddress, dbName }) {
const peerDbAddress = yield call(determineKVAddress, {

2
packages/concordia-app/src/redux/sagas/userSaga.js

@ -5,7 +5,7 @@ import {
import { drizzleActions } from '@ezerous/drizzle';
import { USER_DATA_UPDATED, USER_DATA_ERROR } from '../actions/userActions';
import { FORUM_EVENT_USER_SIGNED_UP } from '../actions/contractEventActions';
import { FORUM_CONTRACT } from '../../constants/ContractNames';
import { FORUM_CONTRACT } from '../../constants/contracts/ContractNames';
function* fetchUserData({ drizzle, account }) {
const contract = drizzle.contracts[FORUM_CONTRACT];

2
packages/concordia-app/src/views/Home/index.jsx

@ -6,7 +6,7 @@ import { useSelector } from 'react-redux';
import Board from './Board';
import './styles.css';
import { drizzle } from '../../redux/store';
import { FORUM_CONTRACT } from '../../constants/ContractNames';
import { FORUM_CONTRACT } from '../../constants/contracts/ContractNames';
const { contracts: { [FORUM_CONTRACT]: { methods: { getNumberOfTopics } } } } = drizzle;

4
packages/concordia-app/src/views/Profile/GeneralTab/index.jsx

@ -7,10 +7,10 @@ import moment from 'moment';
import { useDispatch, useSelector } from 'react-redux';
import { useTranslation } from 'react-i18next';
import determineKVAddress from '../../../utils/orbitUtils';
import databases, { USER_DATABASE } from '../../../constants/OrbitDatabases';
import databases, { USER_DATABASE } from '../../../constants/orbit/OrbitDatabases';
import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions';
import { breeze } from '../../../redux/store';
import { USER_LOCATION, USER_PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys';
import { USER_LOCATION, USER_PROFILE_PICTURE } from '../../../constants/orbit/UserDatabaseKeys';
import './styles.css';
const { orbit } = breeze;

2
packages/concordia-app/src/views/Profile/index.jsx

@ -6,7 +6,7 @@ import { useSelector } from 'react-redux';
import { useHistory, useRouteMatch } from 'react-router';
import { useTranslation } from 'react-i18next';
import { drizzle } from '../../redux/store';
import { FORUM_CONTRACT } from '../../constants/ContractNames';
import { FORUM_CONTRACT } from '../../constants/contracts/ContractNames';
import CustomLoadingTabPane from '../../components/CustomLoadingTabPane';
import TopicList from '../../components/TopicList';
import PostList from '../../components/PostList';

4
packages/concordia-app/src/views/Register/PersonalInformationStep/index.jsx

@ -10,8 +10,8 @@ import { useHistory } from 'react-router';
import checkUrlValid from '../../../utils/urlUtils';
import { breeze } from '../../../redux/store';
import './styles.css';
import { USER_DATABASE } from '../../../constants/OrbitDatabases';
import { USER_LOCATION, USER_PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys';
import { USER_DATABASE } from '../../../constants/orbit/OrbitDatabases';
import { USER_LOCATION, USER_PROFILE_PICTURE } from '../../../constants/orbit/UserDatabaseKeys';
const { orbit: { stores } } = breeze;

2
packages/concordia-app/src/views/Register/SignUpStep/index.jsx

@ -11,7 +11,7 @@ import { useHistory } from 'react-router';
import PropTypes from 'prop-types';
import { drizzle } from '../../../redux/store';
import { TRANSACTION_ERROR, TRANSACTION_SUCCESS } from '../../../constants/TransactionStatus';
import { FORUM_CONTRACT } from '../../../constants/ContractNames';
import { FORUM_CONTRACT } from '../../../constants/contracts/ContractNames';
const { contracts: { [FORUM_CONTRACT]: { methods: { isUserNameTaken, signUp } } } } = drizzle;

10
packages/concordia-app/src/views/Topic/TopicCreate/index.jsx

@ -10,11 +10,11 @@ import { useSelector } from 'react-redux';
import './styles.css';
import { drizzle, breeze } from '../../../redux/store';
import { TRANSACTION_ERROR, TRANSACTION_SUCCESS } from '../../../constants/TransactionStatus';
import { POSTS_DATABASE, TOPICS_DATABASE } from '../../../constants/OrbitDatabases';
import { TOPIC_SUBJECT } from '../../../constants/TopicsDatabaseKeys';
import { POST_CONTENT, POST_SUBJECT } from '../../../constants/PostsDatabaseKeys';
import { FORUM_CONTRACT } from '../../../constants/ContractNames';
import { TOPIC_CREATED_EVENT } from '../../../constants/ForumContractEvents';
import { POSTS_DATABASE, TOPICS_DATABASE } from '../../../constants/orbit/OrbitDatabases';
import { TOPIC_SUBJECT } from '../../../constants/orbit/TopicsDatabaseKeys';
import { POST_CONTENT, POST_SUBJECT } from '../../../constants/orbit/PostsDatabaseKeys';
import { FORUM_CONTRACT } from '../../../constants/contracts/ContractNames';
import { TOPIC_CREATED_EVENT } from '../../../constants/contracts/events/ForumContractEvents';
const { contracts: { [FORUM_CONTRACT]: { methods: { createTopic } } } } = drizzle;
const { orbit: { stores } } = breeze;

8
packages/concordia-app/src/views/Topic/TopicView/index.jsx

@ -11,12 +11,12 @@ import { breeze, drizzle } from '../../../redux/store';
import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions';
import './styles.css';
import PostList from '../../../components/PostList';
import { TOPICS_DATABASE, USER_DATABASE } from '../../../constants/OrbitDatabases';
import { TOPICS_DATABASE, USER_DATABASE } from '../../../constants/orbit/OrbitDatabases';
import determineKVAddress from '../../../utils/orbitUtils';
import { USER_PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys';
import { TOPIC_SUBJECT } from '../../../constants/TopicsDatabaseKeys';
import { USER_PROFILE_PICTURE } from '../../../constants/orbit/UserDatabaseKeys';
import { TOPIC_SUBJECT } from '../../../constants/orbit/TopicsDatabaseKeys';
import PostCreate from '../../../components/PostCreate';
import { FORUM_CONTRACT } from '../../../constants/ContractNames';
import { FORUM_CONTRACT } from '../../../constants/contracts/ContractNames';
const { contracts: { [FORUM_CONTRACT]: { methods: { getTopic: { cacheCall: getTopicChainData } } } } } = drizzle;
const { orbit } = breeze;

Loading…
Cancel
Save