Browse Source

Add transactionsSaga case for posting, Minor fix

develop
Apostolos Fanakis 6 years ago
parent
commit
c1f58cd20e
  1. 8
      app/src/components/NewPost.js
  2. 21
      app/src/redux/sagas/transactionsSaga.js

8
app/src/components/NewPost.js

@ -7,7 +7,7 @@ import TimeAgo from 'react-timeago';
import UserAvatar from 'react-user-avatar';
import ReactMarkdown from 'react-markdown';
/*import { createPost } from '../redux/actions/transactionsMonitorActions';*/
import { createPost } from '../redux/actions/transactionsActions';
class NewPost extends Component {
constructor(props, context) {
@ -25,7 +25,7 @@ class NewPost extends Component {
postSubjectInputEmptySubmit: false,
postContentInputEmptySubmit: false,
previewEnabled: false,
previewDate: ""
previewDate: ''
};
}
@ -38,14 +38,14 @@ class NewPost extends Component {
return;
}
/*this.props.store.dispatch(
this.props.dispatch(
createPost(this.props.topicID,
{
postSubject: this.state.postSubjectInput,
postMessage: this.state.postContentInput
}
)
);*/
);
this.props.onPostCreated();
}

21
app/src/redux/sagas/transactionsSaga.js

@ -7,20 +7,22 @@ let transactionsHistory = Object.create(null);
function* initTransaction(action) {
var dataKey = drizzle.contracts[action.transactionDescriptor.contract]
.methods[action.transactionDescriptor['method']]
.cacheSend(...[action.transactionDescriptor.params]);
.cacheSend(...(action.transactionDescriptor.params));
transactionsHistory[dataKey] = action;
transactionsHistory[dataKey].state = 'initialized';
}
function* handleEvent(action) {
var transactionStack = yield select((state) => state.transactionStack);
var dataKey = transactionStack.indexOf(action.event.transactionHash);
switch(action.event.event) {
case 'TopicCreated':
var transactionStack = yield select((state) => state.transactionStack);
var dataKey = transactionStack.indexOf(action.event.transactionHash);
if (dataKey !== -1 &&
transactionsHistory[dataKey] &&
transactionsHistory[dataKey].state === 'initialized') {
transactionsHistory[dataKey].state = 'success';
//Gets orbit
const orbit = yield select((state) => state.orbit);
//And saves the topic
@ -29,8 +31,19 @@ function* handleEvent(action) {
yield call([orbit.postsDB, 'put'], [action.event.returnValues.postID,
{subject: transactionsHistory[dataKey].userInputs.topicSubject,
content: transactionsHistory[dataKey].userInputs.topicMessage }]);
}
break;
case 'PostCreated':
if (dataKey !== -1 &&
transactionsHistory[dataKey] &&
transactionsHistory[dataKey].state === 'initialized') {
transactionsHistory[dataKey].state = 'success';
//Gets orbit
const orbit = yield select((state) => state.orbit);
//And saves the topic
yield call([orbit.postsDB, 'put'], [action.event.returnValues.postID,
{subject: transactionsHistory[dataKey].userInputs.postSubject,
content: transactionsHistory[dataKey].userInputs.postMessage }]);
}
break;
default:

Loading…
Cancel
Save