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 { selectIsWalletReconnecting } from 'redux/selectors/wallet';
|
||||
import {
|
||||
selectIsWalletReconnecting,
|
||||
selectWalletRollbackToDefault,
|
||||
selectWalletConnectingToDefault,
|
||||
} from 'redux/selectors/wallet';
|
||||
import * as DAEMON_SETTINGS from 'constants/daemon_settings';
|
||||
import {
|
||||
doSetDaemonSetting,
|
||||
|
@ -15,6 +19,8 @@ const select = (state) => ({
|
|||
customWalletServers: selectSavedWalletServers(state),
|
||||
hasWalletServerPrefs: selectHasWalletServerPrefs(state),
|
||||
walletReconnecting: selectIsWalletReconnecting(state),
|
||||
walletRollbackToDefault: selectWalletRollbackToDefault(state),
|
||||
walletReconnectingToDefault: selectWalletConnectingToDefault(state),
|
||||
});
|
||||
|
||||
const perform = (dispatch) => ({
|
||||
|
|
|
@ -30,6 +30,8 @@ type Props = {
|
|||
hasWalletServerPrefs: boolean,
|
||||
daemonStatus: DaemonStatus,
|
||||
walletReconnecting: boolean,
|
||||
walletRollbackToDefault: boolean,
|
||||
walletReconnectingToDefault: boolean,
|
||||
};
|
||||
|
||||
function SettingWalletServer(props: Props) {
|
||||
|
@ -42,9 +44,12 @@ function SettingWalletServer(props: Props) {
|
|||
customWalletServers,
|
||||
hasWalletServerPrefs,
|
||||
walletReconnecting,
|
||||
walletRollbackToDefault,
|
||||
walletReconnectingToDefault,
|
||||
} = props;
|
||||
|
||||
const [advancedMode, setAdvancedMode] = useState(false);
|
||||
const [usingCustomServer, setUsingCustomServer] = useState(false);
|
||||
const [showCustomServers, setShowCustomServers] = useState(false);
|
||||
|
||||
const walletStatus = daemonStatus && daemonStatus.wallet;
|
||||
const activeWalletServers: ServerStatus = (walletStatus && walletStatus.servers) || [];
|
||||
|
@ -73,7 +78,7 @@ function SettingWalletServer(props: Props) {
|
|||
|
||||
useEffect(() => {
|
||||
if (hasWalletServerPrefs) {
|
||||
setAdvancedMode(true);
|
||||
setUsingCustomServer(true);
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
@ -84,8 +89,20 @@ function SettingWalletServer(props: Props) {
|
|||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (walletRollbackToDefault) {
|
||||
doClear();
|
||||
}
|
||||
}, [walletRollbackToDefault]);
|
||||
|
||||
useEffect(() => {
|
||||
if (usingCustomServer) {
|
||||
setShowCustomServers(true);
|
||||
}
|
||||
}, [usingCustomServer]);
|
||||
|
||||
function doClear() {
|
||||
setAdvancedMode(false);
|
||||
setUsingCustomServer(false);
|
||||
clearWalletServers();
|
||||
}
|
||||
|
||||
|
@ -112,7 +129,7 @@ function SettingWalletServer(props: Props) {
|
|||
<FormField
|
||||
type="radio"
|
||||
name="default_wallet_servers"
|
||||
checked={!advancedMode}
|
||||
checked={!usingCustomServer}
|
||||
label={__('Use official LBRY wallet servers')}
|
||||
onChange={(e) => {
|
||||
if (e.target.checked) {
|
||||
|
@ -123,9 +140,9 @@ function SettingWalletServer(props: Props) {
|
|||
<FormField
|
||||
type="radio"
|
||||
name="custom_wallet_servers"
|
||||
checked={advancedMode}
|
||||
checked={usingCustomServer}
|
||||
onChange={(e) => {
|
||||
setAdvancedMode(e.target.checked);
|
||||
setUsingCustomServer(e.target.checked);
|
||||
if (e.target.checked && customWalletServers.length) {
|
||||
setCustomWalletServers(stringifyServerParam(customWalletServers));
|
||||
}
|
||||
|
@ -133,7 +150,7 @@ function SettingWalletServer(props: Props) {
|
|||
label={__('Use custom wallet servers')}
|
||||
/>
|
||||
|
||||
{advancedMode && (
|
||||
{showCustomServers && (
|
||||
<div>
|
||||
{serverConfig &&
|
||||
serverConfig.map((entry, index) => {
|
||||
|
@ -151,7 +168,11 @@ function SettingWalletServer(props: Props) {
|
|||
{host}:{port}
|
||||
</h3>
|
||||
<span className="help">
|
||||
{available ? __('Connected') : walletReconnecting ? __('Connecting...') : __('Not connected')}
|
||||
{available
|
||||
? __('Connected')
|
||||
: walletReconnecting && !walletReconnectingToDefault
|
||||
? __('Connecting...')
|
||||
: __('Not connected')}
|
||||
</span>
|
||||
<Button
|
||||
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_RESTART = 'WALLET_RESTART';
|
||||
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 UPDATE_CURRENT_HEIGHT = 'UPDATE_CURRENT_HEIGHT';
|
||||
export const SET_DRAFT_TRANSACTION_AMOUNT = 'SET_DRAFT_TRANSACTION_AMOUNT';
|
||||
|
|
|
@ -85,7 +85,7 @@ export function doClearDaemonSetting(key) {
|
|||
});
|
||||
}
|
||||
if (key === DAEMON_SETTINGS.LBRYUM_SERVERS) {
|
||||
dispatch(doWalletReconnect());
|
||||
dispatch(doWalletReconnect(true));
|
||||
}
|
||||
});
|
||||
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) => {
|
||||
dispatch({
|
||||
type: ACTIONS.WALLET_RESTART,
|
||||
data: toDefaultServer,
|
||||
});
|
||||
let failed = false;
|
||||
// this basically returns null when it's done. :(
|
||||
|
@ -545,15 +546,24 @@ export function doWalletReconnect() {
|
|||
});
|
||||
dispatch(
|
||||
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,
|
||||
})
|
||||
);
|
||||
dispatch({
|
||||
type: ACTIONS.WALLET_ROLLBACK_DEFAULT,
|
||||
});
|
||||
}
|
||||
}, FIFTEEN_SECONDS);
|
||||
Lbry.wallet_reconnect().then(() => {
|
||||
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
|
||||
export const doSendCashTip = (tipParams, anonymous, userParams, claimId, stripeEnvironment, successCallback) => (
|
||||
dispatch
|
||||
) => {
|
||||
export const doSendCashTip =
|
||||
(tipParams, anonymous, userParams, claimId, stripeEnvironment, successCallback) => (dispatch) => {
|
||||
Lbryio.call(
|
||||
'customer',
|
||||
'tip',
|
||||
|
|
|
@ -105,7 +105,8 @@ const defaultState = {
|
|||
fetchingTxosError: undefined,
|
||||
pendingSupportTransactions: {},
|
||||
pendingTxos: [],
|
||||
|
||||
walletRollbackToDefault: false,
|
||||
walletReconnectingToDefault: false,
|
||||
abandonClaimSupportError: undefined,
|
||||
};
|
||||
|
||||
|
@ -320,12 +321,8 @@ export const walletReducer = handleActions(
|
|||
},
|
||||
|
||||
[ACTIONS.ABANDON_CLAIM_SUPPORT_COMPLETED]: (state: WalletState, action: any): WalletState => {
|
||||
const {
|
||||
claimId,
|
||||
type,
|
||||
txid,
|
||||
effective,
|
||||
}: { claimId: string, type: string, txid: string, effective: string } = action.data;
|
||||
const { claimId, type, txid, effective }: { claimId: string, type: string, txid: string, effective: string } =
|
||||
action.data;
|
||||
const pendingtxs = Object.assign({}, state.pendingSupportTransactions);
|
||||
|
||||
pendingtxs[claimId] = { txid, type, effective };
|
||||
|
@ -535,14 +532,22 @@ export const walletReducer = handleActions(
|
|||
...state,
|
||||
latestBlock: action.data,
|
||||
}),
|
||||
[ACTIONS.WALLET_RESTART]: (state: WalletState) => ({
|
||||
[ACTIONS.WALLET_RESTART]: (state: WalletState, action: { data: boolean }) => ({
|
||||
...state,
|
||||
walletReconnecting: true,
|
||||
walletReconnectingToDefault: action.data,
|
||||
walletRollbackToDefault: false,
|
||||
}),
|
||||
|
||||
[ACTIONS.WALLET_RESTART_COMPLETED]: (state: WalletState) => ({
|
||||
...state,
|
||||
walletReconnecting: false,
|
||||
walletReconnectingToDefault: false,
|
||||
}),
|
||||
|
||||
[ACTIONS.WALLET_ROLLBACK_DEFAULT]: (state: WalletState) => ({
|
||||
...state,
|
||||
walletRollbackToDefault: true,
|
||||
}),
|
||||
},
|
||||
defaultState
|
||||
|
|
|
@ -260,6 +260,13 @@ export const selectFilteredTransactionCount = createSelector(
|
|||
|
||||
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 selectIsConsolidatingUtxos = createSelector(selectState, (state) => state.consolidatingUtxos);
|
||||
|
|
Loading…
Reference in a new issue