Skip to content
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

Reconnect to default server if custom server fails. #7593

Merged
Merged
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
8 changes: 7 additions & 1 deletion ui/component/settingWalletServer/index.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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) => ({
Expand Down
37 changes: 29 additions & 8 deletions ui/component/settingWalletServer/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type Props = {
hasWalletServerPrefs: boolean,
daemonStatus: DaemonStatus,
walletReconnecting: boolean,
walletRollbackToDefault: boolean,
walletReconnectingToDefault: boolean,
};

function SettingWalletServer(props: Props) {
Expand All @@ -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) || [];
Expand Down Expand Up @@ -73,7 +78,7 @@ function SettingWalletServer(props: Props) {

useEffect(() => {
if (hasWalletServerPrefs) {
setAdvancedMode(true);
setUsingCustomServer(true);
}
}, []);

Expand All @@ -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();
}

Expand All @@ -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) {
Expand All @@ -123,17 +140,17 @@ 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));
}
}}
label={__('Use custom wallet servers')}
/>

{advancedMode && (
{showCustomServers && (
<div>
{serverConfig &&
serverConfig.map((entry, index) => {
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions ui/constants/action_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion ui/redux/actions/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function doClearDaemonSetting(key) {
});
}
if (key === DAEMON_SETTINGS.LBRYUM_SERVERS) {
dispatch(doWalletReconnect());
dispatch(doWalletReconnect(true));
}
});
Lbry.settings_get().then((settings) => {
Expand Down
97 changes: 53 additions & 44 deletions ui/redux/actions/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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. :(
Expand All @@ -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 });
}
});
};
}
Expand Down Expand Up @@ -709,45 +719,44 @@ export const doCheckPendingTxs = () => (dispatch, getState) => {
};

// don't need hthis
export const doSendCashTip = (tipParams, anonymous, userParams, claimId, stripeEnvironment, successCallback) => (
dispatch
) => {
Lbryio.call(
'customer',
'tip',
{
// round to fix issues with floating point numbers
amount: Math.round(100 * tipParams.tipAmount), // convert from dollars to cents
creator_channel_name: tipParams.tipChannelName, // creator_channel_name
creator_channel_claim_id: tipParams.channelClaimId,
tipper_channel_name: anonymous ? '' : userParams.activeChannelName,
tipper_channel_claim_id: anonymous ? '' : userParams.activeChannelId,
currency: 'USD',
anonymous: anonymous,
source_claim_id: claimId,
environment: stripeEnvironment,
},
'post'
)
.then((customerTipResponse) => {
dispatch(
doToast({
message: __("You sent $%tipAmount% as a tip to %tipChannelName%, I'm sure they appreciate it!", {
tipAmount: tipParams.tipAmount,
tipChannelName: tipParams.tipChannelName,
}),
})
);
export const doSendCashTip =
(tipParams, anonymous, userParams, claimId, stripeEnvironment, successCallback) => (dispatch) => {
Lbryio.call(
'customer',
'tip',
{
// round to fix issues with floating point numbers
amount: Math.round(100 * tipParams.tipAmount), // convert from dollars to cents
creator_channel_name: tipParams.tipChannelName, // creator_channel_name
creator_channel_claim_id: tipParams.channelClaimId,
tipper_channel_name: anonymous ? '' : userParams.activeChannelName,
tipper_channel_claim_id: anonymous ? '' : userParams.activeChannelId,
currency: 'USD',
anonymous: anonymous,
source_claim_id: claimId,
environment: stripeEnvironment,
},
'post'
)
.then((customerTipResponse) => {
dispatch(
doToast({
message: __("You sent $%tipAmount% as a tip to %tipChannelName%, I'm sure they appreciate it!", {
tipAmount: tipParams.tipAmount,
tipChannelName: tipParams.tipChannelName,
}),
})
);

if (successCallback) successCallback(customerTipResponse);
})
.catch((error) => {
// show error message from Stripe if one exists (being passed from backend by Beamer's API currently)
dispatch(
doToast({
message: error.message || __('Sorry, there was an error in processing your payment!'),
isError: true,
})
);
});
};
if (successCallback) successCallback(customerTipResponse);
})
.catch((error) => {
// show error message from Stripe if one exists (being passed from backend by Beamer's API currently)
dispatch(
doToast({
message: error.message || __('Sorry, there was an error in processing your payment!'),
isError: true,
})
);
});
};
21 changes: 13 additions & 8 deletions ui/redux/reducers/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ const defaultState = {
fetchingTxosError: undefined,
pendingSupportTransactions: {},
pendingTxos: [],

walletRollbackToDefault: false,
walletReconnectingToDefault: false,
abandonClaimSupportError: undefined,
};

Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions ui/redux/selectors/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down