Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
194404b
Replaced sdk settings with DS components
brianacnguyen Feb 8, 2024
1fb07b8
refactor(ramp): use columnGap instead of negative margin
wachunei Mar 4, 2024
c94a319
test(ramp): update snapshots
wachunei Mar 4, 2024
f04f31e
refactor: use ternary in reset region button
wachunei Apr 2, 2024
79006a8
feat(ramp): add labels to activation keys
wachunei Apr 3, 2024
619b19c
test(ramp): update reducer test
wachunei Apr 3, 2024
89914af
feat(ramp): add settings views
wachunei Apr 3, 2024
9f8fdc5
refactor(ramp): imports
wachunei Apr 9, 2024
ca01399
Merge branch 'main' into feature/ramp-activation-keys-labels
wachunei Apr 11, 2024
4522550
Merge branch 'main' into feature/ramp-activation-keys-labels
wachunei Apr 12, 2024
93026fd
Merge branch 'main' into feature/ramp-activation-keys-labels
wachunei Apr 15, 2024
d8d98d9
Merge branch 'main' into feature/ramp-activation-keys-labels
wachunei Apr 19, 2024
027e0a2
Merge branch 'main' into feature/ramp-activation-keys-labels
desi Apr 23, 2024
1e39f4e
Merge branch 'main' into feature/ramp-activation-keys-labels
desi Apr 24, 2024
64b67b9
Merge branch 'main' into feature/ramp-activation-keys-labels
desi Apr 24, 2024
442af86
Merge branch 'main' into feature/ramp-activation-keys-labels
desi Apr 29, 2024
e96da0a
Merge branch 'main' into feature/ramp-activation-keys-labels
desi Apr 30, 2024
3dfe6b2
Merge branch 'main' into feature/ramp-activation-keys-labels
desi May 1, 2024
d6e1dcc
Merge branch 'main' into feature/ramp-activation-keys-labels
desi May 1, 2024
597e5b8
Merge branch 'main' into feature/ramp-activation-keys-labels
wachunei May 2, 2024
441c051
fix(ramp): typo
wachunei May 7, 2024
8429797
Merge branch 'main' into feature/ramp-activation-keys-labels
wachunei May 7, 2024
0ed4954
test(ramp): update test with labels
wachunei May 7, 2024
d652e32
Merge branch 'main' into feature/ramp-activation-keys-labels
wachunei May 8, 2024
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
6 changes: 3 additions & 3 deletions app/components/Nav/Main/MainNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import Drawer from '../../UI/Drawer';
import RampRoutes from '../../UI/Ramp/routes';
import { RampType } from '../../UI/Ramp/types';
import RampSettings from '../../UI/Ramp/Views/Settings';
import RampAddActivationKey from '../../UI/Ramp/Views/Settings/AddActivationKey';
import RampActivationKeyForm from '../../UI/Ramp/Views/Settings/ActivationKeyForm';

import { colors as importedColors } from '../../../styles/common';
import OrderDetails from '../../UI/Ramp/Views/OrderDetails';
Expand Down Expand Up @@ -269,8 +269,8 @@ const SettingsFlow = () => (
/>
<Stack.Screen name={Routes.RAMP.SETTINGS} component={RampSettings} />
<Stack.Screen
name={Routes.RAMP.ADD_ACTIVATION_KEY}
component={RampAddActivationKey}
name={Routes.RAMP.ACTIVATION_KEY_FORM}
component={RampActivationKeyForm}
/>
<Stack.Screen
name="ExperimentalSettings"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AddActivationKey from './AddActivationKey';
import ActivationKeyForm from './ActivationKeyForm';
import { renderScreen } from '../../../../../util/test/renderWithProvider';
import initialBackgroundState from '../../../../../util/test/initial-background-state.json';
import Routes from '../../../../../constants/navigation/Routes';
Expand All @@ -8,7 +8,7 @@ function render(Component: React.ComponentType) {
return renderScreen(
Component,
{
name: Routes.RAMP.ADD_ACTIVATION_KEY,
name: Routes.RAMP.ACTIVATION_KEY_FORM,
},
{
state: {
Expand Down Expand Up @@ -45,37 +45,37 @@ describe('AddActivationKey', () => {
jest.clearAllMocks();
});
it('renders correctly', () => {
render(AddActivationKey);
render(ActivationKeyForm);
expect(screen.toJSON()).toMatchSnapshot();
});

it('has button disabled when input is empty', () => {
render(AddActivationKey);
render(ActivationKeyForm);
const addButton = screen.getByRole('button', { name: 'Add' });
expect(addButton.props.disabled).toBe(true);
});

it('navigates back when pressing cancel', () => {
render(AddActivationKey);
render(ActivationKeyForm);
fireEvent.press(screen.getByRole('button', { name: 'Cancel' }));
expect(mockGoBack).toHaveBeenCalled();
});

it('calls onSubmit with a valid test key', () => {
const validKey = 'valid-key';
render(AddActivationKey);
render(ActivationKeyForm);
const textInput = screen.getByPlaceholderText(
'Paste or type an Activation Key',
);
fireEvent.changeText(textInput, validKey);
const addButton = screen.getByRole('button', { name: 'Add' });
fireEvent.press(addButton);
expect(mockOnSubmit).toHaveBeenCalledWith(validKey);
expect(mockOnSubmit).toHaveBeenCalledWith(validKey, '', undefined);
});

it('does not call onSubmit with an ivalid test key', () => {
const invalidKey = 'invalid-key!!';
render(AddActivationKey);
render(ActivationKeyForm);
const textInput = screen.getByPlaceholderText(
'Paste or type an Activation Key',
);
Expand Down
149 changes: 149 additions & 0 deletions app/components/UI/Ramp/Views/Settings/ActivationKeyForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// Third party dependencies
import React, { useCallback, useEffect, useState } from 'react';
import { useNavigation } from '@react-navigation/native';

// External dependencies
import Row from '../../components/Row';
import ScreenLayout from '../../components/ScreenLayout';
import Text, {
TextVariant,
} from '../../../../../component-library/components/Texts/Text';
import TextField from '../../../../../component-library/components/Form/TextField';
import Label from '../../../../../component-library/components/Form/Label';
import Button, {
ButtonVariants,
ButtonSize,
} from '../../../../../component-library/components/Buttons/Button';

import { getNavigationOptionsTitle } from '../../../Navbar';
import {
createNavigationDetails,
useParams,
} from '../../../../../util/navigation/navUtils';
import { useTheme } from '../../../../../util/theme';
import Routes from '../../../../../constants/navigation/Routes';
import { strings } from '../../../../../../locales/i18n';
import { regex } from '../../../../../util/regex';

// Internal dependencies
import styles from './Settings.styles';

interface ActivationKeyFormParams {
onSubmit: (key: string, label: string, active: boolean) => void;
key: string;
active: boolean;
label: string;
}

export const createActivationKeyFormNavDetails =
createNavigationDetails<ActivationKeyFormParams>(
Routes.RAMP.ACTIVATION_KEY_FORM,
);

function ActivationKeyForm() {
const navigation = useNavigation();
const {
key,
label: initialLabel,
active,
onSubmit,
} = useParams<ActivationKeyFormParams>();
const [activationKey, setActivationKey] = useState(key ?? '');
const [label, setLabel] = useState(initialLabel ?? '');
const { colors } = useTheme();
const style = styles();

useEffect(() => {
navigation.setOptions(
getNavigationOptionsTitle(
key
? strings('app_settings.fiat_on_ramp.edit_activation_key')
: strings('app_settings.fiat_on_ramp.add_activation_key'),
navigation,
false,
colors,
),
);
}, [colors, key, navigation]);

const handleSubmit = useCallback(() => {
if (!regex.activationKey.test(activationKey)) {
return;
}
onSubmit(activationKey, label, active);
navigation.goBack();
}, [activationKey, navigation, onSubmit, active, label]);

const handleCancel = useCallback(() => {
navigation.goBack();
}, [navigation]);

return (
<ScreenLayout>
<ScreenLayout.Body>
<ScreenLayout.Content>
<Text variant={TextVariant.BodyLGMedium}>
{key
? strings('app_settings.fiat_on_ramp.edit_activation_key')
: strings('app_settings.fiat_on_ramp.add_activation_key')}
</Text>

<Row>
<Label>{strings('app_settings.fiat_on_ramp.label')}</Label>
<TextField
autoCapitalize={'none'}
onChangeText={setLabel}
placeholder={strings('app_settings.fiat_on_ramp.add_label')}
numberOfLines={1}
value={label}
returnKeyType={'done'}
onSubmitEditing={handleSubmit}
autoFocus
/>
</Row>
<Row>
<Label>{strings('app_settings.fiat_on_ramp.key')}</Label>
<TextField
autoCapitalize={'none'}
autoCorrect={false}
onChangeText={setActivationKey}
placeholder={strings(
'app_settings.fiat_on_ramp.paste_or_type_activation_key',
)}
spellCheck={false}
numberOfLines={1}
value={activationKey}
returnKeyType={'done'}
onSubmitEditing={handleSubmit}
isReadonly={Boolean(key)}
/>
</Row>

<Row style={style.buttons}>
<Button
variant={ButtonVariants.Secondary}
size={ButtonSize.Lg}
style={style.button}
onPress={handleCancel}
label={strings('app_settings.fiat_on_ramp.cancel')}
/>
<Button
variant={ButtonVariants.Primary}
size={ButtonSize.Lg}
style={style.button}
onPress={handleSubmit}
label={
key
? strings('app_settings.fiat_on_ramp.update')
: strings('app_settings.fiat_on_ramp.add')
}
isDisabled={!regex.activationKey.test(activationKey)}
/>
</Row>
</ScreenLayout.Content>
</ScreenLayout.Body>
</ScreenLayout>
);
}

export default ActivationKeyForm;
Loading