adds reconnect timeout and stores non-signed in prefs in different key

This commit is contained in:
jessop 2020-07-20 20:03:14 -04:00
parent 7847224c89
commit 08c375d024
3 changed files with 41 additions and 12 deletions

22
dist/bundle.es.js vendored
View file

@ -1996,7 +1996,6 @@ function doPreferenceGet(key, success, fail) {
//
const SHARED_PREFERENCE_KEY = 'shared';
const SHARED_PREFERENCE_VERSION = '0.1';
let oldShared = {};
@ -2011,6 +2010,7 @@ const buildSharedStateMiddleware = (actions, sharedStateFilters, sharedStateCb)
const actionResult = next(action);
// Call `getState` after calling `next` to ensure the state has updated in response to the action
const nextState = getState();
const preferenceKey = nextState.user && nextState.user.user && nextState.user.user.has_verified_email ? 'shared' : 'anon';
const shared = {};
Object.keys(sharedStateFilters).forEach(key => {
@ -2027,7 +2027,7 @@ const buildSharedStateMiddleware = (actions, sharedStateFilters, sharedStateCb)
if (!isEqual(oldShared, shared)) {
// only update if the preference changed from last call in the same session
oldShared = shared;
doPreferenceSet(SHARED_PREFERENCE_KEY, shared, SHARED_PREFERENCE_VERSION);
doPreferenceSet(preferenceKey, shared, SHARED_PREFERENCE_VERSION);
}
if (sharedStateCb) {
@ -3235,11 +3235,23 @@ function doWalletReconnect() {
dispatch({
type: WALLET_RESTART
});
let failed = false;
// this basically returns null when it's done. :(
// might be good to dispatch ACTIONS.WALLET_RESTARTED
lbryProxy.wallet_reconnect().then(() => dispatch({
type: WALLET_RESTART_COMPLETED
}));
const walletTimeout = setTimeout(() => {
failed = true;
dispatch({
type: WALLET_RESTART_COMPLETED
});
dispatch(doToast({
message: __('Your servers were not available. Check your url and port, or switch back to defaults.'),
isError: true
}));
}, 15000);
lbryProxy.wallet_reconnect().then(() => {
clearTimeout(walletTimeout);
if (!failed) dispatch({ type: WALLET_RESTART_COMPLETED });
});
};
}
function doWalletDecrypt() {

View file

@ -424,13 +424,27 @@ export function doWalletReconnect() {
dispatch({
type: ACTIONS.WALLET_RESTART,
});
let failed = false;
// this basically returns null when it's done. :(
// might be good to dispatch ACTIONS.WALLET_RESTARTED
Lbry.wallet_reconnect().then(() =>
const walletTimeout = setTimeout(() => {
failed = true;
dispatch({
type: ACTIONS.WALLET_RESTART_COMPLETED,
})
);
});
dispatch(
doToast({
message: __(
'Your servers were not available. Check your url and port, or switch back to defaults.'
),
isError: true,
})
);
}, 15000);
Lbry.wallet_reconnect().then(() => {
clearTimeout(walletTimeout);
if (!failed) dispatch({ type: ACTIONS.WALLET_RESTART_COMPLETED });
});
};
}
export function doWalletDecrypt() {

View file

@ -2,7 +2,6 @@
import isEqual from 'util/deep-equal';
import { doPreferenceSet } from 'redux/actions/sync';
const SHARED_PREFERENCE_KEY = 'shared';
const SHARED_PREFERENCE_VERSION = '0.1';
let oldShared = {};
@ -10,7 +9,7 @@ export const buildSharedStateMiddleware = (
actions: Array<string>,
sharedStateFilters: {},
sharedStateCb?: any => void
) => ({ getState, dispatch }: { getState: () => {}, dispatch: any => void }) => (
) => ({ getState, dispatch }: { getState: () => { user: any }, dispatch: any => void }) => (
next: ({}) => void
) => (action: { type: string, data: any }) => {
const currentState = getState();
@ -22,7 +21,11 @@ export const buildSharedStateMiddleware = (
const actionResult = next(action);
// Call `getState` after calling `next` to ensure the state has updated in response to the action
const nextState = getState();
const nextState: { user: any } = getState();
const preferenceKey =
nextState.user && nextState.user.user && nextState.user.user.has_verified_email
? 'shared'
: 'anon';
const shared = {};
Object.keys(sharedStateFilters).forEach(key => {
@ -39,7 +42,7 @@ export const buildSharedStateMiddleware = (
if (!isEqual(oldShared, shared)) {
// only update if the preference changed from last call in the same session
oldShared = shared;
doPreferenceSet(SHARED_PREFERENCE_KEY, shared, SHARED_PREFERENCE_VERSION);
doPreferenceSet(preferenceKey, shared, SHARED_PREFERENCE_VERSION);
}
if (sharedStateCb) {