From 58ca9d4423f448504bdb0c275b9af8209b71591e Mon Sep 17 00:00:00 2001 From: wilfred Date: Wed, 31 Jan 2024 16:01:31 +0700 Subject: [PATCH] hotfix remove recaptcha --- .../PublicSale/AuthForBuy/btnCreateGuest.tsx | 41 ++++++++++++------ .../PublicSale/AuthForBuy/importOrCreate.tsx | 43 +++++++++++++------ .../depositModal/deposit.content.tsx | 37 +++++++++------- src/services/public-sale.ts | 4 +- 4 files changed, 79 insertions(+), 46 deletions(-) diff --git a/src/modules/PublicSale/AuthForBuy/btnCreateGuest.tsx b/src/modules/PublicSale/AuthForBuy/btnCreateGuest.tsx index 720155ee6..a31cfd984 100644 --- a/src/modules/PublicSale/AuthForBuy/btnCreateGuest.tsx +++ b/src/modules/PublicSale/AuthForBuy/btnCreateGuest.tsx @@ -1,6 +1,6 @@ import SvgInset from '@/components/SvgInset'; import { Button, Center, Spinner, Text } from '@chakra-ui/react'; -import React, { useCallback, useState } from 'react'; +import React, { useCallback, useMemo, useState } from 'react'; import s from './styles.module.scss'; import { useGoogleReCaptcha } from 'react-google-recaptcha-v3'; import { generateRandomString } from '@/utils/encryption'; @@ -9,28 +9,41 @@ import AuthenStorage from '@/utils/storage/authen.storage'; import { setGuestSecretCode } from '@/stores/states/user/reducer'; import { useDispatch } from 'react-redux'; import cs from 'classnames'; +import { userSelector } from '@/stores/states/user/selector'; +import { useAppSelector } from '@/stores/hooks'; const BtnCreateGuest = () => { const dispatch = useDispatch(); const { executeRecaptcha } = useGoogleReCaptcha(); const [loading, setLoading] = useState(false); - const createNewSecretCode = useCallback(() => { + const user = useAppSelector(userSelector); + const isAuth = useMemo(() => user?.guest_code || user?.twitter_id, [user]); + // const createNewSecretCode = useCallback(() => { + // try { + // if (!executeRecaptcha) { + // console.log('Execute recaptcha not yet available'); + // throw Error('Execute recaptcha not yet available'); + // } + // executeRecaptcha('enquiryFormSubmit').then((gReCaptchaToken) => { + // console.log(gReCaptchaToken, 'response Google reCaptcha server'); + // getToken(gReCaptchaToken); + // }); + // } catch (error) { + // // + // } + // }, [executeRecaptcha]); + + const createNewSecretCode = async () => { try { - if (!executeRecaptcha) { - console.log('Execute recaptcha not yet available'); - throw Error('Execute recaptcha not yet available'); - } - executeRecaptcha('enquiryFormSubmit').then((gReCaptchaToken) => { - console.log(gReCaptchaToken, 'response Google reCaptcha server'); - getToken(gReCaptchaToken); - }); - } catch (error) { - // - } - }, [executeRecaptcha]); + await getToken('gReCaptchaToken'); + } catch (error) {} + }; const getToken = async (captcha: string, code?: string) => { try { + if (isAuth) { + return; + } setLoading(true); const _secretCode = generateRandomString(10); diff --git a/src/modules/PublicSale/AuthForBuy/importOrCreate.tsx b/src/modules/PublicSale/AuthForBuy/importOrCreate.tsx index 449fe24d9..283f53f16 100644 --- a/src/modules/PublicSale/AuthForBuy/importOrCreate.tsx +++ b/src/modules/PublicSale/AuthForBuy/importOrCreate.tsx @@ -12,21 +12,27 @@ import { Text, Box, } from '@chakra-ui/react'; -import React, { useCallback, useState } from 'react'; +import React, { useCallback, useMemo, useState } from 'react'; import { useGoogleReCaptcha } from 'react-google-recaptcha-v3'; import { useDispatch } from 'react-redux'; import s from './styles.module.scss'; +import { userSelector } from '@/stores/states/user/selector'; +import { useAppSelector } from '@/stores/hooks'; const ImportOrCreate = ({ onBack }: { onBack?: any }) => { const dispatch = useDispatch(); const getSecretCode = AuthenStorage.getGuestSecretKey(); + const user = useAppSelector(userSelector); + const [loading, setLoading] = useState(false); const [secretCode, setSecretCode] = useState(getSecretCode); const [isImport, setIsImport] = useState(false); const [importSecretKeyText, setImportSecretKeyText] = useState(''); const [secretKeyError, setSecretKeyError] = useState(''); + const isAuth = useMemo(() => user?.guest_code || user?.twitter_id, [user]); + const validatePassword = (password: string) => { // Regular expression to validate password const regex = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{10,}$/; @@ -37,6 +43,9 @@ const ImportOrCreate = ({ onBack }: { onBack?: any }) => { const getToken = async (captcha: string, code?: string) => { try { + if (isAuth) { + return; + } setLoading(true); const _secretCode = code || generateRandomString(10); @@ -51,20 +60,26 @@ const ImportOrCreate = ({ onBack }: { onBack?: any }) => { } }; - const createNewSecretCode = useCallback(() => { + // const createNewSecretCode = useCallback(() => { + // try { + // if (!executeRecaptcha) { + // console.log('Execute recaptcha not yet available'); + // throw Error('Execute recaptcha not yet available'); + // } + // executeRecaptcha('enquiryFormSubmit').then((gReCaptchaToken) => { + // console.log(gReCaptchaToken, 'response Google reCaptcha server'); + // getToken(gReCaptchaToken); + // }); + // } catch (error) { + // // + // } + // }, [executeRecaptcha]); + + const createNewSecretCode = async () => { try { - if (!executeRecaptcha) { - console.log('Execute recaptcha not yet available'); - throw Error('Execute recaptcha not yet available'); - } - executeRecaptcha('enquiryFormSubmit').then((gReCaptchaToken) => { - console.log(gReCaptchaToken, 'response Google reCaptcha server'); - getToken(gReCaptchaToken); - }); - } catch (error) { - // - } - }, [executeRecaptcha]); + await getToken('gReCaptchaToken'); + } catch (error) {} + }; const onImportSecretCode = useCallback( (code: string) => { diff --git a/src/modules/PublicSale/depositModal/deposit.content.tsx b/src/modules/PublicSale/depositModal/deposit.content.tsx index bf5919b6f..25cd389a7 100644 --- a/src/modules/PublicSale/depositModal/deposit.content.tsx +++ b/src/modules/PublicSale/depositModal/deposit.content.tsx @@ -72,21 +72,22 @@ const DepositContent: React.FC = ({ const isAuth = useMemo(() => user?.guest_code || user?.twitter_id, [user]); - const createNewSecretCode = () => { + const createNewSecretCode = async () => { try { - if (isAuth) { - setGenerating(false); - return; - } - if (!executeRecaptcha) { - console.log('Execute recaptcha not yet available'); - throw Error('Execute recaptcha not yet available'); - } - executeRecaptcha('enquiryFormSubmit').then((gReCaptchaToken) => { - console.log(gReCaptchaToken, 'response Google reCaptcha server'); + await getToken(''); + // if (isAuth) { + // setGenerating(false); + // return; + // } + // if (!executeRecaptcha) { + // console.log('Execute recaptcha not yet available'); + // throw Error('Execute recaptcha not yet available'); + // } + // executeRecaptcha('enquiryFormSubmit').then((gReCaptchaToken) => { + // console.log(gReCaptchaToken, 'response Google reCaptcha server'); - getToken(gReCaptchaToken); - }); + // getToken(gReCaptchaToken); + // }); } catch (error) { // } @@ -94,6 +95,9 @@ const DepositContent: React.FC = ({ const getToken = async (captcha: string, code?: string) => { try { + if (isAuth) { + return; + } const _secretCode = generateRandomString(10); const rs = await generateTOkenWithSecretCode(_secretCode, captcha); @@ -185,9 +189,10 @@ const DepositContent: React.FC = ({ return ( - Make a contribution using any of the currencies below.
After your - payment processes, you’ll get a confirmation code to claim your $BVM - allocation later. + Make a contribution using any of the currencies below. +
+ After your payment processes, you’ll get a confirmation code to claim + your $BVM allocation later.
{/* {secretCode && ( <> diff --git a/src/services/public-sale.ts b/src/services/public-sale.ts index 9ba0b93c5..c405b1193 100644 --- a/src/services/public-sale.ts +++ b/src/services/public-sale.ts @@ -40,14 +40,14 @@ export const postPublicsaleWalletInfoManualCheck = export const generateTOkenWithSecretCode = async ( secret_code: string, - recaptcha: string, + _recaptcha: string, ): Promise => { const res = (await apiClient.post( `/bvm/generate-token-with-secret-code`, { secret_code }, { headers: { - recaptcha, + // recaptcha, 'user-data': JSON.stringify({ screen: window?.location?.pathname, timezone: new Date().toString(),