Merge branch 'clearnet' into merge-dialogs

pull/1706/head
Warrick Corfe-Tan 4 years ago
commit 250db61356

@ -18,6 +18,11 @@ import countryLookup from 'country-code-lookup';
import { useTheme } from 'styled-components'; import { useTheme } from 'styled-components';
import { Snode } from '../data/data'; import { Snode } from '../data/data';
import { onionPathModal } from '../state/ducks/modalDialog'; import { onionPathModal } from '../state/ducks/modalDialog';
import {
getFirstOnionPath,
getFirstOnionPathLength,
getOnionPathsCount,
} from '../state/selectors/onions';
// tslint:disable-next-line: no-submodule-imports // tslint:disable-next-line: no-submodule-imports
import useNetworkState from 'react-use/lib/useNetworkState'; import useNetworkState from 'react-use/lib/useNetworkState';
@ -35,8 +40,7 @@ export type StatusLightType = {
}; };
const OnionPathModalInner = () => { const OnionPathModalInner = () => {
const onionNodes = useSelector((state: StateType) => state.onionPaths.snodePath); const onionPath = useSelector(getFirstOnionPath);
const onionPath = onionNodes;
// including the device and destination in calculation // including the device and destination in calculation
const glowDuration = onionPath.length + 2; const glowDuration = onionPath.length + 2;
@ -44,7 +48,7 @@ const OnionPathModalInner = () => {
{ {
label: window.i18n('device'), label: window.i18n('device'),
}, },
...onionNodes, ...onionPath,
{ {
label: window.i18n('destination'), label: window.i18n('destination'),
}, },
@ -133,29 +137,21 @@ export const ActionPanelOnionStatusLight = (props: {
}) => { }) => {
const { isSelected, handleClick } = props; const { isSelected, handleClick } = props;
let iconColor;
const theme = useTheme(); const theme = useTheme();
const firstOnionPath = useSelector((state: StateType) => state.onionPaths.snodePath); const onionPathsCount = useSelector(getOnionPathsCount);
const hasOnionPath = firstOnionPath.length > 2; const firstPathLength = useSelector(getFirstOnionPathLength);
const isOnline = useNetworkState().online;
// Set icon color based on result // Set icon color based on result
const red = theme.colors.destructive; const red = theme.colors.destructive;
const green = theme.colors.accent; const green = theme.colors.accent;
const orange = theme.colors.warning; const orange = theme.colors.warning;
iconColor = hasOnionPath ? theme.colors.accent : theme.colors.destructive; // start with red
const onionState = useSelector((state: StateType) => state.onionPaths); let iconColor = red;
//if we are not online or the first path is not valid, we keep red as color
iconColor = red; if (isOnline && firstPathLength > 1) {
const isOnline = useNetworkState().online; iconColor = onionPathsCount > 2 ? green : onionPathsCount > 1 ? orange : red;
if (!(onionState && onionState.snodePath) || !isOnline) {
iconColor = red;
} else {
const onionSnodePath = onionState.snodePath;
if (onionState && onionSnodePath && onionSnodePath.length > 0) {
const onionNodeCount = onionSnodePath.length;
iconColor = onionNodeCount > 2 ? green : onionNodeCount > 1 ? orange : red;
}
} }
return ( return (

@ -136,7 +136,7 @@ export async function getOnionPath(toExclude?: Snode): Promise<Array<Snode>> {
if (onionPaths.length <= 0) { if (onionPaths.length <= 0) {
window.inboxStore?.dispatch(updateOnionPaths([])); window.inboxStore?.dispatch(updateOnionPaths([]));
} else { } else {
window.inboxStore?.dispatch(updateOnionPaths(onionPaths[0])); window.inboxStore?.dispatch(updateOnionPaths(onionPaths));
} }
const onionPathsWithoutExcluded = toExclude const onionPathsWithoutExcluded = toExclude

@ -2,11 +2,11 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { Snode } from '../../data/data'; import { Snode } from '../../data/data';
export type OnionState = { export type OnionState = {
snodePath: Array<Snode>; snodePaths: Array<Array<Snode>>;
}; };
export const initialOnionPathState = { export const initialOnionPathState = {
snodePath: new Array<Snode>(), snodePaths: new Array<Array<Snode>>(),
}; };
/** /**
@ -16,8 +16,8 @@ const onionSlice = createSlice({
name: 'onionPaths', name: 'onionPaths',
initialState: initialOnionPathState, initialState: initialOnionPathState,
reducers: { reducers: {
updateOnionPaths(state: OnionState, action: PayloadAction<Array<Snode>>) { updateOnionPaths(state: OnionState, action: PayloadAction<Array<Array<Snode>>>) {
return { snodePath: action.payload }; return { snodePaths: action.payload };
}, },
}, },
}); });

@ -0,0 +1,23 @@
import { createSelector } from 'reselect';
import { StateType } from '../reducer';
import { SectionType } from '../../components/session/ActionsPanel';
import { OnionState } from '../ducks/onion';
import { Snode } from '../../data/data';
export const getOnionPaths = (state: StateType): OnionState => state.onionPaths;
export const getOnionPathsCount = createSelector(
getOnionPaths,
(state: OnionState): SectionType => state.snodePaths.length
);
export const getFirstOnionPath = createSelector(
getOnionPaths,
(state: OnionState): Array<Snode> => state.snodePaths?.[0] || []
);
export const getFirstOnionPathLength = createSelector(
getFirstOnionPath,
(state: Array<Snode>): number => state.length || 0
);
Loading…
Cancel
Save