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

TW-1362: Fix app crash after switch to T4L3NT #1048

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
7 changes: 4 additions & 3 deletions src/components/icon-title-no-bg/icon-title-no-bg.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC } from 'react';
import { Text } from 'react-native';
import { StyleProp, Text, TextStyle } from 'react-native';
import { TouchableOpacity } from 'react-native-gesture-handler';

import { TestIdProps } from 'src/interfaces/test-id.props';
Expand All @@ -12,16 +12,17 @@ import { useIconTitleNoBgStyles } from './icon-title-no-bg.styles';
interface Props extends TestIdProps {
text: string;
icon: IconNameEnum;
textStyle?: StyleProp<TextStyle>;
onPress: EmptyFn;
}

export const IconTitleNoBg: FC<Props> = ({ text, icon, onPress, testID }) => {
export const IconTitleNoBg: FC<Props> = ({ text, icon, textStyle, onPress, testID }) => {
const styles = useIconTitleNoBgStyles();

return (
<TouchableOpacity style={styles.touchableOpacity} onPress={onPress} testID={testID}>
<Icon name={icon} />
<Text style={styles.text}>{text}</Text>
<Text style={[styles.text, textStyle]}>{text}</Text>
</TouchableOpacity>
);
};
12 changes: 11 additions & 1 deletion src/components/styled-radio-group/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ interface Props<T extends string> extends StyledRadioGroupProps<T>, TestIdProps
value: T;
onChange: (value: T) => void;
labelStyle?: ViewStyle;
disabledLabelStyle?: ViewStyle;
}

export const StyledRadioGroup = <T extends string>({ value, items, onChange, labelStyle, testID }: Props<T>) => {
export const StyledRadioGroup = <T extends string>({
value,
items,
onChange,
disabledLabelStyle,
labelStyle,
testID
}: Props<T>) => {
const colors = useColors();
const styles = useStyledRadioButtonsGroupStyles();

Expand All @@ -29,8 +37,10 @@ export const StyledRadioGroup = <T extends string>({ value, items, onChange, lab
value={value}
onPress={onChange}
color={colors.orange}
disabledColor={colors.disabled}
itemContainerStyle={styles.itemContainer}
itemLabelStyle={[styles.label, labelStyle]}
disabledItemLabelStyle={[styles.label, disabledLabelStyle ?? styles.disabledLabel]}
testID={testID}
/>
</View>
Expand Down
16 changes: 13 additions & 3 deletions src/components/styled-radio-group/radio-group/radio-group.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { useMemo } from 'react';
import { View } from 'react-native';

import { showWarningToast } from 'src/toast/toast.utils';
import { AnalyticsEventCategory } from 'src/utils/analytics/analytics-event.enum';
import { useAnalytics } from 'src/utils/analytics/use-analytics.hook';
import { isDefined } from 'src/utils/is-defined';

import { RadioItem } from './radio-item';
import { groupStyles } from './styles';
Expand All @@ -12,7 +14,9 @@ export const RadioGroup = <T extends string>({
items,
value: currentValue,
color = '#444',
disabledColor = '#ccc',
itemContainerStyle,
disabledItemLabelStyle: disabledLabelStyle,
itemLabelStyle,
onPress,
testID
Expand All @@ -31,18 +35,24 @@ export const RadioGroup = <T extends string>({
key: item.value,
...item,
selected: item.value === currentValue,
onPress: handlePress
onPress: (value: string) =>
isDefined(item.disabledMessage) ? showWarningToast({ description: item.disabledMessage }) : handlePress(value)
}));
}, [items, currentValue, trackEvent, testID]);

const totalDisabledLabelStyle = useMemo(
() => [itemLabelStyle, disabledLabelStyle].flat(),
[itemLabelStyle, disabledLabelStyle]
);

return (
<View style={groupStyles.container}>
{itemsLocal.map(item => (
<RadioItem
{...item}
color={color}
color={isDefined(item.disabledMessage) ? disabledColor : color}
containerStyle={itemContainerStyle}
labelStyle={itemLabelStyle}
labelStyle={isDefined(item.disabledMessage) ? totalDisabledLabelStyle : itemLabelStyle}
testID={testID}
/>
))}
Expand Down
4 changes: 4 additions & 0 deletions src/components/styled-radio-group/radio-group/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface RadioItemInterface<T extends string> {
value: T;
label?: string;
buttons?: ItemButtonInterface[];
/** If specified, the item cannot be selected but this message is displayed on an attempt to select the item */
disabledMessage?: string;
}

export interface RadioItemProps extends RadioItemInterface<string>, TestIdProps {
Expand All @@ -24,7 +26,9 @@ export interface RadioGroupProps<T extends string> extends TestIdProps {
items: RadioItemInterface<T>[];
value?: T;
color?: string;
disabledColor?: string;
itemContainerStyle?: StyleType;
disabledItemLabelStyle?: StyleType;
itemLabelStyle?: StyleType;
onPress: (value: T) => void;
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/styled-radio-group/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ export const useStyledRadioButtonsGroupStyles = createUseStyles(({ colors, typog
...typography.body15Semibold,
color: colors.black,
flex: 1
},
disabledLabel: {
...typography.body15Semibold,
color: colors.disabled,
flex: 1
}
}));
3 changes: 3 additions & 0 deletions src/modals/custom-rpc-modals/edit-modal/edit-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { useAnalytics, usePageAnalytic } from 'src/utils/analytics/use-analytics
import { formInitialValues, formValidationSchema, confirmUniqueRPC } from '../form.utils';

import { EditModalSelectors } from './edit-modal.selectors';
import { useEditModalStyles } from './styles';

export const EditCustomRpcModal: FC = () => {
const { url } = useRoute<RouteProp<ModalsParamList, ModalsEnum.EditCustomRpc>>().params;
Expand All @@ -36,6 +37,7 @@ export const EditCustomRpcModal: FC = () => {
const { goBack } = useNavigation();
const { trackEvent } = useAnalytics();
const rpcList = useRpcListSelector();
const styles = useEditModalStyles();

const initialValues = useMemo(() => {
const rpc = rpcList.find(rpc => rpc.url === url);
Expand Down Expand Up @@ -105,6 +107,7 @@ export const EditCustomRpcModal: FC = () => {
<IconTitleNoBg
icon={IconNameEnum.Trash}
text="Delete RPC"
textStyle={styles.destructive}
onPress={onDeleteButtonPress}
testID={EditModalSelectors.deleteRpcButton}
/>
Expand Down
7 changes: 7 additions & 0 deletions src/modals/custom-rpc-modals/edit-modal/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createUseStylesMemoized } from 'src/styles/create-use-styles';

export const useEditModalStyles = createUseStylesMemoized(({ colors }) => ({
destructive: {
color: colors.destructive
}
}));
6 changes: 4 additions & 2 deletions src/screens/node-settings/node-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useNavigation } from 'src/navigator/hooks/use-navigation.hook';
import { setSelectedRpcUrl } from 'src/store/settings/settings-actions';
import { useRpcListSelector, useSelectedRpcUrlSelector } from 'src/store/settings/settings-selectors';
import { usePageAnalytic } from 'src/utils/analytics/use-analytics.hook';
import { isDcpNode } from 'src/utils/network.utils';
import { TEMPLE_RPC } from 'src/utils/rpc/rpc-list';

import { NodeSettingsSelectors } from './node-settings.selectors';
Expand All @@ -34,10 +35,11 @@ export const NodeSettings = () => {
{
key: 'edit',
iconName: IconNameEnum.Edit,
disabled: rpc.url === TEMPLE_RPC.url ? true : undefined,
disabled: rpc.url === TEMPLE_RPC.url || isDcpNode(rpc.url) ? true : undefined,
onPress: () => void navigate(ModalsEnum.EditCustomRpc, { url: rpc.url })
}
]
],
disabledMessage: isDcpNode(rpc.url) ? 'The T4L3NT Mainnet RPC is temporarily unavailable.' : undefined
})),
[rpcList]
);
Expand Down
Loading