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

skip captcha on dev mode and refetch setting on phone change #848

Merged
merged 5 commits into from
Sep 10, 2024
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
2 changes: 1 addition & 1 deletion examples/client/Locomotion/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions examples/client/Locomotion/src/context/onboarding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ interface OnboardingContextInterface {
navigateBasedOnUser: (user: any) => void,
requiredOnboarding: any,
nextScreen: (currentScreen: string) => void,
fetchHideCaptchaSetting: () => void,
shouldHideCaptcha?: boolean,
}

export const OnboardingContext = createContext<OnboardingContextInterface>({
verifyCode: async code => undefined,
navigateBasedOnUser: user => undefined,
requiredOnboarding: {},
nextScreen: (currentScreen: string) => undefined,
fetchHideCaptchaSetting: async () => undefined,
shouldHideCaptcha: false,
});

const SCREEN_ORDER = [
Expand Down Expand Up @@ -63,7 +67,15 @@ const OnboardingContextProvider = ({ children }: { children: any }) => {
[MAIN_ROUTES.AVATAR]: false,
[MAIN_ROUTES.CARD]: false,
});
const [shouldHideCaptcha, setShouldHideCaptcha] = useState(false);
const fetchHideCaptchaSetting = async () => {
const hideCaptchaSetting = await getSettingByKey(
SETTINGS_KEYS.DISABLE_CAPTCHA_UI,
true,
);

setShouldHideCaptcha(hideCaptchaSetting);
};
const navigateToScreen = (screen: string) => navigationService.navigate(screen);

const shouldShowCardPage = async () => {
Expand Down Expand Up @@ -155,6 +167,8 @@ const OnboardingContextProvider = ({ children }: { children: any }) => {
navigateBasedOnUser,
requiredOnboarding,
nextScreen,
fetchHideCaptchaSetting,
shouldHideCaptcha,
}}
>
{children}
Expand Down
4 changes: 2 additions & 2 deletions examples/client/Locomotion/src/context/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const useSettings = () => {
const [showPrice, setShowPrice] = useState(false);


const getSettingByKey = async (key) => {
const getSettingByKey = async (key, invalidateCache = false) => {
let value = await StorageService.get(key);
if (value === undefined) {
if (value === undefined || invalidateCache) {
({ value } = await settingsApi.getByKey(key));
await StorageService.save({
[key]: value,
Expand Down
9 changes: 6 additions & 3 deletions examples/client/Locomotion/src/pages/DevPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react';
import React, { useContext, useState } from 'react';
import { ScrollView } from 'react-native-gesture-handler';
import Config from 'react-native-config';
import { OnboardingContext } from '../../context/onboarding';
import TextInput from '../../Components/TextInput';
import { NavButton, ButtonText } from '../Profile/SaveButton/styles';
import AppSettings from '../../services/app-settings';
Expand All @@ -15,6 +16,7 @@ const DevSettingPage = () => {
const [operationId, setOperationId] = useState(Config.OPERATION_ID);
const [serverUrl, setServerUrl] = useState(Config.SERVER_HOST);
const [stripeKey, setStripeKey] = useState(Config.STRIPE_PUBLISHER_KEY);
const { fetchHideCaptchaSetting } = useContext(OnboardingContext);
return (
<PageContainer>
<PageHeader
Expand Down Expand Up @@ -53,8 +55,9 @@ const DevSettingPage = () => {
/>
<NavButton
testID="saveButton"
onPress={() => {
AppSettings.setSettings({ serverUrl, operationId, stripeKey });
onPress={async () => {
await AppSettings.setSettings({ serverUrl, operationId, stripeKey });
await fetchHideCaptchaSetting();
navigationService.goBack();
}}
ofekrotem marked this conversation as resolved.
Show resolved Hide resolved
>
Expand Down
18 changes: 5 additions & 13 deletions examples/client/Locomotion/src/pages/Profile/Phone.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,22 @@ import AppSettings from '../../services/app-settings';
import * as NavigationService from '../../services/navigation';
import { PageContainer, ContentContainer } from '../styles';
import Auth from '../../services/auth';
import SETTINGS_KEYS from '../../context/settings/keys';


const Phone = ({ navigation }) => {
const { nextScreen } = useContext(OnboardingContext);
const { nextScreen, shouldHideCaptcha, fetchHideCaptchaSetting } = useContext(OnboardingContext);
const { updateState, user, onLogin } = useContext(UserContext);
const [showErrorText, setShowErrorText] = useState(false);
const [renderId, setRenderId] = useState(0);
const [isInvalid, setIsInvalid] = useState(true);
const recaptchaRef = useRef(null);
const [captchaToken, setCaptchaToken] = useState(null);
const [isLoadingSaveButton, setIsLoadingSaveButton] = useState(false);
const [shouldHideCaptcha, setShouldHideCaptcha] = useState(false);
const { getSettingByKey } = settings.useContainer();
const fetchHideCaptchaSetting = async () => {
const hideCaptchaSetting = await getSettingByKey(
SETTINGS_KEYS.DISABLE_CAPTCHA_UI,
);
Mixpanel.setEvent('Fetched hide captcha setting', { hideCaptchaSetting });
setShouldHideCaptcha(hideCaptchaSetting);
};

useEffect(() => {
fetchHideCaptchaSetting();
}, []);


const onVerifyCaptcha = async (verifiedCaptchaToken) => {
Mixpanel.setEvent('Captcha Verified successfully', { verifiedCaptchaToken });
setCaptchaToken(verifiedCaptchaToken);
Expand Down Expand Up @@ -94,7 +84,9 @@ const Phone = ({ navigation }) => {
};
useEffect(() => {
if (isLoadingSaveButton) {
if (!shouldHideCaptcha && Config.CAPTCHA_KEY && recaptchaRef.current) {
if (
!shouldHideCaptcha && Config.CAPTCHA_KEY && recaptchaRef.current && !isDebugPhoneNumber()
) {
recaptchaRef.current.open();
} else {
Mixpanel.setEvent('Submit phone number, without captcha , (Config.CAPTCHA_KEY is not defined)');
Expand Down
Loading