mirror of https://gitlab.com/ecentrics/concordia
Ezerous
7 years ago
12 changed files with 158 additions and 35 deletions
@ -0,0 +1,16 @@ |
|||||
|
const initialState = { |
||||
|
grabbed: false |
||||
|
}; |
||||
|
|
||||
|
const contractReducer = (state = initialState, action) => { |
||||
|
switch (action.type) { |
||||
|
case 'CONTRACT_GRABBED': |
||||
|
return { |
||||
|
grabbed: true, |
||||
|
}; |
||||
|
default: |
||||
|
return state |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
export default contractReducer |
@ -0,0 +1,19 @@ |
|||||
|
import { put, takeLatest } from 'redux-saga/effects' |
||||
|
|
||||
|
let contractGrabbed=false; |
||||
|
let grabbedContract; |
||||
|
|
||||
|
function* grabContract({contract}) { |
||||
|
if(!contractGrabbed) |
||||
|
{ |
||||
|
contractGrabbed=true; |
||||
|
grabbedContract = contract; |
||||
|
yield put({type: 'CONTRACT_GRABBED', ...[]}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function* contractSaga() { |
||||
|
yield takeLatest('LISTEN_FOR_EVENT', grabContract); |
||||
|
} |
||||
|
|
||||
|
export { contractSaga, grabbedContract }; |
@ -1,9 +1,11 @@ |
|||||
import { all, fork } from 'redux-saga/effects' |
import { all, fork } from 'redux-saga/effects' |
||||
import { drizzleSagas } from 'drizzle' |
import { drizzleSagas } from 'drizzle' |
||||
|
import { contractSaga } from "./contractSaga"; |
||||
import userSaga from "./userSaga"; |
import userSaga from "./userSaga"; |
||||
|
import orbitSaga from "./util/orbitSaga"; |
||||
|
|
||||
export default function* root() { |
export default function* root() { |
||||
let sagas = [...drizzleSagas,userSaga]; |
let sagas = [...drizzleSagas,userSaga,orbitSaga,contractSaga]; |
||||
yield all( |
yield all( |
||||
sagas.map(saga => fork(saga)) |
sagas.map(saga => fork(saga)) |
||||
) |
) |
||||
|
@ -0,0 +1,42 @@ |
|||||
|
import { loadDatabases } from './../util/orbit' |
||||
|
import { call, put, select, takeLatest } from 'redux-saga/effects' |
||||
|
import {grabbedContract as contract} from "../contractSaga"; |
||||
|
|
||||
|
const accounts = (state) => state.accounts; |
||||
|
|
||||
|
let latestAccount; |
||||
|
|
||||
|
function* getOrbitDBInfo() { |
||||
|
yield put({type: 'ORRBIT_GETTING_INFO', ...[]}); |
||||
|
const account = (yield select(accounts))[0]; |
||||
|
if(account!==latestAccount) |
||||
|
{ |
||||
|
console.log("Deleting local storage.."); |
||||
|
localStorage.clear(); |
||||
|
const txObj1 = yield call(contract.methods["hasUserSignedUp"], ...[account]); |
||||
|
try { |
||||
|
const callResult = yield call(txObj1.call, {address:account}); |
||||
|
if(callResult) { |
||||
|
const txObj2 = yield call(contract.methods["getOrbitDBInfo"], ...[account]); |
||||
|
const info = yield call(txObj2.call, {address: account}); |
||||
|
//TODO: update localStorage OrbitDB stuff
|
||||
|
yield call(loadDatabases, info[0], info[1], info[2],info[3], info[4]); |
||||
|
} |
||||
|
else |
||||
|
yield put({type: 'DATABASES_NOT_READY', ...[]}); |
||||
|
|
||||
|
latestAccount=account; |
||||
|
} |
||||
|
catch (error) { |
||||
|
console.error(error); |
||||
|
yield put({type: 'ORBIT_SAGA_ERROR', ...[]}); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function* orbitSaga() { |
||||
|
yield takeLatest("ACCOUNT_CHANGED", getOrbitDBInfo); |
||||
|
} |
||||
|
|
||||
|
export default orbitSaga; |
Loading…
Reference in new issue