|
@ -1,8 +1,9 @@ |
|
|
import { all, call, put, take, takeLatest } from 'redux-saga/effects'; |
|
|
import { all, call, put, select, take, takeEvery, takeLatest } from 'redux-saga/effects'; |
|
|
|
|
|
import isEqual from 'lodash.isequal'; |
|
|
import { contract, getCurrentAccount } from './drizzleUtilsSaga'; |
|
|
import { contract, getCurrentAccount } from './drizzleUtilsSaga'; |
|
|
import { loadDatabases } from '../../utils/orbitUtils'; |
|
|
import { loadDatabases } from '../../utils/orbitUtils'; |
|
|
import { DRIZZLE_UTILS_SAGA_INITIALIZED } from '../actions/drizzleUtilsActions'; |
|
|
import { DRIZZLE_UTILS_SAGA_INITIALIZED } from '../actions/drizzleUtilsActions'; |
|
|
import { DATABASES_NOT_READY, IPFS_INITIALIZED } from '../actions/orbitActions'; |
|
|
import { DATABASES_NOT_READY, IPFS_INITIALIZED, UPDATE_PEERS } from '../actions/orbitActions'; |
|
|
|
|
|
|
|
|
let latestAccount; |
|
|
let latestAccount; |
|
|
|
|
|
|
|
@ -19,8 +20,6 @@ function* getOrbitDBInfo() { |
|
|
address: account |
|
|
address: account |
|
|
}); |
|
|
}); |
|
|
if (callResult) { |
|
|
if (callResult) { |
|
|
// console.log("Deleting local storage..");
|
|
|
|
|
|
// localStorage.clear();
|
|
|
|
|
|
const txObj2 = yield call(contract.methods.getOrbitIdentityInfo, |
|
|
const txObj2 = yield call(contract.methods.getOrbitIdentityInfo, |
|
|
...[account]); |
|
|
...[account]); |
|
|
const orbitIdentityInfo = yield call(txObj2.call, { |
|
|
const orbitIdentityInfo = yield call(txObj2.call, { |
|
@ -51,12 +50,29 @@ function* getOrbitDBInfo() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function* updatePeersState() { |
|
|
|
|
|
const orbit = yield select(state => state.orbit); |
|
|
|
|
|
if(orbit.ready){ |
|
|
|
|
|
const topicsDBAddress = orbit.topicsDB.address.toString(); |
|
|
|
|
|
const postsDBAddress = orbit.postsDB.address.toString(); |
|
|
|
|
|
const topicsDBPeers = yield call(orbit.ipfs.pubsub.peers, topicsDBAddress); |
|
|
|
|
|
const postsDBPeers = yield call(orbit.ipfs.pubsub.peers, postsDBAddress); |
|
|
|
|
|
if(!isEqual(topicsDBPeers.sort(), orbit.topicsDBPeers.sort()) || |
|
|
|
|
|
!isEqual(postsDBPeers.sort(), orbit.postsDBPeers.sort())){ |
|
|
|
|
|
yield put({ |
|
|
|
|
|
type: UPDATE_PEERS, topicsDBPeers, postsDBPeers |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function* orbitSaga() { |
|
|
function* orbitSaga() { |
|
|
yield all([ |
|
|
yield all([ |
|
|
take(DRIZZLE_UTILS_SAGA_INITIALIZED), |
|
|
take(DRIZZLE_UTILS_SAGA_INITIALIZED), |
|
|
take(IPFS_INITIALIZED) |
|
|
take(IPFS_INITIALIZED) |
|
|
]); |
|
|
]); |
|
|
yield takeLatest('ACCOUNT_CHANGED', getOrbitDBInfo); |
|
|
yield takeLatest('ACCOUNT_CHANGED', getOrbitDBInfo); |
|
|
|
|
|
yield takeEvery('ACCOUNTS_FETCHED', updatePeersState); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export default orbitSaga; |
|
|
export default orbitSaga; |
|
|