From 10713c3a8f28243285a7f9ed4db899376f749ad6 Mon Sep 17 00:00:00 2001 From: Ofek Rotem <92383710+ofekrotem@users.noreply.github.com> Date: Mon, 9 Sep 2024 11:23:50 +0300 Subject: [PATCH 1/5] skip captcha on dev mode and refetch setting on phone change --- examples/client/Locomotion/src/pages/Profile/Phone.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/client/Locomotion/src/pages/Profile/Phone.js b/examples/client/Locomotion/src/pages/Profile/Phone.js index 62bfad505..3e6b8db2f 100644 --- a/examples/client/Locomotion/src/pages/Profile/Phone.js +++ b/examples/client/Locomotion/src/pages/Profile/Phone.js @@ -44,7 +44,7 @@ const Phone = ({ navigation }) => { }; useEffect(() => { fetchHideCaptchaSetting(); - }, []); + }, [user?.phoneNumber]); const onVerifyCaptcha = async (verifiedCaptchaToken) => { @@ -94,7 +94,9 @@ const Phone = ({ navigation }) => { }; useEffect(() => { if (isLoadingSaveButton) { - if (!shouldHideCaptcha && Config.CAPTCHA_KEY && recaptchaRef.current) { + if ( + !shouldHideCaptcha && Config.CAPTCHA_KEY && recaptchaRef.curren && !isDebugPhoneNumber() + ) { recaptchaRef.current.open(); } else { Mixpanel.setEvent('Submit phone number, without captcha , (Config.CAPTCHA_KEY is not defined)'); From e14d90648f2ec4f53636c4dad94ebf9480c32ab0 Mon Sep 17 00:00:00 2001 From: Ofek Rotem <92383710+ofekrotem@users.noreply.github.com> Date: Mon, 9 Sep 2024 11:52:17 +0300 Subject: [PATCH 2/5] Update examples/client/Locomotion/src/pages/Profile/Phone.js Co-authored-by: Omer Gery <68545675+OmerGery@users.noreply.github.com> --- examples/client/Locomotion/src/pages/Profile/Phone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/client/Locomotion/src/pages/Profile/Phone.js b/examples/client/Locomotion/src/pages/Profile/Phone.js index 3e6b8db2f..b11aace7e 100644 --- a/examples/client/Locomotion/src/pages/Profile/Phone.js +++ b/examples/client/Locomotion/src/pages/Profile/Phone.js @@ -95,7 +95,7 @@ const Phone = ({ navigation }) => { useEffect(() => { if (isLoadingSaveButton) { if ( - !shouldHideCaptcha && Config.CAPTCHA_KEY && recaptchaRef.curren && !isDebugPhoneNumber() + !shouldHideCaptcha && Config.CAPTCHA_KEY && recaptchaRef.current && !isDebugPhoneNumber() ) { recaptchaRef.current.open(); } else { From 576ed34b64dd41a615046b906632b6c7d41c294a Mon Sep 17 00:00:00 2001 From: Ofek Rotem <92383710+ofekrotem@users.noreply.github.com> Date: Mon, 9 Sep 2024 23:40:51 +0300 Subject: [PATCH 3/5] fetchHideCaptchaSetting --- examples/client/Locomotion/package-lock.json | 12 ++++++------ .../src/context/onboarding/index.tsx | 15 +++++++++++++++ .../Locomotion/src/context/settings/index.js | 4 ++-- .../Locomotion/src/pages/DevPage/index.tsx | 5 ++++- .../Locomotion/src/pages/Profile/Phone.js | 18 ++++-------------- 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/examples/client/Locomotion/package-lock.json b/examples/client/Locomotion/package-lock.json index 6a0534e5e..52350734c 100644 --- a/examples/client/Locomotion/package-lock.json +++ b/examples/client/Locomotion/package-lock.json @@ -7190,7 +7190,7 @@ "decamelize-keys": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/decamelize-keys/-/decamelize-keys-1.1.0.tgz", - "integrity": "sha1-0XGoeTMlKAfrPLYdwcFEXQeN8tk=", + "integrity": "sha512-ocLWuYzRPoS9bfiSdDd3cxvrzovVMZnRDVEzAs+hWIVXGDbHxWMECij2OBuyB/An0FFW/nLuq6Kv1i/YC5Qfzg==", "requires": { "decamelize": "^1.1.0", "map-obj": "^1.0.0" @@ -7199,7 +7199,7 @@ "map-obj": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-1.0.1.tgz", - "integrity": "sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=" + "integrity": "sha512-7N/q3lyZ+LVCp7PzuxrJr4KMbBE2hW7BT7YNia330OFxIf4d3r5zVpicP2650l7CPN6RM9zOJRl3NGpqSiw3Eg==" } } }, @@ -7212,7 +7212,7 @@ "decode-uri-component": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz", - "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=" + "integrity": "sha512-hjf+xovcEn31w/EUYdTXQh/8smFL/dzYjohQGEIgjyNavaJfBY2p5F527Bo1VPATxv0VYTUC2bOcXvqFwk78Og==" }, "dedent": { "version": "0.6.0", @@ -8425,7 +8425,7 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" } } }, @@ -15706,7 +15706,7 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" } } }, @@ -16836,7 +16836,7 @@ "which-module": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", - "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" + "integrity": "sha512-B+enWhmw6cjfVC7kS8Pj9pCrKSc5txArRyaYGe088shv/FGWH+0Rjx/xPgtsWfsUtS27FkP697E4DDhgrgoc0Q==" }, "word-wrap": { "version": "1.2.3", diff --git a/examples/client/Locomotion/src/context/onboarding/index.tsx b/examples/client/Locomotion/src/context/onboarding/index.tsx index 5a8a35795..688c3de4e 100644 --- a/examples/client/Locomotion/src/context/onboarding/index.tsx +++ b/examples/client/Locomotion/src/context/onboarding/index.tsx @@ -16,6 +16,8 @@ interface OnboardingContextInterface { navigateBasedOnUser: (user: any) => void, requiredOnboarding: any, nextScreen: (currentScreen: string) => void, + fetchHideCaptchaSetting: () => void, + shouldHideCaptcha?: boolean, } export const OnboardingContext = createContext({ @@ -23,6 +25,8 @@ export const OnboardingContext = createContext({ navigateBasedOnUser: user => undefined, requiredOnboarding: {}, nextScreen: (currentScreen: string) => undefined, + fetchHideCaptchaSetting: () => undefined, + shouldHideCaptcha: false, }); const SCREEN_ORDER = [ @@ -63,7 +67,16 @@ 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, + ); + console.log('hideCaptchaSetting', hideCaptchaSetting); + setShouldHideCaptcha(hideCaptchaSetting); + }; const navigateToScreen = (screen: string) => navigationService.navigate(screen); const shouldShowCardPage = async () => { @@ -155,6 +168,8 @@ const OnboardingContextProvider = ({ children }: { children: any }) => { navigateBasedOnUser, requiredOnboarding, nextScreen, + fetchHideCaptchaSetting, + shouldHideCaptcha, }} > {children} diff --git a/examples/client/Locomotion/src/context/settings/index.js b/examples/client/Locomotion/src/context/settings/index.js index 0a45ba4d4..22e3ecc2a 100644 --- a/examples/client/Locomotion/src/context/settings/index.js +++ b/examples/client/Locomotion/src/context/settings/index.js @@ -24,9 +24,9 @@ const useSettings = () => { const [showPrice, setShowPrice] = useState(false); - const getSettingByKey = async (key) => { + const getSettingByKey = async (key, fetchSettingAgain = false) => { let value = await StorageService.get(key); - if (value === undefined) { + if (value === undefined || fetchSettingAgain) { ({ value } = await settingsApi.getByKey(key)); await StorageService.save({ [key]: value, diff --git a/examples/client/Locomotion/src/pages/DevPage/index.tsx b/examples/client/Locomotion/src/pages/DevPage/index.tsx index 63d4c08df..d33462011 100644 --- a/examples/client/Locomotion/src/pages/DevPage/index.tsx +++ b/examples/client/Locomotion/src/pages/DevPage/index.tsx @@ -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'; @@ -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 ( { testID="saveButton" onPress={() => { AppSettings.setSettings({ serverUrl, operationId, stripeKey }); + fetchHideCaptchaSetting(); navigationService.goBack(); }} > diff --git a/examples/client/Locomotion/src/pages/Profile/Phone.js b/examples/client/Locomotion/src/pages/Profile/Phone.js index b11aace7e..35130fc57 100644 --- a/examples/client/Locomotion/src/pages/Profile/Phone.js +++ b/examples/client/Locomotion/src/pages/Profile/Phone.js @@ -1,6 +1,6 @@ import React, { useCallback, - useContext, useEffect, useRef, useState, + useContext, useEffect, useMemo, useRef, useState, } from 'react'; import { useIsFocused } from '@react-navigation/native'; import Config from 'react-native-config'; @@ -21,11 +21,10 @@ 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); @@ -33,19 +32,10 @@ const Phone = ({ navigation }) => { 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(); - }, [user?.phoneNumber]); - + }, []); const onVerifyCaptcha = async (verifiedCaptchaToken) => { Mixpanel.setEvent('Captcha Verified successfully', { verifiedCaptchaToken }); From 3a67cc2aedf7523ec7e13dba461dea4b7b27829b Mon Sep 17 00:00:00 2001 From: Ofek Rotem <92383710+ofekrotem@users.noreply.github.com> Date: Tue, 10 Sep 2024 09:58:18 +0300 Subject: [PATCH 4/5] cr @OmerGery --- examples/client/Locomotion/package-lock.json | 14 +++++++------- .../Locomotion/src/context/onboarding/index.tsx | 3 +-- .../Locomotion/src/context/settings/index.js | 4 ++-- .../client/Locomotion/src/pages/DevPage/index.tsx | 6 +++--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/examples/client/Locomotion/package-lock.json b/examples/client/Locomotion/package-lock.json index 52350734c..934f976cb 100644 --- a/examples/client/Locomotion/package-lock.json +++ b/examples/client/Locomotion/package-lock.json @@ -7190,7 +7190,7 @@ "decamelize-keys": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/decamelize-keys/-/decamelize-keys-1.1.0.tgz", - "integrity": "sha512-ocLWuYzRPoS9bfiSdDd3cxvrzovVMZnRDVEzAs+hWIVXGDbHxWMECij2OBuyB/An0FFW/nLuq6Kv1i/YC5Qfzg==", + "integrity": "sha1-0XGoeTMlKAfrPLYdwcFEXQeN8tk=", "requires": { "decamelize": "^1.1.0", "map-obj": "^1.0.0" @@ -7199,7 +7199,7 @@ "map-obj": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-1.0.1.tgz", - "integrity": "sha512-7N/q3lyZ+LVCp7PzuxrJr4KMbBE2hW7BT7YNia330OFxIf4d3r5zVpicP2650l7CPN6RM9zOJRl3NGpqSiw3Eg==" + "integrity": "sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=" } } }, @@ -7212,7 +7212,7 @@ "decode-uri-component": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz", - "integrity": "sha512-hjf+xovcEn31w/EUYdTXQh/8smFL/dzYjohQGEIgjyNavaJfBY2p5F527Bo1VPATxv0VYTUC2bOcXvqFwk78Og==" + "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=" }, "dedent": { "version": "0.6.0", @@ -8425,7 +8425,7 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" } } }, @@ -15706,7 +15706,7 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" } } }, @@ -16836,7 +16836,7 @@ "which-module": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", - "integrity": "sha512-B+enWhmw6cjfVC7kS8Pj9pCrKSc5txArRyaYGe088shv/FGWH+0Rjx/xPgtsWfsUtS27FkP697E4DDhgrgoc0Q==" + "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" }, "word-wrap": { "version": "1.2.3", @@ -17030,4 +17030,4 @@ } } } -} +} \ No newline at end of file diff --git a/examples/client/Locomotion/src/context/onboarding/index.tsx b/examples/client/Locomotion/src/context/onboarding/index.tsx index 688c3de4e..916ba25f2 100644 --- a/examples/client/Locomotion/src/context/onboarding/index.tsx +++ b/examples/client/Locomotion/src/context/onboarding/index.tsx @@ -25,7 +25,7 @@ export const OnboardingContext = createContext({ navigateBasedOnUser: user => undefined, requiredOnboarding: {}, nextScreen: (currentScreen: string) => undefined, - fetchHideCaptchaSetting: () => undefined, + fetchHideCaptchaSetting: async () => undefined, shouldHideCaptcha: false, }); @@ -73,7 +73,6 @@ const OnboardingContextProvider = ({ children }: { children: any }) => { SETTINGS_KEYS.DISABLE_CAPTCHA_UI, true, ); - console.log('hideCaptchaSetting', hideCaptchaSetting); setShouldHideCaptcha(hideCaptchaSetting); }; diff --git a/examples/client/Locomotion/src/context/settings/index.js b/examples/client/Locomotion/src/context/settings/index.js index 22e3ecc2a..a132e0b82 100644 --- a/examples/client/Locomotion/src/context/settings/index.js +++ b/examples/client/Locomotion/src/context/settings/index.js @@ -24,9 +24,9 @@ const useSettings = () => { const [showPrice, setShowPrice] = useState(false); - const getSettingByKey = async (key, fetchSettingAgain = false) => { + const getSettingByKey = async (key, invalidateCache = false) => { let value = await StorageService.get(key); - if (value === undefined || fetchSettingAgain) { + if (value === undefined || invalidateCache) { ({ value } = await settingsApi.getByKey(key)); await StorageService.save({ [key]: value, diff --git a/examples/client/Locomotion/src/pages/DevPage/index.tsx b/examples/client/Locomotion/src/pages/DevPage/index.tsx index d33462011..ef9e2cea4 100644 --- a/examples/client/Locomotion/src/pages/DevPage/index.tsx +++ b/examples/client/Locomotion/src/pages/DevPage/index.tsx @@ -55,9 +55,9 @@ const DevSettingPage = () => { /> { - AppSettings.setSettings({ serverUrl, operationId, stripeKey }); - fetchHideCaptchaSetting(); + onPress={async () => { + await AppSettings.setSettings({ serverUrl, operationId, stripeKey }); + await fetchHideCaptchaSetting(); navigationService.goBack(); }} > From a98aa00c743630ed9ceecfdf0b57449742658332 Mon Sep 17 00:00:00 2001 From: Ofek Rotem <92383710+ofekrotem@users.noreply.github.com> Date: Tue, 10 Sep 2024 15:03:29 +0300 Subject: [PATCH 5/5] Update Phone.js --- examples/client/Locomotion/src/pages/Profile/Phone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/client/Locomotion/src/pages/Profile/Phone.js b/examples/client/Locomotion/src/pages/Profile/Phone.js index 35130fc57..32046e0f8 100644 --- a/examples/client/Locomotion/src/pages/Profile/Phone.js +++ b/examples/client/Locomotion/src/pages/Profile/Phone.js @@ -1,6 +1,6 @@ import React, { useCallback, - useContext, useEffect, useMemo, useRef, useState, + useContext, useEffect, useRef, useState, } from 'react'; import { useIsFocused } from '@react-navigation/native'; import Config from 'react-native-config';