Skip to content

[Fix] Issue#63 - Refreshing the page logs me out #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/ducks/signIn.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Portis from '@portis/web3';
import Web3 from 'web3';
import { REHYDRATE } from 'redux-persist';
import {
appName,
INFURA_PROVIDER_WSS,
Expand Down Expand Up @@ -43,6 +44,8 @@ export default function reducer( state = initialState, action ) {
const { type, payload, error } = action;

switch (type) {
case REHYDRATE:
return { ...state, isAuthenticated: payload && payload.isAuthenticated && window.ethereum.isConnected() } // TODO: Set appropriate checks to make sure Wallet is connected with the right address
case FETCH_SIGN_IN_REQUEST:
return Object.assign({}, state, {
isFetching: true,
Expand All @@ -51,7 +54,7 @@ export default function reducer( state = initialState, action ) {
error: null
});
case SET_DEFAULT_WEB3:
return {
return {...state,
web3: payload.web3,
error: null
};
Expand Down Expand Up @@ -215,6 +218,7 @@ export const subscribeMetamaskEventChannel = web3 => {

window.ethereum.on('accountsChanged', handleNewAccounts);
window.ethereum.on('chainChanged', handleChainChange);
window.ethereum.on('disconnect', handleNewAccounts);

return () => {};
});
Expand All @@ -230,9 +234,20 @@ const openPortisPopUp = async () => {

function* setDefaultWeb3Saga() {
try {
const provider = yield select(selectProvider);
const address = yield select(selectSignInAddress);

const web3Instance = new Web3(INFURA_PROVIDER_WSS)
yield put(setDefaultWeb3({
web3: new Web3(INFURA_PROVIDER_WSS)
web3: web3Instance
}));

const ethAccounts = yield call(window.ethereum.request, {method: 'eth_accounts'})
if(ethAccounts[0] === address) {
yield put(fetchSignInSuccess({provider, web3: web3Instance, address}));
} else {
yield put(fetchSignInFailure((new Error('Address mismatch'))));
}
} catch (error) {
// Connection Failure
yield put(fetchSignInFailure(error));
Expand Down
10 changes: 9 additions & 1 deletion src/redux/rootReducer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { combineReducers } from "redux";
import { persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import fetchProfileOrganizations, { moduleName as profileModule } from '../ducks/fetchProfile';
import fetchSearchOrganizations, { moduleName as searchModule } from '../ducks/fetchSearchResults';
import fetchOrganizationInfo, { moduleName as orgInfoModule } from '../ducks/fetchOrganizationInfo';
Expand All @@ -10,12 +12,18 @@ import joinOrganisations, {moduleName as joinOrganisationsModule} from '../ducks
import orgActiveStatus, {moduleName as orgActiveStatusModule} from '../ducks/orgActiveStatus';
import directories, { moduleName as directoriesModule } from '../ducks/directories';

const signInPersistConfig = {
storage,
key: 'signIn',
blacklist: ['web3']
}

//Add all reducers here
export default combineReducers({
[profileModule]: fetchProfileOrganizations,
[searchModule]: fetchSearchOrganizations,
[orgInfoModule]: fetchOrganizationInfo,
[signInModule]: fetchSignIn,
[signInModule]: persistReducer(signInPersistConfig, fetchSignIn),
[wizardModule]: extendWizard,
[depositModule]: fetchLifDeposit,
[backendStatusModule]: backendStatus,
Expand Down