Skip to content

Commit

Permalink
hotfix remove recaptcha
Browse files Browse the repository at this point in the history
  • Loading branch information
wilfred committed Jan 31, 2024
1 parent 375980e commit 58ca9d4
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 46 deletions.
41 changes: 27 additions & 14 deletions src/modules/PublicSale/AuthForBuy/btnCreateGuest.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);

Expand Down
43 changes: 29 additions & 14 deletions src/modules/PublicSale/AuthForBuy/importOrCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,}$/;
Expand All @@ -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);

Expand All @@ -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) => {
Expand Down
37 changes: 21 additions & 16 deletions src/modules/PublicSale/depositModal/deposit.content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,32 @@ const DepositContent: React.FC<IDepositContent> = ({

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) {
//
}
};

const getToken = async (captcha: string, code?: string) => {
try {
if (isAuth) {
return;
}
const _secretCode = generateRandomString(10);

const rs = await generateTOkenWithSecretCode(_secretCode, captcha);
Expand Down Expand Up @@ -185,9 +189,10 @@ const DepositContent: React.FC<IDepositContent> = ({
return (
<Flex className={s.depositContent}>
<Text className={s.descStaked}>
Make a contribution using any of the currencies below.<br/>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.
<br />
After your payment processes, you’ll get a confirmation code to claim
your $BVM allocation later.
</Text>
{/* {secretCode && (
<>
Expand Down
4 changes: 2 additions & 2 deletions src/services/public-sale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export const postPublicsaleWalletInfoManualCheck =

export const generateTOkenWithSecretCode = async (
secret_code: string,
recaptcha: string,
_recaptcha: string,
): Promise<IGenerateTOkenWithSecretCode> => {
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(),
Expand Down

0 comments on commit 58ca9d4

Please sign in to comment.