From 955c2d78eeeced4159143edd7ee38b60c096bed7 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Mon, 11 Mar 2019 19:42:25 +0200 Subject: [PATCH] OrbitDB put fix for sagas --- app/src/components/Topic.js | 3 +-- app/src/orbit.js | 7 +++++-- app/src/redux/sagas/transactionsSaga.js | 15 ++++++++------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/src/components/Topic.js b/app/src/components/Topic.js index 35cbebb..4f97352 100644 --- a/app/src/components/Topic.js +++ b/app/src/components/Topic.js @@ -97,8 +97,7 @@ class Topic extends Component { const mapStateToProps = state => { return { user: state.user, - orbitDB: state.orbit, - topicsDB: state.topicsDB + orbitDB: state.orbit } } diff --git a/app/src/orbit.js b/app/src/orbit.js index 78c75dc..6983430 100644 --- a/app/src/orbit.js +++ b/app/src/orbit.js @@ -39,7 +39,6 @@ async function createDatabases() { topicsDB: topicsDB.address.root, postsDB: postsDB.address.root }; - console.dir(returnValue); return returnValue; } @@ -71,4 +70,8 @@ async function loadDatabases(identityId, identityPublicKey, identityPrivateKey, }); } -export { initIPFS, createDatabases, loadDatabases }; \ No newline at end of file +async function orbitSagaPut(db, key, value) { + db.put(key, value); +} + +export { initIPFS, createDatabases, loadDatabases, orbitSagaPut }; diff --git a/app/src/redux/sagas/transactionsSaga.js b/app/src/redux/sagas/transactionsSaga.js index 2c28c88..ae02122 100644 --- a/app/src/redux/sagas/transactionsSaga.js +++ b/app/src/redux/sagas/transactionsSaga.js @@ -1,6 +1,7 @@ import {call, select, take, takeEvery} from 'redux-saga/effects' import { drizzle } from '../../index' +import { orbitSagaPut } from '../../orbit' let transactionsHistory = Object.create(null); @@ -26,11 +27,11 @@ function* handleEvent(action) { //Gets orbit const orbit = yield select((state) => state.orbit); //And saves the topic - yield call([orbit.topicsDB, 'put'], [action.event.returnValues.topicID, - { subject: transactionsHistory[dataKey].userInputs.topicSubject }]); - yield call([orbit.postsDB, 'put'], [action.event.returnValues.postID, - {subject: transactionsHistory[dataKey].userInputs.topicSubject, - content: transactionsHistory[dataKey].userInputs.topicMessage }]); + yield call(orbitSagaPut, orbit.topicsDB, action.event.returnValues.topicID, + { subject: transactionsHistory[dataKey].userInputs.topicSubject }); + yield call(orbitSagaPut, orbit.postsDB, action.event.returnValues.postID, + { subject: transactionsHistory[dataKey].userInputs.topicSubject, + content: transactionsHistory[dataKey].userInputs.topicMessage }); } break; case 'PostCreated': @@ -41,9 +42,9 @@ function* handleEvent(action) { //Gets orbit const orbit = yield select((state) => state.orbit); //And saves the topic - yield call([orbit.postsDB, 'put'], [action.event.returnValues.postID, + yield call(orbitSagaPut, orbit.postsDB, action.event.returnValues.postID, {subject: transactionsHistory[dataKey].userInputs.postSubject, - content: transactionsHistory[dataKey].userInputs.postMessage }]); + content: transactionsHistory[dataKey].userInputs.postMessage }); } break; default: