|
@ -1,4 +1,4 @@ |
|
|
import { call, put, take, takeEvery } from 'redux-saga/effects' |
|
|
import {call, put, select, take, takeEvery} from 'redux-saga/effects' |
|
|
|
|
|
|
|
|
import { contract, getCurrentAccount } from './drizzleUtilsSaga'; |
|
|
import { contract, getCurrentAccount } from './drizzleUtilsSaga'; |
|
|
|
|
|
|
|
@ -12,21 +12,26 @@ function* updateUserData() { |
|
|
} |
|
|
} |
|
|
const txObj1 = yield call(contract.methods["hasUserSignedUp"], ...[account]); |
|
|
const txObj1 = yield call(contract.methods["hasUserSignedUp"], ...[account]); |
|
|
try { |
|
|
try { |
|
|
|
|
|
const userState = yield call(getUserState); |
|
|
const callResult = yield call(txObj1.call, {address:account}); |
|
|
const callResult = yield call(txObj1.call, {address:account}); |
|
|
if(callResult) { |
|
|
if(callResult) { |
|
|
const txObj2 = yield call(contract.methods["getUsername"], ...[account]); |
|
|
const txObj2 = yield call(contract.methods["getUsername"], ...[account]); |
|
|
const username = yield call(txObj2.call, {address:account}); |
|
|
const username = yield call(txObj2.call, {address:account}); |
|
|
const dispatchArgs = { |
|
|
if(account!==userState.address || username!==userState.username){ |
|
|
address: account, |
|
|
const dispatchArgs = { |
|
|
username: username |
|
|
address: account, |
|
|
}; |
|
|
username: username |
|
|
yield put({type: 'USER_HAS_SIGNED_UP', ...dispatchArgs}); |
|
|
}; |
|
|
|
|
|
yield put({type: 'USER_DATA_UPDATED_(AUTHENTICATED)', ...dispatchArgs}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
else{ |
|
|
else{ |
|
|
const dispatchArgs = { |
|
|
if(account!==userState.address){ |
|
|
address: account |
|
|
const dispatchArgs = { |
|
|
}; |
|
|
address: account |
|
|
yield put({type: 'USER_IS_GUEST', ...dispatchArgs}); |
|
|
}; |
|
|
|
|
|
yield put({type: 'USER_DATA_UPDATED_(GUEST)', ...dispatchArgs}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
catch (error) { |
|
|
catch (error) { |
|
@ -35,6 +40,9 @@ function* updateUserData() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function* getUserState(){ |
|
|
|
|
|
return yield select((state) => state.user); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function* userSaga() { |
|
|
function* userSaga() { |
|
|
yield take("DRIZZLE_UTILS_SAGA_INITIALIZED"); |
|
|
yield take("DRIZZLE_UTILS_SAGA_INITIALIZED"); |
|
|