adds reconnect timeout and stores non-signed in prefs in different key
This commit is contained in:
parent
7847224c89
commit
08c375d024
3 changed files with 41 additions and 12 deletions
22
dist/bundle.es.js
vendored
22
dist/bundle.es.js
vendored
|
@ -1996,7 +1996,6 @@ function doPreferenceGet(key, success, fail) {
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
const SHARED_PREFERENCE_KEY = 'shared';
|
|
||||||
const SHARED_PREFERENCE_VERSION = '0.1';
|
const SHARED_PREFERENCE_VERSION = '0.1';
|
||||||
let oldShared = {};
|
let oldShared = {};
|
||||||
|
|
||||||
|
@ -2011,6 +2010,7 @@ const buildSharedStateMiddleware = (actions, sharedStateFilters, sharedStateCb)
|
||||||
const actionResult = next(action);
|
const actionResult = next(action);
|
||||||
// Call `getState` after calling `next` to ensure the state has updated in response to the action
|
// Call `getState` after calling `next` to ensure the state has updated in response to the action
|
||||||
const nextState = getState();
|
const nextState = getState();
|
||||||
|
const preferenceKey = nextState.user && nextState.user.user && nextState.user.user.has_verified_email ? 'shared' : 'anon';
|
||||||
const shared = {};
|
const shared = {};
|
||||||
|
|
||||||
Object.keys(sharedStateFilters).forEach(key => {
|
Object.keys(sharedStateFilters).forEach(key => {
|
||||||
|
@ -2027,7 +2027,7 @@ const buildSharedStateMiddleware = (actions, sharedStateFilters, sharedStateCb)
|
||||||
if (!isEqual(oldShared, shared)) {
|
if (!isEqual(oldShared, shared)) {
|
||||||
// only update if the preference changed from last call in the same session
|
// only update if the preference changed from last call in the same session
|
||||||
oldShared = shared;
|
oldShared = shared;
|
||||||
doPreferenceSet(SHARED_PREFERENCE_KEY, shared, SHARED_PREFERENCE_VERSION);
|
doPreferenceSet(preferenceKey, shared, SHARED_PREFERENCE_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sharedStateCb) {
|
if (sharedStateCb) {
|
||||||
|
@ -3235,11 +3235,23 @@ function doWalletReconnect() {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: WALLET_RESTART
|
type: WALLET_RESTART
|
||||||
});
|
});
|
||||||
|
let failed = false;
|
||||||
// this basically returns null when it's done. :(
|
// this basically returns null when it's done. :(
|
||||||
// might be good to dispatch ACTIONS.WALLET_RESTARTED
|
// might be good to dispatch ACTIONS.WALLET_RESTARTED
|
||||||
lbryProxy.wallet_reconnect().then(() => dispatch({
|
const walletTimeout = setTimeout(() => {
|
||||||
type: WALLET_RESTART_COMPLETED
|
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() {
|
function doWalletDecrypt() {
|
||||||
|
|
|
@ -424,13 +424,27 @@ export function doWalletReconnect() {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.WALLET_RESTART,
|
type: ACTIONS.WALLET_RESTART,
|
||||||
});
|
});
|
||||||
|
let failed = false;
|
||||||
// this basically returns null when it's done. :(
|
// this basically returns null when it's done. :(
|
||||||
// might be good to dispatch ACTIONS.WALLET_RESTARTED
|
// might be good to dispatch ACTIONS.WALLET_RESTARTED
|
||||||
Lbry.wallet_reconnect().then(() =>
|
const walletTimeout = setTimeout(() => {
|
||||||
|
failed = true;
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.WALLET_RESTART_COMPLETED,
|
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() {
|
export function doWalletDecrypt() {
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
import isEqual from 'util/deep-equal';
|
import isEqual from 'util/deep-equal';
|
||||||
import { doPreferenceSet } from 'redux/actions/sync';
|
import { doPreferenceSet } from 'redux/actions/sync';
|
||||||
|
|
||||||
const SHARED_PREFERENCE_KEY = 'shared';
|
|
||||||
const SHARED_PREFERENCE_VERSION = '0.1';
|
const SHARED_PREFERENCE_VERSION = '0.1';
|
||||||
let oldShared = {};
|
let oldShared = {};
|
||||||
|
|
||||||
|
@ -10,7 +9,7 @@ export const buildSharedStateMiddleware = (
|
||||||
actions: Array<string>,
|
actions: Array<string>,
|
||||||
sharedStateFilters: {},
|
sharedStateFilters: {},
|
||||||
sharedStateCb?: any => void
|
sharedStateCb?: any => void
|
||||||
) => ({ getState, dispatch }: { getState: () => {}, dispatch: any => void }) => (
|
) => ({ getState, dispatch }: { getState: () => { user: any }, dispatch: any => void }) => (
|
||||||
next: ({}) => void
|
next: ({}) => void
|
||||||
) => (action: { type: string, data: any }) => {
|
) => (action: { type: string, data: any }) => {
|
||||||
const currentState = getState();
|
const currentState = getState();
|
||||||
|
@ -22,7 +21,11 @@ export const buildSharedStateMiddleware = (
|
||||||
|
|
||||||
const actionResult = next(action);
|
const actionResult = next(action);
|
||||||
// Call `getState` after calling `next` to ensure the state has updated in response to the 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 = {};
|
const shared = {};
|
||||||
|
|
||||||
Object.keys(sharedStateFilters).forEach(key => {
|
Object.keys(sharedStateFilters).forEach(key => {
|
||||||
|
@ -39,7 +42,7 @@ export const buildSharedStateMiddleware = (
|
||||||
if (!isEqual(oldShared, shared)) {
|
if (!isEqual(oldShared, shared)) {
|
||||||
// only update if the preference changed from last call in the same session
|
// only update if the preference changed from last call in the same session
|
||||||
oldShared = shared;
|
oldShared = shared;
|
||||||
doPreferenceSet(SHARED_PREFERENCE_KEY, shared, SHARED_PREFERENCE_VERSION);
|
doPreferenceSet(preferenceKey, shared, SHARED_PREFERENCE_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sharedStateCb) {
|
if (sharedStateCb) {
|
||||||
|
|
Loading…
Reference in a new issue