Reconnect to default server if custom server fails.
This commit is contained in:
parent
c7511fc803
commit
c5b018afc3
7 changed files with 111 additions and 62 deletions
|
@ -1,5 +1,9 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { selectIsWalletReconnecting } from 'redux/selectors/wallet';
|
import {
|
||||||
|
selectIsWalletReconnecting,
|
||||||
|
selectWalletRollbackToDefault,
|
||||||
|
selectWalletConnectingToDefault,
|
||||||
|
} from 'redux/selectors/wallet';
|
||||||
import * as DAEMON_SETTINGS from 'constants/daemon_settings';
|
import * as DAEMON_SETTINGS from 'constants/daemon_settings';
|
||||||
import {
|
import {
|
||||||
doSetDaemonSetting,
|
doSetDaemonSetting,
|
||||||
|
@ -15,6 +19,8 @@ const select = (state) => ({
|
||||||
customWalletServers: selectSavedWalletServers(state),
|
customWalletServers: selectSavedWalletServers(state),
|
||||||
hasWalletServerPrefs: selectHasWalletServerPrefs(state),
|
hasWalletServerPrefs: selectHasWalletServerPrefs(state),
|
||||||
walletReconnecting: selectIsWalletReconnecting(state),
|
walletReconnecting: selectIsWalletReconnecting(state),
|
||||||
|
walletRollbackToDefault: selectWalletRollbackToDefault(state),
|
||||||
|
walletReconnectingToDefault: selectWalletConnectingToDefault(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = (dispatch) => ({
|
const perform = (dispatch) => ({
|
||||||
|
|
|
@ -30,6 +30,8 @@ type Props = {
|
||||||
hasWalletServerPrefs: boolean,
|
hasWalletServerPrefs: boolean,
|
||||||
daemonStatus: DaemonStatus,
|
daemonStatus: DaemonStatus,
|
||||||
walletReconnecting: boolean,
|
walletReconnecting: boolean,
|
||||||
|
walletRollbackToDefault: boolean,
|
||||||
|
walletReconnectingToDefault: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
function SettingWalletServer(props: Props) {
|
function SettingWalletServer(props: Props) {
|
||||||
|
@ -42,9 +44,12 @@ function SettingWalletServer(props: Props) {
|
||||||
customWalletServers,
|
customWalletServers,
|
||||||
hasWalletServerPrefs,
|
hasWalletServerPrefs,
|
||||||
walletReconnecting,
|
walletReconnecting,
|
||||||
|
walletRollbackToDefault,
|
||||||
|
walletReconnectingToDefault,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const [advancedMode, setAdvancedMode] = useState(false);
|
const [usingCustomServer, setUsingCustomServer] = useState(false);
|
||||||
|
const [showCustomServers, setShowCustomServers] = useState(false);
|
||||||
|
|
||||||
const walletStatus = daemonStatus && daemonStatus.wallet;
|
const walletStatus = daemonStatus && daemonStatus.wallet;
|
||||||
const activeWalletServers: ServerStatus = (walletStatus && walletStatus.servers) || [];
|
const activeWalletServers: ServerStatus = (walletStatus && walletStatus.servers) || [];
|
||||||
|
@ -73,7 +78,7 @@ function SettingWalletServer(props: Props) {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (hasWalletServerPrefs) {
|
if (hasWalletServerPrefs) {
|
||||||
setAdvancedMode(true);
|
setUsingCustomServer(true);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
@ -84,8 +89,20 @@ function SettingWalletServer(props: Props) {
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (walletRollbackToDefault) {
|
||||||
|
doClear();
|
||||||
|
}
|
||||||
|
}, [walletRollbackToDefault]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (usingCustomServer) {
|
||||||
|
setShowCustomServers(true);
|
||||||
|
}
|
||||||
|
}, [usingCustomServer]);
|
||||||
|
|
||||||
function doClear() {
|
function doClear() {
|
||||||
setAdvancedMode(false);
|
setUsingCustomServer(false);
|
||||||
clearWalletServers();
|
clearWalletServers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +129,7 @@ function SettingWalletServer(props: Props) {
|
||||||
<FormField
|
<FormField
|
||||||
type="radio"
|
type="radio"
|
||||||
name="default_wallet_servers"
|
name="default_wallet_servers"
|
||||||
checked={!advancedMode}
|
checked={!usingCustomServer}
|
||||||
label={__('Use official LBRY wallet servers')}
|
label={__('Use official LBRY wallet servers')}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
if (e.target.checked) {
|
if (e.target.checked) {
|
||||||
|
@ -123,9 +140,9 @@ function SettingWalletServer(props: Props) {
|
||||||
<FormField
|
<FormField
|
||||||
type="radio"
|
type="radio"
|
||||||
name="custom_wallet_servers"
|
name="custom_wallet_servers"
|
||||||
checked={advancedMode}
|
checked={usingCustomServer}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setAdvancedMode(e.target.checked);
|
setUsingCustomServer(e.target.checked);
|
||||||
if (e.target.checked && customWalletServers.length) {
|
if (e.target.checked && customWalletServers.length) {
|
||||||
setCustomWalletServers(stringifyServerParam(customWalletServers));
|
setCustomWalletServers(stringifyServerParam(customWalletServers));
|
||||||
}
|
}
|
||||||
|
@ -133,7 +150,7 @@ function SettingWalletServer(props: Props) {
|
||||||
label={__('Use custom wallet servers')}
|
label={__('Use custom wallet servers')}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{advancedMode && (
|
{showCustomServers && (
|
||||||
<div>
|
<div>
|
||||||
{serverConfig &&
|
{serverConfig &&
|
||||||
serverConfig.map((entry, index) => {
|
serverConfig.map((entry, index) => {
|
||||||
|
@ -151,7 +168,11 @@ function SettingWalletServer(props: Props) {
|
||||||
{host}:{port}
|
{host}:{port}
|
||||||
</h3>
|
</h3>
|
||||||
<span className="help">
|
<span className="help">
|
||||||
{available ? __('Connected') : walletReconnecting ? __('Connecting...') : __('Not connected')}
|
{available
|
||||||
|
? __('Connected')
|
||||||
|
: walletReconnecting && !walletReconnectingToDefault
|
||||||
|
? __('Connecting...')
|
||||||
|
: __('Not connected')}
|
||||||
</span>
|
</span>
|
||||||
<Button
|
<Button
|
||||||
button="close"
|
button="close"
|
||||||
|
|
|
@ -103,6 +103,7 @@ export const WALLET_STATUS_START = 'WALLET_STATUS_START';
|
||||||
export const WALLET_STATUS_COMPLETED = 'WALLET_STATUS_COMPLETED';
|
export const WALLET_STATUS_COMPLETED = 'WALLET_STATUS_COMPLETED';
|
||||||
export const WALLET_RESTART = 'WALLET_RESTART';
|
export const WALLET_RESTART = 'WALLET_RESTART';
|
||||||
export const WALLET_RESTART_COMPLETED = 'WALLET_RESTART_COMPLETED';
|
export const WALLET_RESTART_COMPLETED = 'WALLET_RESTART_COMPLETED';
|
||||||
|
export const WALLET_ROLLBACK_DEFAULT = 'WALLET_ROLLBACK_DEFAULT';
|
||||||
export const SET_TRANSACTION_LIST_FILTER = 'SET_TRANSACTION_LIST_FILTER';
|
export const SET_TRANSACTION_LIST_FILTER = 'SET_TRANSACTION_LIST_FILTER';
|
||||||
export const UPDATE_CURRENT_HEIGHT = 'UPDATE_CURRENT_HEIGHT';
|
export const UPDATE_CURRENT_HEIGHT = 'UPDATE_CURRENT_HEIGHT';
|
||||||
export const SET_DRAFT_TRANSACTION_AMOUNT = 'SET_DRAFT_TRANSACTION_AMOUNT';
|
export const SET_DRAFT_TRANSACTION_AMOUNT = 'SET_DRAFT_TRANSACTION_AMOUNT';
|
||||||
|
|
|
@ -85,7 +85,7 @@ export function doClearDaemonSetting(key) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (key === DAEMON_SETTINGS.LBRYUM_SERVERS) {
|
if (key === DAEMON_SETTINGS.LBRYUM_SERVERS) {
|
||||||
dispatch(doWalletReconnect());
|
dispatch(doWalletReconnect(true));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Lbry.settings_get().then((settings) => {
|
Lbry.settings_get().then((settings) => {
|
||||||
|
|
|
@ -524,10 +524,11 @@ export function doSupportAbandonForClaim(claimId, claimType, keep, preview) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doWalletReconnect() {
|
export function doWalletReconnect(toDefaultServer = false) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.WALLET_RESTART,
|
type: ACTIONS.WALLET_RESTART,
|
||||||
|
data: toDefaultServer,
|
||||||
});
|
});
|
||||||
let failed = false;
|
let failed = false;
|
||||||
// this basically returns null when it's done. :(
|
// this basically returns null when it's done. :(
|
||||||
|
@ -545,15 +546,24 @@ export function doWalletReconnect() {
|
||||||
});
|
});
|
||||||
dispatch(
|
dispatch(
|
||||||
doToast({
|
doToast({
|
||||||
message: __('Your servers were not available. Check your url and port, or switch back to defaults.'),
|
message: __('Your servers were not available. Rolling back to the default server.'),
|
||||||
isError: true,
|
isError: true,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.WALLET_ROLLBACK_DEFAULT,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, FIFTEEN_SECONDS);
|
}, FIFTEEN_SECONDS);
|
||||||
Lbry.wallet_reconnect().then(() => {
|
Lbry.wallet_reconnect().then(() => {
|
||||||
clearTimeout(walletTimeout);
|
clearTimeout(walletTimeout);
|
||||||
if (!failed) dispatch({ type: ACTIONS.WALLET_RESTART_COMPLETED });
|
if (failed) {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.WALLET_ROLLBACK_DEFAULT,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
dispatch({ type: ACTIONS.WALLET_RESTART_COMPLETED });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -709,9 +719,8 @@ export const doCheckPendingTxs = () => (dispatch, getState) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// don't need hthis
|
// don't need hthis
|
||||||
export const doSendCashTip = (tipParams, anonymous, userParams, claimId, stripeEnvironment, successCallback) => (
|
export const doSendCashTip =
|
||||||
dispatch
|
(tipParams, anonymous, userParams, claimId, stripeEnvironment, successCallback) => (dispatch) => {
|
||||||
) => {
|
|
||||||
Lbryio.call(
|
Lbryio.call(
|
||||||
'customer',
|
'customer',
|
||||||
'tip',
|
'tip',
|
||||||
|
@ -750,4 +759,4 @@ export const doSendCashTip = (tipParams, anonymous, userParams, claimId, stripeE
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -105,7 +105,8 @@ const defaultState = {
|
||||||
fetchingTxosError: undefined,
|
fetchingTxosError: undefined,
|
||||||
pendingSupportTransactions: {},
|
pendingSupportTransactions: {},
|
||||||
pendingTxos: [],
|
pendingTxos: [],
|
||||||
|
walletRollbackToDefault: false,
|
||||||
|
walletReconnectingToDefault: false,
|
||||||
abandonClaimSupportError: undefined,
|
abandonClaimSupportError: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -320,12 +321,8 @@ export const walletReducer = handleActions(
|
||||||
},
|
},
|
||||||
|
|
||||||
[ACTIONS.ABANDON_CLAIM_SUPPORT_COMPLETED]: (state: WalletState, action: any): WalletState => {
|
[ACTIONS.ABANDON_CLAIM_SUPPORT_COMPLETED]: (state: WalletState, action: any): WalletState => {
|
||||||
const {
|
const { claimId, type, txid, effective }: { claimId: string, type: string, txid: string, effective: string } =
|
||||||
claimId,
|
action.data;
|
||||||
type,
|
|
||||||
txid,
|
|
||||||
effective,
|
|
||||||
}: { claimId: string, type: string, txid: string, effective: string } = action.data;
|
|
||||||
const pendingtxs = Object.assign({}, state.pendingSupportTransactions);
|
const pendingtxs = Object.assign({}, state.pendingSupportTransactions);
|
||||||
|
|
||||||
pendingtxs[claimId] = { txid, type, effective };
|
pendingtxs[claimId] = { txid, type, effective };
|
||||||
|
@ -535,14 +532,22 @@ export const walletReducer = handleActions(
|
||||||
...state,
|
...state,
|
||||||
latestBlock: action.data,
|
latestBlock: action.data,
|
||||||
}),
|
}),
|
||||||
[ACTIONS.WALLET_RESTART]: (state: WalletState) => ({
|
[ACTIONS.WALLET_RESTART]: (state: WalletState, action: { data: boolean }) => ({
|
||||||
...state,
|
...state,
|
||||||
walletReconnecting: true,
|
walletReconnecting: true,
|
||||||
|
walletReconnectingToDefault: action.data,
|
||||||
|
walletRollbackToDefault: false,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
[ACTIONS.WALLET_RESTART_COMPLETED]: (state: WalletState) => ({
|
[ACTIONS.WALLET_RESTART_COMPLETED]: (state: WalletState) => ({
|
||||||
...state,
|
...state,
|
||||||
walletReconnecting: false,
|
walletReconnecting: false,
|
||||||
|
walletReconnectingToDefault: false,
|
||||||
|
}),
|
||||||
|
|
||||||
|
[ACTIONS.WALLET_ROLLBACK_DEFAULT]: (state: WalletState) => ({
|
||||||
|
...state,
|
||||||
|
walletRollbackToDefault: true,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
defaultState
|
defaultState
|
||||||
|
|
|
@ -260,6 +260,13 @@ export const selectFilteredTransactionCount = createSelector(
|
||||||
|
|
||||||
export const selectIsWalletReconnecting = createSelector(selectState, (state) => state.walletReconnecting);
|
export const selectIsWalletReconnecting = createSelector(selectState, (state) => state.walletReconnecting);
|
||||||
|
|
||||||
|
export const selectWalletRollbackToDefault = createSelector(selectState, (state) => state.walletRollbackToDefault);
|
||||||
|
|
||||||
|
export const selectWalletConnectingToDefault = createSelector(
|
||||||
|
selectState,
|
||||||
|
(state) => state.walletReconnectingToDefault
|
||||||
|
);
|
||||||
|
|
||||||
export const selectIsFetchingUtxoCounts = createSelector(selectState, (state) => state.fetchingUtxoCounts);
|
export const selectIsFetchingUtxoCounts = createSelector(selectState, (state) => state.fetchingUtxoCounts);
|
||||||
|
|
||||||
export const selectIsConsolidatingUtxos = createSelector(selectState, (state) => state.consolidatingUtxos);
|
export const selectIsConsolidatingUtxos = createSelector(selectState, (state) => state.consolidatingUtxos);
|
||||||
|
|
Loading…
Reference in a new issue