From 2d66195d1f660c998524c65b9b1a0bd30147c03a Mon Sep 17 00:00:00 2001 From: Apostolof Date: Wed, 18 Nov 2020 21:40:16 +0200 Subject: [PATCH 1/5] Add events saga --- .../src/redux/actions/contractEventActions.js | 4 ++++ .../concordia-app/src/redux/sagas/eventSaga.js | 12 ++++++++++++ packages/concordia-app/src/redux/sagas/rootSaga.js | 2 ++ packages/concordia-app/src/redux/sagas/userSaga.js | 14 +++++++++++++- .../concordia-app/src/views/Register/index.jsx | 3 ++- 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 packages/concordia-app/src/redux/actions/contractEventActions.js create mode 100644 packages/concordia-app/src/redux/sagas/eventSaga.js diff --git a/packages/concordia-app/src/redux/actions/contractEventActions.js b/packages/concordia-app/src/redux/actions/contractEventActions.js new file mode 100644 index 0000000..9c54288 --- /dev/null +++ b/packages/concordia-app/src/redux/actions/contractEventActions.js @@ -0,0 +1,4 @@ +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'; diff --git a/packages/concordia-app/src/redux/sagas/eventSaga.js b/packages/concordia-app/src/redux/sagas/eventSaga.js new file mode 100644 index 0000000..5b43d1c --- /dev/null +++ b/packages/concordia-app/src/redux/sagas/eventSaga.js @@ -0,0 +1,12 @@ +import { put, takeEvery } from 'redux-saga/effects'; +import { CONTRACT_EVENT_FIRED } from '@ezerous/drizzle/src/contracts/constants'; + +function* eventBreakDown({ event }) { + yield put({ type: event.event, event: { ...event } }); +} + +function* eventSaga() { + yield takeEvery(CONTRACT_EVENT_FIRED, eventBreakDown); +} + +export default eventSaga; diff --git a/packages/concordia-app/src/redux/sagas/rootSaga.js b/packages/concordia-app/src/redux/sagas/rootSaga.js index 7f5bfb4..dd24291 100644 --- a/packages/concordia-app/src/redux/sagas/rootSaga.js +++ b/packages/concordia-app/src/redux/sagas/rootSaga.js @@ -4,11 +4,13 @@ import { breezeSagas } from '@ezerous/breeze'; import orbitSaga from './orbitSaga'; import userSaga from './userSaga'; import peerDbReplicationSaga from './peerDbReplicationSaga'; +import eventSaga from './eventSaga'; export default function* root() { const sagas = [ ...drizzleSagas, ...breezeSagas, + eventSaga, orbitSaga, userSaga, peerDbReplicationSaga, diff --git a/packages/concordia-app/src/redux/sagas/userSaga.js b/packages/concordia-app/src/redux/sagas/userSaga.js index 6d35de4..92cc840 100644 --- a/packages/concordia-app/src/redux/sagas/userSaga.js +++ b/packages/concordia-app/src/redux/sagas/userSaga.js @@ -1,10 +1,11 @@ /* eslint-disable no-console */ import { - all, call, put, take, + 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'; function* fetchUserData({ drizzle, account }) { const contract = drizzle.contracts.Forum; @@ -31,6 +32,15 @@ function* fetchUserData({ drizzle, account }) { } } +function* userHasSignedUp({ event }) { + yield put({ + type: USER_DATA_UPDATED, + ...{ + address: event.returnValues.userAddress, username: event.returnValues.username, + }, + }); +} + function* userSaga() { const res = yield all([ take(drizzleActions.drizzle.DRIZZLE_INITIALIZED), @@ -38,6 +48,8 @@ function* userSaga() { ]); yield fetchUserData({ drizzle: res[0].drizzle, account: res[1].accounts[0] }); + + yield takeLatest(FORUM_EVENT_USER_SIGNED_UP, userHasSignedUp); } export default userSaga; diff --git a/packages/concordia-app/src/views/Register/index.jsx b/packages/concordia-app/src/views/Register/index.jsx index e7da27f..d2dac4a 100644 --- a/packages/concordia-app/src/views/Register/index.jsx +++ b/packages/concordia-app/src/views/Register/index.jsx @@ -13,6 +13,7 @@ import { REGISTER_STEP_PROFILE_INFORMATION, REGISTER_STEP_SIGNUP } from '../../c const Register = () => { const [currentStep, setCurrentStep] = useState('signup'); const user = useSelector((state) => state.user); + const [signingUp] = useState(!user.hasSignedUp); const history = useHistory(); const { t } = useTranslation(); @@ -92,7 +93,7 @@ const Register = () => {

- {user.hasSignedUp + {user.hasSignedUp && !signingUp ? ( <> From 3bcff9d7cdad7e9b7350feccd1304f3fcf0b0a23 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Thu, 19 Nov 2020 20:37:55 +0200 Subject: [PATCH 2/5] Change contract event names to SNAKE_CASE --- packages/concordia-contracts/contracts/Forum.sol | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/concordia-contracts/contracts/Forum.sol b/packages/concordia-contracts/contracts/Forum.sol index 13ad2ea..8876828 100644 --- a/packages/concordia-contracts/contracts/Forum.sol +++ b/packages/concordia-contracts/contracts/Forum.sol @@ -15,8 +15,8 @@ contract Forum { mapping (address => User) users; mapping (string => address) userAddresses; - event UserSignedUp(string username, address userAddress); - event UsernameUpdated(string newName, string oldName,address userAddress); + event USER_SIGNED_UP(string username, address userAddress); + event USERNAME_UPDATED(string newName, string oldName, address userAddress); function signUp(string memory username) public returns (bool) { require (!hasUserSignedUp(msg.sender), "User has already signed up."); @@ -24,7 +24,7 @@ contract Forum { users[msg.sender] = User(username, new uint[](0), new uint[](0), block.timestamp, true); userAddresses[username] = msg.sender; - emit UserSignedUp(username, msg.sender); + emit USER_SIGNED_UP(username, msg.sender); return true; } @@ -35,7 +35,7 @@ contract Forum { delete userAddresses[users[msg.sender].username]; users[msg.sender].username = newUsername; userAddresses[newUsername] = msg.sender; - emit UsernameUpdated(newUsername, oldUsername, msg.sender); + emit USERNAME_UPDATED(newUsername, oldUsername, msg.sender); return true; } @@ -95,8 +95,8 @@ contract Forum { mapping (uint => Topic) topics; mapping (uint => Post) posts; - event TopicCreated(uint topicID, uint postID); - event PostCreated(uint postID, uint topicID); + event TOPIC_CREATED(uint topicID, uint postID); + event POST_CREATED(uint postID, uint topicID); function createTopic() public returns (uint, uint) { require(hasUserSignedUp(msg.sender)); // Only registered users can create topics @@ -111,7 +111,7 @@ contract Forum { topics[topicID].postIDs.push(postID); users[msg.sender].postIDs.push(postID); - emit TopicCreated(topicID, postID); + emit TOPIC_CREATED(topicID, postID); return (topicID, postID); } @@ -122,7 +122,7 @@ contract Forum { posts[postID] = Post(postID, msg.sender, block.timestamp, topicID); topics[topicID].postIDs.push(postID); users[msg.sender].postIDs.push(postID); - emit PostCreated(postID, topicID); + emit POST_CREATED(postID, topicID); return postID; } From c1c6341ddf59bf8eea8fcacfd3e031a79848fcc0 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Thu, 19 Nov 2020 20:38:56 +0200 Subject: [PATCH 3/5] Move all contract and event names to constants --- .../src/components/LoadingContainer.jsx | 5 ++-- .../components/PostList/PostListRow/index.jsx | 3 ++- .../src/components/PostList/index.jsx | 3 ++- .../TopicList/TopicListRow/index.jsx | 3 ++- .../src/components/TopicList/index.jsx | 3 ++- .../src/constants/ContractNames.js | 2 +- .../src/constants/ForumContractEvents.js | 13 ++++++++++ .../src/options/drizzleOptions.js | 4 +++- .../src/redux/actions/contractEventActions.js | 24 +++++++++++++++---- .../src/redux/sagas/eventSaga.js | 3 ++- .../concordia-app/src/redux/sagas/userSaga.js | 4 ++-- .../concordia-app/src/views/Home/index.jsx | 5 ++-- .../src/views/Register/SignUpStep/index.jsx | 5 ++-- .../src/views/Topic/TopicCreate/index.jsx | 6 +++-- .../src/views/Topic/TopicView/index.jsx | 5 ++-- 15 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 packages/concordia-app/src/constants/ForumContractEvents.js diff --git a/packages/concordia-app/src/components/LoadingContainer.jsx b/packages/concordia-app/src/components/LoadingContainer.jsx index 6add0ba..c44c468 100644 --- a/packages/concordia-app/src/components/LoadingContainer.jsx +++ b/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) diff --git a/packages/concordia-app/src/components/PostList/PostListRow/index.jsx b/packages/concordia-app/src/components/PostList/PostListRow/index.jsx index 0fff102..af1a69a 100644 --- a/packages/concordia-app/src/components/PostList/PostListRow/index.jsx +++ b/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); diff --git a/packages/concordia-app/src/components/PostList/index.jsx b/packages/concordia-app/src/components/PostList/index.jsx index 991fc2f..c5c8130 100644 --- a/packages/concordia-app/src/components/PostList/index.jsx +++ b/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; diff --git a/packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx b/packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx index 4e6196d..05974ee 100644 --- a/packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx +++ b/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); diff --git a/packages/concordia-app/src/components/TopicList/index.jsx b/packages/concordia-app/src/components/TopicList/index.jsx index 511ae2b..e171caf 100644 --- a/packages/concordia-app/src/components/TopicList/index.jsx +++ b/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; diff --git a/packages/concordia-app/src/constants/ContractNames.js b/packages/concordia-app/src/constants/ContractNames.js index bfb65b4..95fe6f7 100644 --- a/packages/concordia-app/src/constants/ContractNames.js +++ b/packages/concordia-app/src/constants/ContractNames.js @@ -1 +1 @@ -export const FORUM = 'Forum'; +export const FORUM_CONTRACT = 'Forum'; diff --git a/packages/concordia-app/src/constants/ForumContractEvents.js b/packages/concordia-app/src/constants/ForumContractEvents.js new file mode 100644 index 0000000..600a80a --- /dev/null +++ b/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; diff --git a/packages/concordia-app/src/options/drizzleOptions.js b/packages/concordia-app/src/options/drizzleOptions.js index aa563f7..80dd30c 100644 --- a/packages/concordia-app/src/options/drizzleOptions.js +++ b/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 diff --git a/packages/concordia-app/src/redux/actions/contractEventActions.js b/packages/concordia-app/src/redux/actions/contractEventActions.js index 9c54288..1dd5be1 100644 --- a/packages/concordia-app/src/redux/actions/contractEventActions.js +++ b/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; diff --git a/packages/concordia-app/src/redux/sagas/eventSaga.js b/packages/concordia-app/src/redux/sagas/eventSaga.js index 5b43d1c..b6017c6 100644 --- a/packages/concordia-app/src/redux/sagas/eventSaga.js +++ b/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() { diff --git a/packages/concordia-app/src/redux/sagas/userSaga.js b/packages/concordia-app/src/redux/sagas/userSaga.js index 92cc840..f436914 100644 --- a/packages/concordia-app/src/redux/sagas/userSaga.js +++ b/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 { diff --git a/packages/concordia-app/src/views/Home/index.jsx b/packages/concordia-app/src/views/Home/index.jsx index ce9decf..3272cfd 100644 --- a/packages/concordia-app/src/views/Home/index.jsx +++ b/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()); diff --git a/packages/concordia-app/src/views/Register/SignUpStep/index.jsx b/packages/concordia-app/src/views/Register/SignUpStep/index.jsx index 006ce04..948b3ae 100644 --- a/packages/concordia-app/src/views/Register/SignUpStep/index.jsx +++ b/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(''); diff --git a/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx b/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx index 224f11b..b6106e6 100644 --- a/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx +++ b/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, diff --git a/packages/concordia-app/src/views/Topic/TopicView/index.jsx b/packages/concordia-app/src/views/Topic/TopicView/index.jsx index 943b804..5f747c2 100644 --- a/packages/concordia-app/src/views/Topic/TopicView/index.jsx +++ b/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([]); From 26f600090997cf71957584d291ef90f7852ed987 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Thu, 19 Nov 2020 23:06:04 +0200 Subject: [PATCH 4/5] Change added contract accessors with constants --- packages/concordia-app/src/components/PostCreate/index.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/concordia-app/src/components/PostCreate/index.jsx b/packages/concordia-app/src/components/PostCreate/index.jsx index 0047247..e13f343 100644 --- a/packages/concordia-app/src/components/PostCreate/index.jsx +++ b/packages/concordia-app/src/components/PostCreate/index.jsx @@ -15,8 +15,10 @@ 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'; -const { contracts: { Forum: { methods: { createPost } } } } = drizzle; +const { contracts: { [FORUM_CONTRACT]: { methods: { createPost } } } } = drizzle; const { orbit } = breeze; const PostCreate = (props) => { @@ -86,7 +88,7 @@ const PostCreate = (props) => { setPosting(false); } else if (transactions[transactionStack[createPostCacheSendStackId]].status === TRANSACTION_SUCCESS) { const { - receipt: { events: { PostCreated: { returnValues: { postID: contractPostId } } } }, + receipt: { events: { [POST_CREATED_EVENT]: { returnValues: { postID: contractPostId } } } }, } = transactions[transactionStack[createPostCacheSendStackId]]; const { stores } = orbit; From 260ba08b29d74e537cce6ae229c72ab141325745 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Fri, 20 Nov 2020 21:04:50 +0200 Subject: [PATCH 5/5] Revert contract event names change --- .../src/constants/ForumContractEvents.js | 8 ++++---- packages/concordia-contracts/contracts/Forum.sol | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/concordia-app/src/constants/ForumContractEvents.js b/packages/concordia-app/src/constants/ForumContractEvents.js index 600a80a..f0f9a34 100644 --- a/packages/concordia-app/src/constants/ForumContractEvents.js +++ b/packages/concordia-app/src/constants/ForumContractEvents.js @@ -1,7 +1,7 @@ -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'; +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, diff --git a/packages/concordia-contracts/contracts/Forum.sol b/packages/concordia-contracts/contracts/Forum.sol index 8876828..5b15290 100644 --- a/packages/concordia-contracts/contracts/Forum.sol +++ b/packages/concordia-contracts/contracts/Forum.sol @@ -15,8 +15,8 @@ contract Forum { mapping (address => User) users; mapping (string => address) userAddresses; - event USER_SIGNED_UP(string username, address userAddress); - event USERNAME_UPDATED(string newName, string oldName, address userAddress); + event UserSignedUp(string username, address userAddress); + event UsernameUpdated(string newName, string oldName, address userAddress); function signUp(string memory username) public returns (bool) { require (!hasUserSignedUp(msg.sender), "User has already signed up."); @@ -24,7 +24,7 @@ contract Forum { users[msg.sender] = User(username, new uint[](0), new uint[](0), block.timestamp, true); userAddresses[username] = msg.sender; - emit USER_SIGNED_UP(username, msg.sender); + emit UserSignedUp(username, msg.sender); return true; } @@ -35,7 +35,7 @@ contract Forum { delete userAddresses[users[msg.sender].username]; users[msg.sender].username = newUsername; userAddresses[newUsername] = msg.sender; - emit USERNAME_UPDATED(newUsername, oldUsername, msg.sender); + emit UsernameUpdated(newUsername, oldUsername, msg.sender); return true; } @@ -95,8 +95,8 @@ contract Forum { mapping (uint => Topic) topics; mapping (uint => Post) posts; - event TOPIC_CREATED(uint topicID, uint postID); - event POST_CREATED(uint postID, uint topicID); + event TopicCreated(uint topicID, uint postID); + event PostCreated(uint postID, uint topicID); function createTopic() public returns (uint, uint) { require(hasUserSignedUp(msg.sender)); // Only registered users can create topics @@ -111,7 +111,7 @@ contract Forum { topics[topicID].postIDs.push(postID); users[msg.sender].postIDs.push(postID); - emit TOPIC_CREATED(topicID, postID); + emit TopicCreated(topicID, postID); return (topicID, postID); } @@ -122,7 +122,7 @@ contract Forum { posts[postID] = Post(postID, msg.sender, block.timestamp, topicID); topics[topicID].postIDs.push(postID); users[msg.sender].postIDs.push(postID); - emit POST_CREATED(postID, topicID); + emit PostCreated(postID, topicID); return postID; }