Browse Source

Move all contract and event names to constants

develop
Apostolos Fanakis 4 years ago
parent
commit
c1c6341ddf
  1. 5
      packages/concordia-app/src/components/LoadingContainer.jsx
  2. 3
      packages/concordia-app/src/components/PostList/PostListRow/index.jsx
  3. 3
      packages/concordia-app/src/components/PostList/index.jsx
  4. 3
      packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx
  5. 3
      packages/concordia-app/src/components/TopicList/index.jsx
  6. 2
      packages/concordia-app/src/constants/ContractNames.js
  7. 13
      packages/concordia-app/src/constants/ForumContractEvents.js
  8. 4
      packages/concordia-app/src/options/drizzleOptions.js
  9. 24
      packages/concordia-app/src/redux/actions/contractEventActions.js
  10. 3
      packages/concordia-app/src/redux/sagas/eventSaga.js
  11. 4
      packages/concordia-app/src/redux/sagas/userSaga.js
  12. 5
      packages/concordia-app/src/views/Home/index.jsx
  13. 5
      packages/concordia-app/src/views/Register/SignUpStep/index.jsx
  14. 6
      packages/concordia-app/src/views/Topic/TopicCreate/index.jsx
  15. 5
      packages/concordia-app/src/views/Topic/TopicView/index.jsx

5
packages/concordia-app/src/components/LoadingContainer.jsx

@ -5,6 +5,7 @@ import LoadingComponent from './LoadingComponent';
// CSS
import '../assets/css/loading-component.css';
import { FORUM_CONTRACT } from '../constants/ContractNames';
const LoadingContainer = ({ children }) => {
const initializing = useSelector((state) => state.drizzleStatus.initializing);
@ -15,8 +16,8 @@ const LoadingContainer = ({ children }) => {
const web3NetworkId = useSelector((state) => state.web3.networkId);
const web3NetworkFailed = useSelector((state) => state.web3.networkFailed);
const web3AccountsFailed = useSelector((state) => state.web3.accountsFailed);
const contractInitialized = useSelector((state) => state.contracts.Forum.initialized);
const contractDeployed = useSelector((state) => state.contracts.Forum.deployed);
const contractInitialized = useSelector((state) => state.contracts[FORUM_CONTRACT].initialized);
const contractDeployed = useSelector((state) => state.contracts[FORUM_CONTRACT].deployed);
const userFetched = useSelector((state) => state.user.address);
if ((web3Status === 'initializing' || !web3NetworkId)

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

@ -16,12 +16,13 @@ import { POSTS_DATABASE, USER_DATABASE } from '../../../constants/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';
const { orbit } = breeze;
const PostListRow = (props) => {
const { id: postId, postCallHash, loading } = props;
const getPostResults = useSelector((state) => state.contracts.Forum.getPost);
const getPostResults = useSelector((state) => state.contracts[FORUM_CONTRACT].getPost);
const [postAuthorAddress, setPostAuthorAddress] = useState(null);
const [postAuthor, setPostAuthor] = useState(null);
const [timeAgo, setTimeAgo] = useState(null);

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

@ -6,8 +6,9 @@ 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';
const { contracts: { Forum: { methods: { getPost: { cacheCall: getPostChainData } } } } } = drizzle;
const { contracts: { [FORUM_CONTRACT]: { methods: { getPost: { cacheCall: getPostChainData } } } } } = drizzle;
const PostList = (props) => {
const { postIds, loading } = props;

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

@ -16,12 +16,13 @@ import { TOPICS_DATABASE, USER_DATABASE } from '../../../constants/OrbitDatabase
import determineKVAddress from '../../../utils/orbitUtils';
import { USER_PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys';
import { TOPIC_SUBJECT } from '../../../constants/TopicsDatabaseKeys';
import { FORUM_CONTRACT } from '../../../constants/ContractNames';
const { orbit } = breeze;
const TopicListRow = (props) => {
const { id: topicId, topicCallHash, loading } = props;
const getTopicResults = useSelector((state) => state.contracts.Forum.getTopic);
const getTopicResults = useSelector((state) => state.contracts[FORUM_CONTRACT].getTopic);
const [numberOfReplies, setNumberOfReplies] = useState(null);
const [topicAuthorAddress, setTopicAuthorAddress] = useState(null);
const [topicAuthor, setTopicAuthor] = useState(null);

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

@ -6,8 +6,9 @@ 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';
const { contracts: { Forum: { methods: { getTopic: { cacheCall: getTopicChainData } } } } } = drizzle;
const { contracts: { [FORUM_CONTRACT]: { methods: { getTopic: { cacheCall: getTopicChainData } } } } } = drizzle;
const TopicList = (props) => {
const { topicIds } = props;

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

@ -1 +1 @@
export const FORUM = 'Forum';
export const FORUM_CONTRACT = 'Forum';

13
packages/concordia-app/src/constants/ForumContractEvents.js

@ -0,0 +1,13 @@
export const USER_SIGNED_UP_EVENT = 'USER_SIGNED_UP';
export const USERNAME_UPDATED_EVENT = 'USERNAME_UPDATED';
export const TOPIC_CREATED_EVENT = 'TOPIC_CREATED';
export const POST_CREATED_EVENT = 'POST_CREATED';
const forumContractEvents = [
USER_SIGNED_UP_EVENT,
USERNAME_UPDATED_EVENT,
TOPIC_CREATED_EVENT,
POST_CREATED_EVENT,
];
export default forumContractEvents;

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

@ -1,6 +1,8 @@
// See also: 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';
const drizzleOptions = {
web3: {
@ -8,7 +10,7 @@ const drizzleOptions = {
},
contracts,
events: {
Forum: ['UserSignedUp', 'UsernameUpdated', 'TopicCreated', 'PostCreated'],
[FORUM_CONTRACT]: forumContractEvents,
},
reloadWindowOnNetworkChange: true,
reloadWindowOnAccountChange: true, // We need it to reinitialize breeze and create new Orbit databases

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

@ -1,4 +1,20 @@
export const FORUM_EVENT_USER_SIGNED_UP = 'UserSignedUp';
export const FORUM_EVENT_USERNAME_UPDATED = 'UsernameUpdated';
export const FORUM_EVENT_TOPIC_CREATED = 'TopicCreated';
export const FORUM_EVENT_POST_CREATED = 'PostCreated';
import {
POST_CREATED_EVENT,
TOPIC_CREATED_EVENT,
USER_SIGNED_UP_EVENT,
USERNAME_UPDATED_EVENT,
} from '../../constants/ForumContractEvents';
export const FORUM_EVENT_USER_SIGNED_UP = 'FORUM_EVENT_USER_SIGNED_UP';
export const FORUM_EVENT_USERNAME_UPDATED = 'FORUM_EVENT_USERNAME_UPDATED';
export const FORUM_EVENT_TOPIC_CREATED = 'FORUM_EVENT_TOPIC_CREATED';
export const FORUM_EVENT_POST_CREATED = 'FORUM_EVENT_POST_CREATED';
const eventActionMap = {
[USER_SIGNED_UP_EVENT]: FORUM_EVENT_USER_SIGNED_UP,
[USERNAME_UPDATED_EVENT]: FORUM_EVENT_USERNAME_UPDATED,
[TOPIC_CREATED_EVENT]: FORUM_EVENT_TOPIC_CREATED,
[POST_CREATED_EVENT]: FORUM_EVENT_POST_CREATED,
};
export default eventActionMap;

3
packages/concordia-app/src/redux/sagas/eventSaga.js

@ -1,8 +1,9 @@
import { put, takeEvery } from 'redux-saga/effects';
import { CONTRACT_EVENT_FIRED } from '@ezerous/drizzle/src/contracts/constants';
import eventActionMap from '../actions/contractEventActions';
function* eventBreakDown({ event }) {
yield put({ type: event.event, event: { ...event } });
yield put({ type: eventActionMap[event.event], event: { ...event } });
}
function* eventSaga() {

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

@ -2,13 +2,13 @@
import {
all, call, put, take, takeLatest,
} from 'redux-saga/effects';
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';
function* fetchUserData({ drizzle, account }) {
const contract = drizzle.contracts.Forum;
const contract = drizzle.contracts[FORUM_CONTRACT];
const transaction = yield call(contract.methods.hasUserSignedUp, account);
try {

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

@ -6,12 +6,13 @@ import { useSelector } from 'react-redux';
import Board from './Board';
import './styles.css';
import { drizzle } from '../../redux/store';
import { FORUM_CONTRACT } from '../../constants/ContractNames';
const { contracts: { Forum: { methods: { getNumberOfTopics } } } } = drizzle;
const { contracts: { [FORUM_CONTRACT]: { methods: { getNumberOfTopics } } } } = drizzle;
const Home = () => {
const [numberOfTopicsCallHash, setNumberOfTopicsCallHash] = useState('');
const getNumberOfTopicsResults = useSelector((state) => state.contracts.Forum.getNumberOfTopics);
const getNumberOfTopicsResults = useSelector((state) => state.contracts[FORUM_CONTRACT].getNumberOfTopics);
useEffect(() => {
setNumberOfTopicsCallHash(getNumberOfTopics.cacheCall());

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

@ -11,13 +11,14 @@ 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';
const { contracts: { Forum: { methods: { isUserNameTaken, signUp } } } } = drizzle;
const { contracts: { [FORUM_CONTRACT]: { methods: { isUserNameTaken, signUp } } } } = drizzle;
const SignUpStep = (props) => {
const { pushNextStep, account } = props;
const user = useSelector((state) => state.user);
const isUserNameTakenResults = useSelector((state) => state.contracts.Forum.isUserNameTaken);
const isUserNameTakenResults = useSelector((state) => state.contracts[FORUM_CONTRACT].isUserNameTaken);
const transactionStack = useSelector((state) => state.transactionStack);
const transactions = useSelector((state) => state.transactions);
const [usernameInput, setUsernameInput] = useState('');

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

@ -13,8 +13,10 @@ import { TRANSACTION_ERROR, TRANSACTION_SUCCESS } from '../../../constants/Trans
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';
const { contracts: { Forum: { methods: { createTopic } } } } = drizzle;
const { contracts: { [FORUM_CONTRACT]: { methods: { createTopic } } } } = drizzle;
const { orbit: { stores } } = breeze;
const TopicCreate = (props) => {
@ -57,7 +59,7 @@ const TopicCreate = (props) => {
const {
receipt: {
events: {
TopicCreated: {
[TOPIC_CREATED_EVENT]: {
returnValues: {
topicID: topicId,
postID: postId,

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

@ -14,8 +14,9 @@ import determineKVAddress from '../../../utils/orbitUtils';
import { USER_PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys';
import { TOPIC_SUBJECT } from '../../../constants/TopicsDatabaseKeys';
import PostCreate from '../../../components/PostCreate';
import { FORUM_CONTRACT } from '../../../constants/ContractNames';
const { contracts: { Forum: { methods: { getTopic: { cacheCall: getTopicChainData } } } } } = drizzle;
const { contracts: { [FORUM_CONTRACT]: { methods: { getTopic: { cacheCall: getTopicChainData } } } } } = drizzle;
const { orbit } = breeze;
const TopicView = (props) => {
@ -26,7 +27,7 @@ const TopicView = (props) => {
const drizzleInitialized = useSelector((state) => state.drizzleStatus.initialized);
const drizzleInitializationFailed = useSelector((state) => state.drizzleStatus.failed);
const userAddress = useSelector((state) => state.user.address);
const getTopicResults = useSelector((state) => state.contracts.Forum.getTopic);
const getTopicResults = useSelector((state) => state.contracts[FORUM_CONTRACT].getTopic);
const topics = useSelector((state) => state.orbitData.topics);
const users = useSelector((state) => state.orbitData.users);
const [getTopicCallHash, setGetTopicCallHash] = useState([]);

Loading…
Cancel
Save