Skip to content

Commit 77e9f14

Browse files
authored
Merge pull request #1062 from singnet/SM-254_implement-captcha
Sm 254 implement captcha
2 parents 0560cd6 + f3410c0 commit 77e9f14

File tree

10 files changed

+31
-127
lines changed

10 files changed

+31
-127
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"snet-sdk-web": "5.0.4",
5252
"utf8": "^3.0.0",
5353
"validate.js": "^0.13.1",
54+
"waf-captcha-frontend": "0.0.7",
5455
"web3": "^4.11.1"
5556
},
5657
"resolutions": {
@@ -126,4 +127,4 @@
126127
"ts-protoc-gen": "^0.15.0",
127128
"url": "^0.11.4"
128129
}
129-
}
130+
}

src/components/Captcha/WAFScriptLoad.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/components/Captcha/captchaFetchHandler.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/components/Captcha/modal/CaptchaModal.css

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/components/Captcha/modal/CaptchaModal.jsx

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/components/FeedbackFormModal/FeedbackForm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ const FeedbackForm = ({ closeForm, sendFeedbackAPI }) => {
3838
} catch (error) {
3939
setAlert({ type: alertTypes.ERROR, message: error?.message });
4040
} finally {
41+
dispatch(loaderActions.stopAppLoader());
4142
await new Promise((resolve) => setTimeout(resolve, 3000));
4243
resetForm();
4344
setIsRequestHandling(false);
44-
dispatch(loaderActions.stopAppLoader());
4545
closeForm();
4646
}
4747
};

src/components/FeedbackFormModal/index.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
1-
import { Fragment, useEffect, useState } from "react";
1+
import { Fragment, useState } from "react";
22
import OpenFormButton from "./OpenFormButton";
33
import "./styles.css";
44
import FeedbackFormModal from "./FeedbackFormModal";
55
import { sendFeedbackSnetAPI } from "../../config/SupportAPI";
6-
import CaptchaModal from "../Captcha/modal/CaptchaModal";
7-
import { loadCaptchaScript } from "../Captcha/WAFScriptLoad";
86

97
const FeedbackForm = () => {
108
const [isModalVisible, setIsModalVisible] = useState(false);
119

12-
useEffect(() => {
13-
try {
14-
loadCaptchaScript();
15-
} catch (err) {
16-
console.error("CAPTCHA script error: ", err);
17-
}
18-
}, []);
19-
2010
return (
2111
<Fragment>
22-
<CaptchaModal />
12+
<div id="captchaContainer" />
2313
<FeedbackFormModal
2414
sendFeedbackAPI={sendFeedbackSnetAPI}
2515
isModalVisible={isModalVisible}

src/components/ServiceDetails/AboutService/ServiceDemo/Purchase/ExpiredSession/GeneralAccountWallet/PaymentPopup/Purchase/PurchaseAlert.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
1-
import React, { useEffect, useState } from "react";
1+
import React, { useState } from "react";
22
import { withStyles } from "@mui/styles";
33

44
import AlertBox from "../../../../../../../../common/AlertBox";
55
import StyledButton from "../../../../../../../../common/StyledButton";
66
import { useStyles } from "./styles";
77
import { sendFeedbackSnetAPI } from "../../../../../../../../../config/SupportAPI";
88
import FeedbackFormModal from "../../../../../../../../FeedbackFormModal/FeedbackFormModal";
9-
import { loadCaptchaScript } from "../../../../../../../../Captcha/WAFScriptLoad";
109

1110
const PurchaseAlert = ({ classes, alert, handleCancel }) => {
1211
const [isModalVisible, setIsModalVisible] = useState(false);
1312

14-
useEffect(() => {
15-
try {
16-
loadCaptchaScript();
17-
} catch (err) {
18-
console.error("CAPTCHA script error: ", err);
19-
}
20-
}, []);
21-
2213
return (
2314
<div className={classes.purchaseErrorContainer}>
2415
<AlertBox type={alert.type} message={alert.message} />

src/config/SupportAPI.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import axios from "axios";
2-
import { captchaFetch } from "../components/Captcha/captchaFetchHandler";
2+
import { getCaptchaFetch } from "../utility/captchaFetch";
33

44
const source = "MARKETPLACE";
55

6-
export const sendFeedbackSnetAPI = ({ name, email, category, feedback, attachmentUrls }) => {
6+
const captchaFetch = getCaptchaFetch();
7+
8+
export const sendFeedbackSnetAPI = async ({ name, email, category, feedback, attachmentUrls }) => {
79
const options = {
810
method: "POST",
911
headers: {
@@ -27,7 +29,7 @@ export const sendFeedbackSnetAPI = ({ name, email, category, feedback, attachmen
2729
if (!feedbackUrl) {
2830
throw new Error("Cannot start the application! process.env.REACT_APP_FEEDBACK_ENDPOINT is undefined");
2931
}
30-
captchaFetch(feedbackUrl + "/user/message", options);
32+
await captchaFetch(feedbackUrl + "/user/message", options);
3133
};
3234

3335
const ENTER_CODE = "%0D%0A";

src/utility/captchaFetch.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { createCaptchaFetchHandler } from "waf-captcha-frontend";
2+
3+
export const getCaptchaFetch = () => {
4+
const keys = {
5+
JSAPI_URL: process.env.REACT_APP_JSAPI_URL,
6+
CAPTCHA_TOKEN: process.env.REACT_APP_CAPTCHA_TOKEN,
7+
};
8+
9+
if (!keys.CAPTCHA_TOKEN || !keys.JSAPI_URL) {
10+
throw new Error("Tokens undefined");
11+
}
12+
13+
const captchaFetch = createCaptchaFetchHandler({
14+
API_KEY: keys.CAPTCHA_TOKEN,
15+
JSAPI_URL: keys.JSAPI_URL,
16+
captchaContainerId: "captchaContainer",
17+
});
18+
19+
return captchaFetch;
20+
};

0 commit comments

Comments
 (0)