diff --git a/.gitignore b/.gitignore index 31c619d..6d57d54 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,5 @@ docker/env/contracts.env # Lerna *.lerna_backup + +yarn-clean.sh diff --git a/packages/concordia-app/package.json b/packages/concordia-app/package.json index bbe624a..8727d5a 100644 --- a/packages/concordia-app/package.json +++ b/packages/concordia-app/package.json @@ -30,6 +30,7 @@ "@reduxjs/toolkit": "~1.4.0", "@welldone-software/why-did-you-render": "^6.0.0-rc.1", "concordia-contracts": "~0.1.0", + "concordia-shared": "~0.1.0", "i18next": "^19.8.3", "i18next-browser-languagedetector": "^6.0.1", "i18next-http-backend": "^1.0.21", diff --git a/packages/concordia-app/patches/web3-eth+1.3.3.patch b/packages/concordia-app/patches/web3-eth+1.3.4.patch similarity index 100% rename from packages/concordia-app/patches/web3-eth+1.3.3.patch rename to packages/concordia-app/patches/web3-eth+1.3.4.patch diff --git a/packages/concordia-app/src/components/InitializationScreen/index.jsx b/packages/concordia-app/src/components/InitializationScreen/index.jsx index 7a2dc5a..6ada2b8 100644 --- a/packages/concordia-app/src/components/InitializationScreen/index.jsx +++ b/packages/concordia-app/src/components/InitializationScreen/index.jsx @@ -1,11 +1,11 @@ import React, { Children } from 'react'; import { breezeConstants } from '@ezerous/breeze'; import { useSelector } from 'react-redux'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; import CustomLoader from './CustomLoader'; // CSS import '../../assets/css/loading-component.css'; -import { FORUM_CONTRACT } from '../../constants/contracts/ContractNames'; const InitializationLoader = ({ children }) => { const initializing = useSelector((state) => state.drizzleStatus.initializing); diff --git a/packages/concordia-app/src/components/PostCreate/index.jsx b/packages/concordia-app/src/components/PostCreate/index.jsx index 27d966a..b912417 100644 --- a/packages/concordia-app/src/components/PostCreate/index.jsx +++ b/packages/concordia-app/src/components/PostCreate/index.jsx @@ -7,16 +7,16 @@ import { import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next'; import { useDispatch, useSelector } from 'react-redux'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; +import { POSTS_DATABASE, USER_DATABASE } from 'concordia-shared/src/constants/orbit/OrbitDatabases'; +import { POST_CREATED_EVENT } from 'concordia-shared/src/constants/contracts/events/ForumContractEvents'; import determineKVAddress from '../../utils/orbitUtils'; -import { POSTS_DATABASE, USER_DATABASE } from '../../constants/orbit/OrbitDatabases'; import { FETCH_USER_DATABASE } from '../../redux/actions/peerDbReplicationActions'; 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 } 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; diff --git a/packages/concordia-app/src/components/PostList/PostListRow/index.jsx b/packages/concordia-app/src/components/PostList/PostListRow/index.jsx index 8814374..de93824 100644 --- a/packages/concordia-app/src/components/PostList/PostListRow/index.jsx +++ b/packages/concordia-app/src/components/PostList/PostListRow/index.jsx @@ -9,14 +9,14 @@ import { useTranslation } from 'react-i18next'; import TimeAgo from 'react-timeago'; import { useDispatch, useSelector } from 'react-redux'; import { Link } from 'react-router-dom'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; +import { POSTS_DATABASE, USER_DATABASE } from 'concordia-shared/src/constants/orbit/OrbitDatabases'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; import { breeze } from '../../../redux/store'; import './styles.css'; -import { POSTS_DATABASE, USER_DATABASE } from '../../../constants/orbit/OrbitDatabases'; import determineKVAddress from '../../../utils/orbitUtils'; import { USER_PROFILE_PICTURE } from '../../../constants/orbit/UserDatabaseKeys'; import { POST_CONTENT } from '../../../constants/orbit/PostsDatabaseKeys'; -import { FORUM_CONTRACT } from '../../../constants/contracts/ContractNames'; const { orbit } = breeze; diff --git a/packages/concordia-app/src/components/PostList/index.jsx b/packages/concordia-app/src/components/PostList/index.jsx index a967ccd..504a3a7 100644 --- a/packages/concordia-app/src/components/PostList/index.jsx +++ b/packages/concordia-app/src/components/PostList/index.jsx @@ -4,9 +4,9 @@ import React, { import PropTypes from 'prop-types'; import { useSelector } from 'react-redux'; import { Dimmer, Feed, Loader } from 'semantic-ui-react'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; import PostListRow from './PostListRow'; import { drizzle } from '../../redux/store'; -import { FORUM_CONTRACT } from '../../constants/contracts/ContractNames'; const { contracts: { [FORUM_CONTRACT]: { methods: { getPost: { cacheCall: getPostChainData } } } } } = drizzle; diff --git a/packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx b/packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx index fd96bf4..1a50ba9 100644 --- a/packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx +++ b/packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx @@ -10,14 +10,14 @@ import TimeAgo from 'react-timeago'; import { useHistory } from 'react-router'; import { useDispatch, useSelector } from 'react-redux'; import { Link } from 'react-router-dom'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; +import { TOPICS_DATABASE, USER_DATABASE } from 'concordia-shared/src/constants/orbit/OrbitDatabases'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; import { breeze } from '../../../redux/store'; import './styles.css'; -import { TOPICS_DATABASE, USER_DATABASE } from '../../../constants/orbit/OrbitDatabases'; import determineKVAddress from '../../../utils/orbitUtils'; 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; diff --git a/packages/concordia-app/src/components/TopicList/index.jsx b/packages/concordia-app/src/components/TopicList/index.jsx index 8a85f4e..8a6b9fd 100644 --- a/packages/concordia-app/src/components/TopicList/index.jsx +++ b/packages/concordia-app/src/components/TopicList/index.jsx @@ -4,9 +4,9 @@ import React, { import PropTypes from 'prop-types'; import { useSelector } from 'react-redux'; import { List } from 'semantic-ui-react'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; import TopicListRow from './TopicListRow'; import { drizzle } from '../../redux/store'; -import { FORUM_CONTRACT } from '../../constants/contracts/ContractNames'; const { contracts: { [FORUM_CONTRACT]: { methods: { getTopic: { cacheCall: getTopicChainData } } } } } = drizzle; diff --git a/packages/concordia-app/src/components/UsernameSelector.jsx b/packages/concordia-app/src/components/UsernameSelector.jsx index 8323757..72d9eb3 100644 --- a/packages/concordia-app/src/components/UsernameSelector.jsx +++ b/packages/concordia-app/src/components/UsernameSelector.jsx @@ -6,8 +6,8 @@ import throttle from 'lodash/throttle'; import { useTranslation } from 'react-i18next'; import { useSelector } from 'react-redux'; import PropTypes from 'prop-types'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; import { drizzle } from '../redux/store'; -import { FORUM_CONTRACT } from '../constants/contracts/ContractNames'; const { contracts: { [FORUM_CONTRACT]: { methods: { isUserNameTaken } } } } = drizzle; diff --git a/packages/concordia-app/src/constants/configuration/defaults.js b/packages/concordia-app/src/constants/configuration/defaults.js index c288c9c..5c94c7b 100644 --- a/packages/concordia-app/src/constants/configuration/defaults.js +++ b/packages/concordia-app/src/constants/configuration/defaults.js @@ -1,14 +1,2 @@ -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_CONCORDIA_HOST_DEFAULT = '127.0.0.1'; -export const REACT_APP_CONCORDIA_PORT_DEFAULT = '7000'; - -export const REACT_APP_RENDEZVOUS_HOST_DEFAULT = '127.0.0.1'; -export const REACT_APP_RENDEZVOUS_PORT_DEFAULT = '9090'; - -export const REACT_APP_CONTRACTS_SUPPLIER_HOST_DEFAULT = '127.0.0.1'; -export const REACT_APP_CONTRACTS_SUPPLIER_PORT_DEFAULT = '8400'; -export const REACT_APP_CONTRACTS_VERSION_HASH_DEFAULT = 'latest'; +export const CONCORDIA_HOST_DEFAULT = '127.0.0.1'; +export const CONCORDIA_PORT_DEFAULT = '7000'; diff --git a/packages/concordia-app/src/constants/contracts/ContractNames.js b/packages/concordia-app/src/constants/contracts/ContractNames.js deleted file mode 100644 index 52990a1..0000000 --- a/packages/concordia-app/src/constants/contracts/ContractNames.js +++ /dev/null @@ -1,11 +0,0 @@ -export const FORUM_CONTRACT = 'Forum'; -export const POST_VOTING_CONTRACT = 'PostVoting'; -export const VOTING_CONTRACT = 'Voting'; - -const CONTRACTS = [ - FORUM_CONTRACT, - POST_VOTING_CONTRACT, - VOTING_CONTRACT, -]; - -export default CONTRACTS; diff --git a/packages/concordia-app/src/constants/contracts/events/ForumContractEvents.js b/packages/concordia-app/src/constants/contracts/events/ForumContractEvents.js deleted file mode 100644 index f0f9a34..0000000 --- a/packages/concordia-app/src/constants/contracts/events/ForumContractEvents.js +++ /dev/null @@ -1,13 +0,0 @@ -export const USER_SIGNED_UP_EVENT = 'UserSignedUp'; -export const USERNAME_UPDATED_EVENT = 'UsernameUpdated'; -export const TOPIC_CREATED_EVENT = 'TopicCreated'; -export const POST_CREATED_EVENT = 'PostCreated'; - -const forumContractEvents = [ - USER_SIGNED_UP_EVENT, - USERNAME_UPDATED_EVENT, - TOPIC_CREATED_EVENT, - POST_CREATED_EVENT, -]; - -export default forumContractEvents; diff --git a/packages/concordia-app/src/constants/contracts/events/index.js b/packages/concordia-app/src/constants/contracts/events/index.js deleted file mode 100644 index 870bd36..0000000 --- a/packages/concordia-app/src/constants/contracts/events/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import { FORUM_CONTRACT } from '../ContractNames'; -import forumContractEvents from './ForumContractEvents'; - -const appEvents = { - [FORUM_CONTRACT]: forumContractEvents, -}; - -export default appEvents; diff --git a/packages/concordia-app/src/options/breezeOptions.js b/packages/concordia-app/src/options/breezeOptions.js deleted file mode 100644 index ea38e82..0000000 --- a/packages/concordia-app/src/options/breezeOptions.js +++ /dev/null @@ -1,42 +0,0 @@ -import { EthereumContractIdentityProvider } from '@ezerous/eth-identity-provider'; -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; - -export const RENDEZVOUS_URL = `http://${REACT_APP_RENDEZVOUS_HOST}:${REACT_APP_RENDEZVOUS_PORT}`; - -const breezeOptions = { - ipfs: { - repo: 'concordia', - config: { - Addresses: { - Swarm: [ - // Use local signaling server (see also rendezvous script in package.json) - // For more information: https://github.com/libp2p/js-libp2p-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', - // '/dns4/ wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star' - ], - }, - }, - preload: { - enabled: false, - }, - init: { - emptyRepo: true, - }, - }, - orbit: { - identityProvider: EthereumContractIdentityProvider, - databases, - }, -}; - -export default breezeOptions; diff --git a/packages/concordia-app/src/options/drizzleOptions.js b/packages/concordia-app/src/options/drizzleOptions.js index 9bb664d..ba6b211 100644 --- a/packages/concordia-app/src/options/drizzleOptions.js +++ b/packages/concordia-app/src/options/drizzleOptions.js @@ -1,17 +1,18 @@ // Check out the documentation: https://truffleframework.com/docs/drizzle/reference/drizzle-options import { contracts } from 'concordia-contracts'; -import web3Options from './web3Options'; -import appEvents from '../constants/contracts/events'; +import { getWeb3Configuration } from 'concordia-shared/src/configuration/web3Configuration'; +import Web3 from 'web3'; +import appEvents from 'concordia-shared/src/constants/contracts/events'; import downloadContractArtifactsSync from '../utils/drizzleUtils'; const drizzleOptions = { - web3: web3Options, + web3: getWeb3Configuration(Web3), events: { ...appEvents }, reloadWindowOnNetworkChange: true, reloadWindowOnAccountChange: true, // We need it to reinitialize breeze and create new Orbit databases }; -if (process.env.REACT_APP_USE_EXTERNAL_CONTRACTS_SUPPLIER) { +if (process.env.REACT_APP_USE_EXTERNAL_CONTRACTS_PROVIDER) { drizzleOptions.contracts = downloadContractArtifactsSync(); } else { drizzleOptions.contracts = contracts; diff --git a/packages/concordia-app/src/options/web3Options.js b/packages/concordia-app/src/options/web3Options.js deleted file mode 100644 index ded958c..0000000 --- a/packages/concordia-app/src/options/web3Options.js +++ /dev/null @@ -1,29 +0,0 @@ -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_HOST, WEB3_PORT, WEBSOCKET_TIMEOUT } = process.env; - -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) - ? new Web3(new Web3.providers.WebsocketProvider(`ws://${WEB3_HOST}:${WEB3_PORT}`)) - : new Web3(Web3.givenProvider || new Web3.providers.WebsocketProvider( - `ws://${WEB3_HOST_DEFAULT}:${WEB3_PORT_DEFAULT}`, web3WebsocketOptions, - )); - -const web3Options = { - customProvider: web3, -}; - -export default web3Options; diff --git a/packages/concordia-app/src/redux/actions/contractEventActions.js b/packages/concordia-app/src/redux/actions/contractEventActions.js index a7b250e..36a7aea 100644 --- a/packages/concordia-app/src/redux/actions/contractEventActions.js +++ b/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/contracts/events/ForumContractEvents'; +} from 'concordia-shared/src/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'; diff --git a/packages/concordia-app/src/redux/sagas/orbitSaga.js b/packages/concordia-app/src/redux/sagas/orbitSaga.js index 385295b..1e3a8c4 100644 --- a/packages/concordia-app/src/redux/sagas/orbitSaga.js +++ b/packages/concordia-app/src/redux/sagas/orbitSaga.js @@ -7,7 +7,7 @@ import { drizzleActions } from '@ezerous/drizzle'; import { contracts } from 'concordia-contracts'; import { EthereumContractIdentityProvider } from '@ezerous/eth-identity-provider'; -import { FORUM_CONTRACT } from '../../constants/contracts/ContractNames'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; function* initOrbitDatabases(action) { const { account, breeze } = action; diff --git a/packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js b/packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js index 0ed1896..969195d 100644 --- a/packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js +++ b/packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js @@ -7,9 +7,9 @@ import { ORBIT_DB_REPLICATED, ORBIT_DB_WRITE, } from '@ezerous/breeze/src/orbit/orbitActions'; +import { POSTS_DATABASE, TOPICS_DATABASE, USER_DATABASE } from 'concordia-shared/src/constants/orbit/OrbitDatabases'; import determineKVAddress from '../../utils/orbitUtils'; import { FETCH_USER_DATABASE, UPDATE_ORBIT_DATA } from '../actions/peerDbReplicationActions'; -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 } from '../../constants/orbit/PostsDatabaseKeys'; diff --git a/packages/concordia-app/src/redux/sagas/userSaga.js b/packages/concordia-app/src/redux/sagas/userSaga.js index ac06fd2..ed7ae8b 100644 --- a/packages/concordia-app/src/redux/sagas/userSaga.js +++ b/packages/concordia-app/src/redux/sagas/userSaga.js @@ -3,9 +3,9 @@ import { all, call, put, take, takeLatest, } from 'redux-saga/effects'; import { drizzleActions } from '@ezerous/drizzle'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; import { USER_DATA_UPDATED, USER_DATA_ERROR } from '../actions/userActions'; import { FORUM_EVENT_USER_SIGNED_UP } from '../actions/contractEventActions'; -import { FORUM_CONTRACT } from '../../constants/contracts/ContractNames'; function* fetchUserData({ drizzle, account }) { const contract = drizzle.contracts[FORUM_CONTRACT]; diff --git a/packages/concordia-app/src/redux/store.js b/packages/concordia-app/src/redux/store.js index 8ed1b9e..34dedbe 100644 --- a/packages/concordia-app/src/redux/store.js +++ b/packages/concordia-app/src/redux/store.js @@ -4,11 +4,12 @@ import { } from '@ezerous/drizzle'; import { Breeze, breezeReducers } from '@ezerous/breeze'; import createSagaMiddleware from 'redux-saga'; +import getBreezeConfiguration from 'concordia-shared/src/configuration/breezeConfiguration'; +import { EthereumContractIdentityProvider } from '@ezerous/eth-identity-provider'; import userReducer from './reducers/userReducer'; import rootSaga from './sagas/rootSaga'; import drizzleOptions from '../options/drizzleOptions'; import peerDbReplicationReducer from './reducers/peerDbReplicationReducer'; -import breezeOptions from '../options/breezeOptions'; const initialState = { contracts: generateContractsInitialState(drizzleOptions), @@ -27,8 +28,12 @@ const store = configureStore({ preloadedState: initialState, }); +const breezeConfiguration = getBreezeConfiguration(EthereumContractIdentityProvider, + process.env.REACT_APP_RENDEZVOUS_HOST, + process.env.REACT_APP_RENDEZVOUS_PORT); + export const drizzle = new Drizzle(drizzleOptions, store); -export const breeze = new Breeze(breezeOptions, store); +export const breeze = new Breeze(breezeConfiguration, store); sagaMiddleware.run(rootSaga); export default store; diff --git a/packages/concordia-app/src/utils/drizzleUtils.js b/packages/concordia-app/src/utils/drizzleUtils.js index 5496d85..59208f2 100755 --- a/packages/concordia-app/src/utils/drizzleUtils.js +++ b/packages/concordia-app/src/utils/drizzleUtils.js @@ -1,26 +1,22 @@ +import { CONTRACTS } from 'concordia-shared/src/constants/contracts/ContractNames'; import { - REACT_APP_CONCORDIA_HOST_DEFAULT, - REACT_APP_CONCORDIA_PORT_DEFAULT, - REACT_APP_CONTRACTS_SUPPLIER_HOST_DEFAULT, - REACT_APP_CONTRACTS_SUPPLIER_PORT_DEFAULT, - REACT_APP_CONTRACTS_VERSION_HASH_DEFAULT, + contractsProviderHost, + contractsProviderPort, + contractsVersionHash, +} from 'concordia-shared/src/environment/interpolated/contractsProvider'; +import { + CONCORDIA_HOST_DEFAULT, + CONCORDIA_PORT_DEFAULT, } from '../constants/configuration/defaults'; -import CONTRACTS from '../constants/contracts/ContractNames'; function getContractsDownloadRequest() { - const CONTRACTS_SUPPLIER_HOST = process.env.REACT_APP_CONTRACTS_SUPPLIER_HOST - || REACT_APP_CONTRACTS_SUPPLIER_HOST_DEFAULT; - const CONTRACTS_SUPPLIER_PORT = process.env.REACT_APP_CONTRACTS_SUPPLIER_PORT - || REACT_APP_CONTRACTS_SUPPLIER_PORT_DEFAULT; - const CONTRACTS_VERSION_HASH = process.env.REACT_APP_CONTRACTS_VERSION_HASH - || REACT_APP_CONTRACTS_VERSION_HASH_DEFAULT; - const HOST = process.env.REACT_APP_CONCORDIA_HOST || REACT_APP_CONCORDIA_HOST_DEFAULT; - const PORT = process.env.REACT_APP_CONCORDIA_PORT || REACT_APP_CONCORDIA_PORT_DEFAULT; + const HOST = process.env.REACT_APP_CONCORDIA_HOST || CONCORDIA_HOST_DEFAULT; + const PORT = process.env.REACT_APP_CONCORDIA_PORT || CONCORDIA_PORT_DEFAULT; const xhrRequest = new XMLHttpRequest(); xhrRequest.open('GET', - `http://${CONTRACTS_SUPPLIER_HOST}:${CONTRACTS_SUPPLIER_PORT}/contracts/${CONTRACTS_VERSION_HASH}`, + `http://${contractsProviderHost}:${contractsProviderPort}/contracts/${contractsVersionHash}`, false); xhrRequest.setRequestHeader('Access-Control-Allow-Origin', `${HOST}:${PORT}`); xhrRequest.setRequestHeader('Access-Control-Allow-Credentials', 'true'); @@ -40,7 +36,7 @@ function validateRemoteContracts(remoteContracts) { })); if (contractsPresentStatus.reduce((accumulator, contract) => accumulator && contract.present, true)) { - throw new Error(`Contracts missing from artifacts. Supplier didn't bring ${contractsPresentStatus + throw new Error(`Contracts missing from artifacts. Provider didn't bring ${contractsPresentStatus .filter((contractPresentStatus) => contractPresentStatus.present === false) .map((contractPresentStatus) => contractPresentStatus.contract) .join(', ')}.`); diff --git a/packages/concordia-app/src/views/Home/index.jsx b/packages/concordia-app/src/views/Home/index.jsx index 989d684..73613d5 100644 --- a/packages/concordia-app/src/views/Home/index.jsx +++ b/packages/concordia-app/src/views/Home/index.jsx @@ -3,10 +3,10 @@ import React, { } from 'react'; import { Container } from 'semantic-ui-react'; import { useSelector } from 'react-redux'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; import Board from './Board'; import './styles.css'; import { drizzle } from '../../redux/store'; -import { FORUM_CONTRACT } from '../../constants/contracts/ContractNames'; const { contracts: { [FORUM_CONTRACT]: { methods: { numTopics } } } } = drizzle; diff --git a/packages/concordia-app/src/views/Profile/GeneralTab/EditInformationModal/index.jsx b/packages/concordia-app/src/views/Profile/GeneralTab/EditInformationModal/index.jsx index 1290c7e..d86f395 100644 --- a/packages/concordia-app/src/views/Profile/GeneralTab/EditInformationModal/index.jsx +++ b/packages/concordia-app/src/views/Profile/GeneralTab/EditInformationModal/index.jsx @@ -6,12 +6,12 @@ import { } from 'semantic-ui-react'; import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; +import { USER_DATABASE } from 'concordia-shared/src/constants/orbit/OrbitDatabases'; import checkUrlValid from '../../../../utils/urlUtils'; import { USER_LOCATION, USER_PROFILE_PICTURE } from '../../../../constants/orbit/UserDatabaseKeys'; -import { USER_DATABASE } from '../../../../constants/orbit/OrbitDatabases'; import { breeze, drizzle } from '../../../../redux/store'; import UsernameSelector from '../../../../components/UsernameSelector'; -import { FORUM_CONTRACT } from '../../../../constants/contracts/ContractNames'; const { orbit: { stores } } = breeze; const { contracts: { [FORUM_CONTRACT]: { methods: { updateUsername } } } } = drizzle; diff --git a/packages/concordia-app/src/views/Profile/GeneralTab/index.jsx b/packages/concordia-app/src/views/Profile/GeneralTab/index.jsx index 2515bea..74fd9ef 100644 --- a/packages/concordia-app/src/views/Profile/GeneralTab/index.jsx +++ b/packages/concordia-app/src/views/Profile/GeneralTab/index.jsx @@ -5,8 +5,8 @@ import { import PropTypes from 'prop-types'; import { useDispatch, useSelector } from 'react-redux'; import { useTranslation } from 'react-i18next'; +import { USER_DATABASE, databases } from 'concordia-shared/src/constants/orbit/OrbitDatabases'; import determineKVAddress from '../../../utils/orbitUtils'; -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/orbit/UserDatabaseKeys'; diff --git a/packages/concordia-app/src/views/Profile/index.jsx b/packages/concordia-app/src/views/Profile/index.jsx index 2126536..7751e51 100644 --- a/packages/concordia-app/src/views/Profile/index.jsx +++ b/packages/concordia-app/src/views/Profile/index.jsx @@ -5,8 +5,8 @@ import { Container, Header, Tab } from 'semantic-ui-react'; import { useSelector } from 'react-redux'; import { useHistory, useRouteMatch } from 'react-router'; import { useTranslation } from 'react-i18next'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; import { drizzle } from '../../redux/store'; -import { FORUM_CONTRACT } from '../../constants/contracts/ContractNames'; import CustomLoadingTabPane from '../../components/CustomLoadingTabPane'; import TopicList from '../../components/TopicList'; import PostList from '../../components/PostList'; diff --git a/packages/concordia-app/src/views/Register/PersonalInformationStep/index.jsx b/packages/concordia-app/src/views/Register/PersonalInformationStep/index.jsx index 1ac1cdb..5cf10d9 100644 --- a/packages/concordia-app/src/views/Register/PersonalInformationStep/index.jsx +++ b/packages/concordia-app/src/views/Register/PersonalInformationStep/index.jsx @@ -7,10 +7,10 @@ import { import { useTranslation } from 'react-i18next'; import PropTypes from 'prop-types'; import { useHistory } from 'react-router'; +import { USER_DATABASE } from 'concordia-shared/src/constants/orbit/OrbitDatabases'; import checkUrlValid from '../../../utils/urlUtils'; import { breeze } from '../../../redux/store'; import './styles.css'; -import { USER_DATABASE } from '../../../constants/orbit/OrbitDatabases'; import { USER_LOCATION, USER_PROFILE_PICTURE } from '../../../constants/orbit/UserDatabaseKeys'; const { orbit: { stores } } = breeze; diff --git a/packages/concordia-app/src/views/Register/SignUpStep/index.jsx b/packages/concordia-app/src/views/Register/SignUpStep/index.jsx index 7e8cb8b..e4d494c 100644 --- a/packages/concordia-app/src/views/Register/SignUpStep/index.jsx +++ b/packages/concordia-app/src/views/Register/SignUpStep/index.jsx @@ -6,9 +6,9 @@ import { useTranslation } from 'react-i18next'; import { useSelector } from 'react-redux'; import { useHistory } from 'react-router'; import PropTypes from 'prop-types'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; import { drizzle } from '../../../redux/store'; import { TRANSACTION_ERROR, TRANSACTION_SUCCESS } from '../../../constants/TransactionStatus'; -import { FORUM_CONTRACT } from '../../../constants/contracts/ContractNames'; import UsernameSelector from '../../../components/UsernameSelector'; const { contracts: { [FORUM_CONTRACT]: { methods: { signUp } } } } = drizzle; diff --git a/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx b/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx index 9fa5759..d43157b 100644 --- a/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx +++ b/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx @@ -8,13 +8,13 @@ import { useTranslation } from 'react-i18next'; import { useHistory } from 'react-router'; import { useSelector } from 'react-redux'; import './styles.css'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; +import { TOPIC_CREATED_EVENT } from 'concordia-shared/src/constants/contracts/events/ForumContractEvents'; +import { POSTS_DATABASE, TOPICS_DATABASE } from 'concordia-shared/src/constants/orbit/OrbitDatabases'; import { drizzle, breeze } from '../../../redux/store'; import { TRANSACTION_ERROR, TRANSACTION_SUCCESS } from '../../../constants/TransactionStatus'; -import { POSTS_DATABASE, TOPICS_DATABASE } from '../../../constants/orbit/OrbitDatabases'; import { TOPIC_SUBJECT } from '../../../constants/orbit/TopicsDatabaseKeys'; import { POST_CONTENT } 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; diff --git a/packages/concordia-app/src/views/Topic/TopicView/index.jsx b/packages/concordia-app/src/views/Topic/TopicView/index.jsx index c0ca6c8..406bb2e 100644 --- a/packages/concordia-app/src/views/Topic/TopicView/index.jsx +++ b/packages/concordia-app/src/views/Topic/TopicView/index.jsx @@ -7,16 +7,16 @@ import { import { Link } from 'react-router-dom'; import { useHistory } from 'react-router'; import TimeAgo from 'react-timeago'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; +import { TOPICS_DATABASE, USER_DATABASE } from 'concordia-shared/src/constants/orbit/OrbitDatabases'; 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/orbit/OrbitDatabases'; import determineKVAddress from '../../../utils/orbitUtils'; 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/contracts/ContractNames'; const { contracts: { [FORUM_CONTRACT]: { methods: { getTopic: { cacheCall: getTopicChainData } } } } } = drizzle; const { orbit } = breeze; diff --git a/packages/concordia-contracts-provider/package.json b/packages/concordia-contracts-provider/package.json index 7bdc166..9dd2629 100755 --- a/packages/concordia-contracts-provider/package.json +++ b/packages/concordia-contracts-provider/package.json @@ -5,10 +5,12 @@ "private": true, "main": "src/index.js", "scripts": { - "start": "node -r esm src/index.js" + "start": "node -r esm src/index.js", + "lint": "eslint --ext js,jsx . --format table" }, "license": "MIT", "dependencies": { + "concordia-shared": "~0.1.0", "cors": "^2.8.5", "esm": "~3.2.25", "express": "^4.17.1", diff --git a/packages/concordia-contracts-provider/src/constants.js b/packages/concordia-contracts-provider/src/constants.js index fbe54de..4c65196 100755 --- a/packages/concordia-contracts-provider/src/constants.js +++ b/packages/concordia-contracts-provider/src/constants.js @@ -1,11 +1,9 @@ import path from 'path'; -const PROVIDER_PORT = '8400'; const UPLOAD_CONTRACTS_DIRECTORY = path.join(__dirname, '..', 'contracts-uploads'); const CORS_ALLOWED_ORIGINS = ['http://127.0.0.1:7000', 'http://localhost:7000']; export default { - port: PROVIDER_PORT, uploadsDirectory: UPLOAD_CONTRACTS_DIRECTORY, corsAllowedOrigins: CORS_ALLOWED_ORIGINS, }; diff --git a/packages/concordia-contracts-provider/src/index.js b/packages/concordia-contracts-provider/src/index.js index 0d8ddf4..0b2f2a6 100755 --- a/packages/concordia-contracts-provider/src/index.js +++ b/packages/concordia-contracts-provider/src/index.js @@ -1,9 +1,9 @@ import express from 'express'; import cors from 'cors'; +import { contractsProviderPort } from 'concordia-shared/src/environment/interpolated/contractsProvider'; import initRoutes from './routes/web'; import constants from './constants'; -const PROVIDER_PORT = process.env.CONTRACTS_PROVIDER_PORT || constants.port; const ALLOWED_ORIGINS = process.env.CORS_ALLOWED_ORIGINS ? process.env.CORS_ALLOWED_ORIGINS.split(';') : constants.corsAllowedOrigins; @@ -20,6 +20,6 @@ app.use(cors(corsOptions)); initRoutes(app); -app.listen(PROVIDER_PORT, () => { - console.log(`Contracts provider listening at http://127.0.0.1:${PROVIDER_PORT}`); +app.listen(contractsProviderPort, () => { + console.log(`Contracts provider listening at http://127.0.0.1:${contractsProviderPort}`); }); diff --git a/packages/concordia-contracts/.eslintrc.js b/packages/concordia-contracts/.eslintrc.js index f4fd0dd..eb1cf53 100644 --- a/packages/concordia-contracts/.eslintrc.js +++ b/packages/concordia-contracts/.eslintrc.js @@ -32,7 +32,7 @@ module.exports = { 'no-console': 'warn', 'no-shadow': 'warn', 'no-multi-str': 'warn', - 'one-var': ["error", { "uninitialized": "always" }], + 'one-var': ["error", {"uninitialized": "always"}], 'one-var-declaration-per-line': ['error', 'initializations'] }, 'settings': { diff --git a/packages/concordia-contracts/constants/config/defaults.js b/packages/concordia-contracts/constants/config/defaults.js deleted file mode 100644 index 10941e0..0000000 --- a/packages/concordia-contracts/constants/config/defaults.js +++ /dev/null @@ -1,21 +0,0 @@ -const DEVELOP_CHAIN_HOST_DEFAULT = '127.0.0.1'; -const DEVELOP_CHAIN_PORT_DEFAULT = '8545'; - -const TEST_CHAIN_HOST_DEFAULT = '127.0.0.1'; -const TEST_CHAIN_PORT_DEFAULT = '8546'; - -const CONTRACTS_PROVIDER_HOST_DEFAULT = '127.0.0.1'; -const CONTRACTS_PROVIDER_PORT_DEFAULT = '8400'; - -module.exports = { - develop: { - chainHost: DEVELOP_CHAIN_HOST_DEFAULT, - chainPort: DEVELOP_CHAIN_PORT_DEFAULT, - }, - test: { - chainHost: TEST_CHAIN_HOST_DEFAULT, - chainPort: TEST_CHAIN_PORT_DEFAULT, - }, - contractsProviderHost: CONTRACTS_PROVIDER_HOST_DEFAULT, - contractsProviderPort: CONTRACTS_PROVIDER_PORT_DEFAULT, -}; diff --git a/packages/concordia-contracts/package.json b/packages/concordia-contracts/package.json index 37a9028..6c46a16 100644 --- a/packages/concordia-contracts/package.json +++ b/packages/concordia-contracts/package.json @@ -17,6 +17,7 @@ }, "dependencies": { "@openzeppelin/contracts": "~3.3.0", + "concordia-shared": "~0.1.0", "truffle": "~5.1.58", "unirest": "^0.6.0" }, diff --git a/packages/concordia-contracts/truffle-config.js b/packages/concordia-contracts/truffle-config.js index 6d07a9f..2467673 100644 --- a/packages/concordia-contracts/truffle-config.js +++ b/packages/concordia-contracts/truffle-config.js @@ -1,9 +1,6 @@ const path = require('path'); -const defaults = require('./constants/config/defaults'); - -const { - CHAIN_HOST, CHAIN_PORT, -} = process.env; +const web3EnvInterpolated = require('concordia-shared/src/environment/interpolated/web3'); +const configurationDefaults = require('concordia-shared/src/constants/configuration/defaults'); module.exports = { // See @@ -16,18 +13,18 @@ module.exports = { contracts_build_directory: path.join(__dirname, 'build/'), networks: { develop: { - host: defaults.develop.chainHost, - port: defaults.develop.chainPort, + host: configurationDefaults.web3.develop.chainHost, + port: configurationDefaults.web3.develop.chainPort, network_id: '*', }, test: { - host: defaults.test.chainHost, - port: defaults.test.chainPort, + host: configurationDefaults.web3.test.chainHost, + port: configurationDefaults.web3.test.chainPort, network_id: '*', }, env: { - host: CHAIN_HOST, - port: CHAIN_PORT, + host: web3EnvInterpolated.web3Host, + port: web3EnvInterpolated.web3Port, network_id: '*', }, }, diff --git a/packages/concordia-contracts/utils/contractsProviderUtils.js b/packages/concordia-contracts/utils/contractsProviderUtils.js index 2bd52a3..5777da1 100644 --- a/packages/concordia-contracts/utils/contractsProviderUtils.js +++ b/packages/concordia-contracts/utils/contractsProviderUtils.js @@ -1,13 +1,11 @@ const path = require('path'); const unirest = require('unirest'); +const { contractsProviderHost } = require('concordia-shared/src/environment/interpolated/contractsProvider'); +const { contractsProviderPort } = require('concordia-shared/src/environment/interpolated/contractsProvider'); const { contracts } = require('../index'); -const defaults = require('../constants/config/defaults'); const uploadContractsToProviderUnirest = (versionHash, tag) => { - const CONTRACTS_PROVIDER_HOST = process.env.CONTRACTS_PROVIDER_HOST || defaults.contractsProviderHost; - const CONTRACTS_PROVIDER_PORT = process.env.CONTRACTS_PROVIDER_PORT || defaults.contractsProviderPort; - - const uploadPath = `http://${CONTRACTS_PROVIDER_HOST}:${CONTRACTS_PROVIDER_PORT}/contracts/${versionHash}`; + const uploadPath = `http://${contractsProviderHost}:${contractsProviderPort}/contracts/${versionHash}`; const request = unirest('POST', uploadPath) .field('tag', tag); diff --git a/packages/concordia-pinner/package.json b/packages/concordia-pinner/package.json index 65fa4f8..d5b0ccc 100644 --- a/packages/concordia-pinner/package.json +++ b/packages/concordia-pinner/package.json @@ -6,13 +6,14 @@ "main": "src/index.js", "scripts": { "start": "node -r esm src/index.js", - "clean": "rimraf ipfs orbitdb" + "clean": "rimraf ipfs orbitdb", + "lint": "eslint --ext js,jsx . --format table" }, "license": "MIT", "dependencies": { "@ezerous/eth-identity-provider": "~0.1.2", - "concordia-app": "~0.1.0", "concordia-contracts": "~0.1.0", + "concordia-shared": "~0.1.0", "esm": "~3.2.25", "express": "^4.17.1", "ipfs": "~0.52.1", diff --git a/packages/concordia-pinner/src/app.js b/packages/concordia-pinner/src/app.js index f0eb924..690e450 100644 --- a/packages/concordia-pinner/src/app.js +++ b/packages/concordia-pinner/src/app.js @@ -1,7 +1,9 @@ import express from 'express'; import _ from 'lodash'; import isReachable from 'is-reachable'; -import { API_PORT, RENDEZVOUS_URL, WEB3_PROVIDER_URL } from './constants'; +import { pinnerApiPort } from 'concordia-shared/src/environment/interpolated/pinner'; +import getWeb3ProviderUrl from 'concordia-shared/src/utils/web3'; +import getRendezvousUrl from 'concordia-shared/src/utils/rendezvous'; const POLLING_INTERVAL = 1000; @@ -10,8 +12,8 @@ const responseBody = { id: '', localAddresses: [], peers: [], totalPeers: 0, repoStats: {}, }, orbit: { identity: {}, databases: [] }, - web3: { url: WEB3_PROVIDER_URL, reachable: false }, - rendezvous: { url: RENDEZVOUS_URL, reachable: false }, + web3: { url: getWeb3ProviderUrl(), reachable: false }, + rendezvous: { url: getRendezvousUrl(), reachable: false }, timestamp: 0, }; @@ -26,8 +28,8 @@ async function getStats(orbit) { const uniquePeers = _.uniqBy(peers, 'peer'); const orbitIdentity = orbit.identity; const databases = Object.keys(orbit.stores); - const isWeb3Reachable = await isReachable(WEB3_PROVIDER_URL); - const isRendezvousReachable = await isReachable(RENDEZVOUS_URL); + const isWeb3Reachable = await isReachable(getWeb3ProviderUrl()); + const isRendezvousReachable = await isReachable(getRendezvousUrl()); const timestamp = +new Date(); responseBody.ipfs.id = id; @@ -51,8 +53,8 @@ const startAPI = (orbit) => { res.send(responseBody); }); - app.listen(API_PORT, () => { - console.log(`Pinner API at http://localhost:${API_PORT}!`); + app.listen(pinnerApiPort, () => { + console.log(`Pinner API at http://localhost:${pinnerApiPort}!`); }); setInterval(getStats, POLLING_INTERVAL, orbit); diff --git a/packages/concordia-pinner/src/constants.js b/packages/concordia-pinner/src/constants.js index e837f85..6a8055f 100644 --- a/packages/concordia-pinner/src/constants.js +++ b/packages/concordia-pinner/src/constants.js @@ -1,17 +1,6 @@ -import breezeOptions, { RENDEZVOUS_URL } from 'concordia-app/src/options/breezeOptions'; -import { WEB3_HOST_DEFAULT, WEB3_PORT_DEFAULT } from 'concordia-app/src/constants/configuration/defaults'; import path from 'path'; +import getBreezeConfiguration from 'concordia-shared/src/configuration/breezeConfiguration'; -const { WEB3_HOST, WEB3_PORT } = process.env; - -const API_PORT = process.env.PINNER_API_PORT || 4444; - -const WEB3_PROVIDER_URL = (WEB3_HOST !== undefined && WEB3_PORT !== undefined) - ? `ws://${WEB3_HOST}:${WEB3_PORT}` - : `ws://${WEB3_HOST_DEFAULT}:${WEB3_PORT_DEFAULT}`; - -export const swarmAddresses = breezeOptions.ipfs.config.Addresses.Swarm; +export const swarmAddresses = getBreezeConfiguration().ipfs.config.Addresses.Swarm; export const ORBIT_DIRECTORY_DEFAULT = path.join(__dirname, '..', 'orbitdb'); - -export { API_PORT, WEB3_PROVIDER_URL, RENDEZVOUS_URL }; diff --git a/packages/concordia-pinner/src/index.js b/packages/concordia-pinner/src/index.js index 57566b8..401bced 100644 --- a/packages/concordia-pinner/src/index.js +++ b/packages/concordia-pinner/src/index.js @@ -2,10 +2,10 @@ import Web3 from 'web3'; import Contract from 'web3-eth-contract'; import IPFS from 'ipfs'; import { contracts } from 'concordia-contracts'; -import { FORUM_CONTRACT } from 'concordia-app/src/constants/contracts/ContractNames'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; +import getWeb3ProviderUrl from 'concordia-shared/src/utils/web3'; import { createOrbitInstance, getPeerDatabases, openKVDBs } from './utils/orbitUtils'; import ipfsOptions from './options/ipfsOptions'; -import { WEB3_PROVIDER_URL } from './constants'; import startAPI from './app'; process.on('unhandledRejection', (error) => { @@ -26,7 +26,7 @@ const getDeployedContract = async (web3) => { return web3.eth.net.getId() .then((networkId) => forumContract.networks[networkId].address) .then((contractAddress) => { - Contract.setProvider(WEB3_PROVIDER_URL); + Contract.setProvider(getWeb3ProviderUrl()); const contract = new Contract(forumContract.abi, contractAddress); return { contract, contractAddress }; @@ -54,7 +54,7 @@ const handleWeb3LogEvent = (web3, eventJsonInterface, orbit) => (error, result) const main = async () => { console.log('Initializing...'); - const web3 = new Web3(new Web3.providers.WebsocketProvider(WEB3_PROVIDER_URL)); + const web3 = new Web3(new Web3.providers.WebsocketProvider(getWeb3ProviderUrl())); getDeployedContract(web3) .then(({ contract, contractAddress }) => IPFS.create(ipfsOptions) diff --git a/packages/concordia-shared/.eslintrc.js b/packages/concordia-shared/.eslintrc.js new file mode 100644 index 0000000..96481bd --- /dev/null +++ b/packages/concordia-shared/.eslintrc.js @@ -0,0 +1,60 @@ +module.exports = { + 'env': { + 'browser': true, + 'es6': true, + 'jest': true + }, + 'extends': [ + 'plugin:react/recommended', + 'airbnb' + ], + 'globals': { + 'Atomics': 'readonly', + 'SharedArrayBuffer': 'readonly' + }, + parser: 'babel-eslint', + 'parserOptions': { + 'ecmaFeatures': { + 'jsx': true + }, + 'ecmaVersion': 2018, + 'sourceType': 'module' + }, + 'plugins': [ + 'react', + 'react-hooks', + ], + 'rules': { + 'react/jsx-props-no-spreading': 'off', + 'import/extensions': 'off', + "react/jsx-indent": [ + 'error', + 4, + { + checkAttributes: true, + indentLogicalExpressions: true + } + ], + 'react/require-default-props': 'off', + 'react/prop-types': 'off', + 'react-hooks/rules-of-hooks': 'error', + 'react-hooks/exhaustive-deps': 'error', + 'max-len': ['warn', {'code': 120, 'tabWidth': 4}], + 'no-unused-vars': 'warn', + 'no-console': 'warn', + 'no-shadow': 'warn', + "no-multi-str": "warn", + "jsx-a11y/label-has-associated-control": [ 2, { + "labelAttributes": ["label"], + "controlComponents": ["Input"], + "depth": 3, + }], + }, + 'settings': { + 'import/resolver': { + 'node': { + 'extensions': ['.js', '.jsx'] + } + } + }, +}; diff --git a/packages/concordia-shared/package.json b/packages/concordia-shared/package.json new file mode 100644 index 0000000..a57542d --- /dev/null +++ b/packages/concordia-shared/package.json @@ -0,0 +1,16 @@ +{ + "name": "concordia-shared", + "version": "0.1.0", + "private": true, + "scripts": { + "lint": "eslint --ext js,jsx . --format table" + }, + "devDependencies": { + "eslint": "^6.8.0", + "eslint-config-airbnb": "^18.1.0", + "eslint-plugin-import": "^2.20.2", + "eslint-plugin-jsx-a11y": "^6.2.3", + "eslint-plugin-react": "^7.19.0", + "eslint-plugin-react-hooks": "^4.2.0" + } +} diff --git a/packages/concordia-shared/src/configuration/breezeConfiguration.js b/packages/concordia-shared/src/configuration/breezeConfiguration.js new file mode 100644 index 0000000..e1ab0e0 --- /dev/null +++ b/packages/concordia-shared/src/configuration/breezeConfiguration.js @@ -0,0 +1,33 @@ +const { databases } = require('../constants/orbit/OrbitDatabases'); +const { rendezvousHost, rendezvousPort } = require('../environment/interpolated/rendezvous'); + +const getBreezeConfiguration = (identityProvider) => ({ + ipfs: { + repo: 'concordia', + config: { + Addresses: { + Swarm: [ + // Use local signaling server (see also rendezvous script in package.json) + // For more information: https://github.com/libp2p/js-libp2p-webrtc-star + `/ip4/${rendezvousHost}/tcp/${rendezvousPort}/wss/p2p-webrtc-star`, + + // Use the following public servers if needed + // '/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star', + // '/dns4/ wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star' + ], + }, + }, + preload: { + enabled: false, + }, + init: { + emptyRepo: true, + }, + }, + orbit: { + identityProvider, + databases, + }, +}); + +module.exports = getBreezeConfiguration; diff --git a/packages/concordia-shared/src/configuration/web3Configuration.js b/packages/concordia-shared/src/configuration/web3Configuration.js new file mode 100644 index 0000000..91a10a8 --- /dev/null +++ b/packages/concordia-shared/src/configuration/web3Configuration.js @@ -0,0 +1,25 @@ +const getWeb3ProviderUrl = require('../utils/web3'); +const { web3PortSocketConnectMaxAttempts, web3PortSocketTimeout } = require('../environment/interpolated/web3'); +const { web3HostEnv, web3PortEnv } = require('../environment/web3Env'); + +const getWeb3Configuration = (Web3) => { + const web3WebsocketOptions = { + keepAlive: true, + timeout: web3PortSocketTimeout, + reconnect: { + maxAttempts: web3PortSocketConnectMaxAttempts, + }, + }; + + const web3 = (web3HostEnv !== undefined && web3PortEnv !== undefined) + ? new Web3(new Web3.providers.WebsocketProvider(getWeb3ProviderUrl())) + : new Web3(Web3.givenProvider || new Web3.providers.WebsocketProvider(getWeb3ProviderUrl(), web3WebsocketOptions)); + + return { + customProvider: web3, + }; +}; + +module.exports = { + getWeb3Configuration, +}; diff --git a/packages/concordia-shared/src/constants/configuration/defaults.js b/packages/concordia-shared/src/constants/configuration/defaults.js new file mode 100644 index 0000000..07ee374 --- /dev/null +++ b/packages/concordia-shared/src/constants/configuration/defaults.js @@ -0,0 +1,46 @@ +// Contracts provider +const CONTRACTS_PROVIDER_HOST_DEFAULT = '127.0.0.1'; +const CONTRACTS_PROVIDER_PORT_DEFAULT = '8400'; +const CONTRACTS_VERSION_HASH_DEFAULT = 'latest'; + +// Pinner +const PINNER_API_PORT_DEFAULT = 4444; + +// Rendezvous +const RENDEZVOUS_HOST_DEFAULT = '127.0.0.1'; +const RENDEZVOUS_PORT_DEFAULT = '9090'; + +// Web3 (probably ganache) +const WEB3_HOST_DEFAULT = '127.0.0.1'; +const WEB3_PORT_DEFAULT = '8545'; +const WEB3_HOST_TEST_DEFAULT = '127.0.0.1'; +const WEB3_PORT_TEST_DEFAULT = '8546'; +const WEB3_PORT_SOCKET_TIMEOUT_DEFAULT = 30000; +const WEB3_PORT_SOCKET_CONNECT_MAX_ATTEMPTS_DEFAULT = 3; + +module.exports = Object.freeze({ + contractsProvider: { + host: CONTRACTS_PROVIDER_HOST_DEFAULT, + port: CONTRACTS_PROVIDER_PORT_DEFAULT, + hash: CONTRACTS_VERSION_HASH_DEFAULT, + }, + pinner: { + port: PINNER_API_PORT_DEFAULT, + }, + rendezvous: { + host: RENDEZVOUS_HOST_DEFAULT, + port: RENDEZVOUS_PORT_DEFAULT, + }, + web3: { + develop: { + chainHost: WEB3_HOST_DEFAULT, + chainPort: WEB3_PORT_DEFAULT, + }, + test: { + chainHost: WEB3_HOST_TEST_DEFAULT, + chainPort: WEB3_PORT_TEST_DEFAULT, + }, + socketTimeout: WEB3_PORT_SOCKET_TIMEOUT_DEFAULT, + socketConnectMaxAttempts: WEB3_PORT_SOCKET_CONNECT_MAX_ATTEMPTS_DEFAULT, + }, +}); diff --git a/packages/concordia-shared/src/constants/contracts/ContractNames.js b/packages/concordia-shared/src/constants/contracts/ContractNames.js new file mode 100644 index 0000000..1e6751d --- /dev/null +++ b/packages/concordia-shared/src/constants/contracts/ContractNames.js @@ -0,0 +1,16 @@ +const FORUM_CONTRACT = 'Forum'; +const POST_VOTING_CONTRACT = 'PostVoting'; +const VOTING_CONTRACT = 'Voting'; + +const CONTRACTS = [ + FORUM_CONTRACT, + POST_VOTING_CONTRACT, + VOTING_CONTRACT, +]; + +module.exports = Object.freeze({ + FORUM_CONTRACT, + POST_VOTING_CONTRACT, + VOTING_CONTRACT, + CONTRACTS, +}); diff --git a/packages/concordia-shared/src/constants/contracts/events/ForumContractEvents.js b/packages/concordia-shared/src/constants/contracts/events/ForumContractEvents.js new file mode 100644 index 0000000..4a741db --- /dev/null +++ b/packages/concordia-shared/src/constants/contracts/events/ForumContractEvents.js @@ -0,0 +1,19 @@ +const USER_SIGNED_UP_EVENT = 'UserSignedUp'; +const USERNAME_UPDATED_EVENT = 'UsernameUpdated'; +const TOPIC_CREATED_EVENT = 'TopicCreated'; +const POST_CREATED_EVENT = 'PostCreated'; + +const forumContractEvents = Object.freeze([ + USER_SIGNED_UP_EVENT, + USERNAME_UPDATED_EVENT, + TOPIC_CREATED_EVENT, + POST_CREATED_EVENT, +]); + +module.exports = { + USER_SIGNED_UP_EVENT, + USERNAME_UPDATED_EVENT, + TOPIC_CREATED_EVENT, + POST_CREATED_EVENT, + forumContractEvents, +}; diff --git a/packages/concordia-shared/src/constants/contracts/events/index.js b/packages/concordia-shared/src/constants/contracts/events/index.js new file mode 100644 index 0000000..09e71a3 --- /dev/null +++ b/packages/concordia-shared/src/constants/contracts/events/index.js @@ -0,0 +1,8 @@ +const forumContractEvents = require('./ForumContractEvents'); +const { FORUM_CONTRACT } = require('../ContractNames'); + +const appEvents = Object.freeze({ + [FORUM_CONTRACT]: forumContractEvents, +}); + +module.exports = appEvents; diff --git a/packages/concordia-app/src/constants/orbit/OrbitDatabases.js b/packages/concordia-shared/src/constants/orbit/OrbitDatabases.js similarity index 50% rename from packages/concordia-app/src/constants/orbit/OrbitDatabases.js rename to packages/concordia-shared/src/constants/orbit/OrbitDatabases.js index bf85018..75048f6 100644 --- a/packages/concordia-app/src/constants/orbit/OrbitDatabases.js +++ b/packages/concordia-shared/src/constants/orbit/OrbitDatabases.js @@ -1,6 +1,6 @@ -export const USER_DATABASE = 'user'; -export const TOPICS_DATABASE = 'topics'; -export const POSTS_DATABASE = 'posts'; +const USER_DATABASE = 'user'; +const TOPICS_DATABASE = 'topics'; +const POSTS_DATABASE = 'posts'; const databases = [ { @@ -17,4 +17,9 @@ const databases = [ }, ]; -export default databases; +module.exports = Object.freeze({ + USER_DATABASE, + TOPICS_DATABASE, + POSTS_DATABASE, + databases, +}); diff --git a/packages/concordia-shared/src/environment/contractsProviderEnv.js b/packages/concordia-shared/src/environment/contractsProviderEnv.js new file mode 100644 index 0000000..3a545ca --- /dev/null +++ b/packages/concordia-shared/src/environment/contractsProviderEnv.js @@ -0,0 +1,14 @@ +// Depending on the package user (app in contrast to any of the other packages) the env var names should either include +// the REACT_APP_ prefix or not +const contractsProviderHostEnv = process.env.REACT_APP_CONTRACTS_PROVIDER_HOST + || process.env.CONTRACTS_PROVIDER_HOST; +const contractsProviderPortEnv = process.env.REACT_APP_CONTRACTS_PROVIDER_PORT + || process.env.CONTRACTS_PROVIDER_PORT; +const contractsVersionHashEnv = process.env.REACT_APP_CONTRACTS_VERSION_HASH + || process.env.CONTRACTS_VERSION_HASH; + +module.exports = { + contractsProviderHostEnv, + contractsProviderPortEnv, + contractsVersionHashEnv, +}; diff --git a/packages/concordia-shared/src/environment/interpolated/contractsProvider.js b/packages/concordia-shared/src/environment/interpolated/contractsProvider.js new file mode 100644 index 0000000..ea4537e --- /dev/null +++ b/packages/concordia-shared/src/environment/interpolated/contractsProvider.js @@ -0,0 +1,21 @@ +const { + contractsProviderHostEnv, contractsProviderPortEnv, contractsVersionHashEnv, +} = require('../contractsProviderEnv'); + +const { + contractsProvider: { + host: CONTRACTS_PROVIDER_HOST_DEFAULT, + port: CONTRACTS_PROVIDER_PORT_DEFAULT, + hash: CONTRACTS_VERSION_HASH_DEFAULT, + }, +} = require('../../constants/configuration/defaults'); + +const contractsProviderHost = contractsProviderHostEnv || CONTRACTS_PROVIDER_HOST_DEFAULT; +const contractsProviderPort = contractsProviderPortEnv || CONTRACTS_PROVIDER_PORT_DEFAULT; +const contractsVersionHash = contractsVersionHashEnv || CONTRACTS_VERSION_HASH_DEFAULT; + +module.exports = { + contractsProviderHost, + contractsProviderPort, + contractsVersionHash, +}; diff --git a/packages/concordia-shared/src/environment/interpolated/pinner.js b/packages/concordia-shared/src/environment/interpolated/pinner.js new file mode 100644 index 0000000..5c81a88 --- /dev/null +++ b/packages/concordia-shared/src/environment/interpolated/pinner.js @@ -0,0 +1,12 @@ +const { + pinner: { + port: PINNER_API_PORT_DEFAULT, + }, +} = require('../../constants/configuration/defaults'); +const { pinnerApiPortEnv } = require('../pinnerEnv'); + +const pinnerApiPort = pinnerApiPortEnv || PINNER_API_PORT_DEFAULT; + +module.exports = { + pinnerApiPort, +}; diff --git a/packages/concordia-shared/src/environment/interpolated/rendezvous.js b/packages/concordia-shared/src/environment/interpolated/rendezvous.js new file mode 100644 index 0000000..d683408 --- /dev/null +++ b/packages/concordia-shared/src/environment/interpolated/rendezvous.js @@ -0,0 +1,15 @@ +const { rendezvousHostEnv, rendezvousPortEnv } = require('../rendezvousEnv'); +const { + rendezvous: { + host: RENDEZVOUS_HOST_DEFAULT, + port: RENDEZVOUS_PORT_DEFAULT, + }, +} = require('../../constants/configuration/defaults'); + +const rendezvousHost = rendezvousHostEnv || RENDEZVOUS_HOST_DEFAULT; +const rendezvousPort = rendezvousPortEnv || RENDEZVOUS_PORT_DEFAULT; + +module.exports = { + rendezvousHost, + rendezvousPort, +}; diff --git a/packages/concordia-shared/src/environment/interpolated/shared.js b/packages/concordia-shared/src/environment/interpolated/shared.js new file mode 100644 index 0000000..6cf342a --- /dev/null +++ b/packages/concordia-shared/src/environment/interpolated/shared.js @@ -0,0 +1,9 @@ +const contractsProvider = require('./contractsProvider'); +const rendezvous = require('./rendezvous'); +const web3 = require('./web3'); + +module.exports = { + contractsProvider, + rendezvous, + web3, +}; diff --git a/packages/concordia-shared/src/environment/interpolated/web3.js b/packages/concordia-shared/src/environment/interpolated/web3.js new file mode 100644 index 0000000..4fe1e9d --- /dev/null +++ b/packages/concordia-shared/src/environment/interpolated/web3.js @@ -0,0 +1,37 @@ +const { + web3: { + develop: { + chainHost: WEB3_HOST_DEFAULT, + chainPort: WEB3_PORT_DEFAULT, + }, + test: { + chainHost: WEB3_HOST_TEST_DEFAULT, + chainPort: WEB3_PORT_TEST_DEFAULT, + }, + socketConnectMaxAttempts: WEB3_PORT_SOCKET_CONNECT_MAX_ATTEMPTS_DEFAULT, + socketTimeout: WEB3_PORT_SOCKET_TIMEOUT_DEFAULT, + }, +} = require('../../constants/configuration/defaults'); +const { + web3HostEnv, web3HostTestEnv, web3PortEnv, web3PortSocketConnectMaxAttemptsEnv, web3PortSocketTimeoutEnv, + web3PortTestEnv, +} = require('../web3Env'); + +const web3Host = web3HostEnv || WEB3_HOST_DEFAULT; +const web3Port = web3PortEnv || WEB3_PORT_DEFAULT; + +const web3HostTest = web3HostTestEnv || WEB3_HOST_TEST_DEFAULT; +const web3PortTest = web3PortTestEnv || WEB3_PORT_TEST_DEFAULT; + +const web3PortSocketTimeout = web3PortSocketTimeoutEnv || WEB3_PORT_SOCKET_TIMEOUT_DEFAULT; +const web3PortSocketConnectMaxAttempts = web3PortSocketConnectMaxAttemptsEnv + || WEB3_PORT_SOCKET_CONNECT_MAX_ATTEMPTS_DEFAULT; + +module.exports = { + web3Host, + web3Port, + web3HostTest, + web3PortTest, + web3PortSocketTimeout, + web3PortSocketConnectMaxAttempts, +}; diff --git a/packages/concordia-shared/src/environment/pinnerEnv.js b/packages/concordia-shared/src/environment/pinnerEnv.js new file mode 100644 index 0000000..2ab5cbf --- /dev/null +++ b/packages/concordia-shared/src/environment/pinnerEnv.js @@ -0,0 +1,7 @@ +// Depending on the package user (app in contrast to any of the other packages) the env var names should either include +// the REACT_APP_ prefix or not +const pinnerApiPortEnv = process.env.REACT_APP_PINNER_API_PORT || process.env.PINNER_API_PORT; + +module.exports = { + pinnerApiPortEnv, +}; diff --git a/packages/concordia-shared/src/environment/rendezvousEnv.js b/packages/concordia-shared/src/environment/rendezvousEnv.js new file mode 100644 index 0000000..44f8965 --- /dev/null +++ b/packages/concordia-shared/src/environment/rendezvousEnv.js @@ -0,0 +1,9 @@ +// Depending on the package user (app in contrast to any of the other packages) the env var names should either include +// the REACT_APP_ prefix or not +const rendezvousHostEnv = process.env.REACT_APP_RENDEZVOUS_HOST || process.env.RENDEZVOUS_HOST; +const rendezvousPortEnv = process.env.REACT_APP_RENDEZVOUS_PORT || process.env.RENDEZVOUS_PORT; + +module.exports = { + rendezvousHostEnv, + rendezvousPortEnv, +}; diff --git a/packages/concordia-shared/src/environment/sharedEnv.js b/packages/concordia-shared/src/environment/sharedEnv.js new file mode 100644 index 0000000..28c2920 --- /dev/null +++ b/packages/concordia-shared/src/environment/sharedEnv.js @@ -0,0 +1,9 @@ +const contractsProvider = require('./contractsProviderEnv'); +const rendezvous = require('./rendezvousEnv'); +const web3 = require('./web3Env'); + +module.exports = { + contractsProvider, + rendezvous, + web3, +}; diff --git a/packages/concordia-shared/src/environment/web3Env.js b/packages/concordia-shared/src/environment/web3Env.js new file mode 100644 index 0000000..7bc2041 --- /dev/null +++ b/packages/concordia-shared/src/environment/web3Env.js @@ -0,0 +1,24 @@ +// Depending on the package user (app in contrast to any of the other packages) the env var names should either include +// the REACT_APP_ prefix or not +const web3HostEnv = process.env.REACT_APP_WEB3_HOST + || process.env.WEB3_HOST; +const web3PortEnv = process.env.REACT_APP_WEB3_PORT + || process.env.WEB3_PORT; + +// Web3 test environment shouldn't be available to the react app +const web3HostTestEnv = process.env.WEB3_HOST_TEST; +const web3PortTestEnv = process.env.WEB3_PORT_TEST; + +const web3PortSocketTimeoutEnv = process.env.REACT_APP_WEB3_PORT_SOCKET_TIMEOUT + || process.env.WEB3_PORT_SOCKET_TIMEOUT; +const web3PortSocketConnectMaxAttemptsEnv = process.env.REACT_APP_WEB3_PORT_SOCKET_CONNECT_MAX_ATTEMPTS + || process.env.WEB3_PORT_SOCKET_CONNECT_MAX_ATTEMPTS; + +module.exports = { + web3HostEnv, + web3PortEnv, + web3HostTestEnv, + web3PortTestEnv, + web3PortSocketTimeoutEnv, + web3PortSocketConnectMaxAttemptsEnv, +}; diff --git a/packages/concordia-shared/src/utils/rendezvous.js b/packages/concordia-shared/src/utils/rendezvous.js new file mode 100644 index 0000000..8d862fc --- /dev/null +++ b/packages/concordia-shared/src/utils/rendezvous.js @@ -0,0 +1,5 @@ +const { rendezvousHost, rendezvousPort } = require('../environment/interpolated/rendezvous'); + +const getRendezvousUrl = () => `http://${rendezvousHost}:${rendezvousPort}`; + +module.exports = getRendezvousUrl; diff --git a/packages/concordia-shared/src/utils/web3.js b/packages/concordia-shared/src/utils/web3.js new file mode 100644 index 0000000..4c7adc8 --- /dev/null +++ b/packages/concordia-shared/src/utils/web3.js @@ -0,0 +1,6 @@ +const { web3Port } = require('../environment/interpolated/web3'); +const { web3Host } = require('../environment/interpolated/web3'); + +const getWeb3ProviderUrl = () => `ws://${web3Host}:${web3Port}`; + +module.exports = getWeb3ProviderUrl; diff --git a/yarn.lock b/yarn.lock index 33dc661..9f8b3cd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5762,9 +5762,9 @@ ee-first@1.1.1: integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= ejs@^3.1.5: - version "3.1.5" - resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.5.tgz#aed723844dc20acb4b170cd9ab1017e476a0d93b" - integrity sha512-dldq3ZfFtgVTJMLjOe+/3sROTzALlL9E34V4/sDtUd/KlBSS0s6U1/+WPE1B4sj9CXHJpL1M6rhNJnc9Wbal9w== + version "3.1.6" + resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.6.tgz#5bfd0a0689743bb5268b3550cceeebbc1702822a" + integrity sha512-9lt9Zse4hPucPkoP7FHDF0LQAlGyF9JVpnClFLFH3aSSbxmyoqINRpp/9wePWJTUl4KOQwRL72Iw3InHPDkoGw== dependencies: jake "^10.6.1"