You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

37 lines
1.1 KiB

import getWeb3 from '@drizzle-utils/get-web3';
import getContractInstance from '@drizzle-utils/get-contract-instance';
import { call, put, takeLatest, select } from 'redux-saga/effects'
import Forum from '../../contracts/Forum';
const accounts = (state) => state.accounts;
let initFlag, web3, contract;
function* init() {
if(!initFlag) {
web3 = yield call(getWeb3);
contract = yield call(getContractInstance,{
web3,
artifact: Forum
});
initFlag=true;
yield put({type: 'DRIZZLE_UTILS_SAGA_INITIALIZED', ...[]});
}
else
console.warn("Attempted to reinitialize drizzleUtilsSaga!");
}
// If the method below proves to be problematic/ineffective (i.e. getting current account
// from state), consider getting it from @drizzle-utils/get-accounts instead
// with (yield call(getAccounts, {web3}))[0];
function* getCurrentAccount(){
return (yield select(accounts))[0];
}
function* drizzleUtilsSaga() {
yield takeLatest("DRIZZLE_INITIALIZED", init);
}
export { web3, contract, getCurrentAccount }
export default drizzleUtilsSaga;