encrypt / decrypt logic isolate
This commit is contained in:
@@ -32,7 +32,11 @@ import {
|
||||
} from "../../actions/eventActions";
|
||||
import { sendLogShopByMobile } from "../../actions/logActions";
|
||||
import { ACTIVE_POPUP, LOG_TP_NO } from "../../utils/Config";
|
||||
import { $L } from "../../utils/helperMethods";
|
||||
import {
|
||||
$L,
|
||||
decryptPhoneNumber,
|
||||
encryptPhoneNumber,
|
||||
} from "../../utils/helperMethods";
|
||||
import CustomImage from "../CustomImage/CustomImage";
|
||||
import TButton from "../TButton/TButton";
|
||||
import TPopUp from "../TPopUp/TPopUp";
|
||||
@@ -225,10 +229,6 @@ export default function MobileSendPopUp({
|
||||
}
|
||||
}, [deviceInfo, dispatch]);
|
||||
|
||||
useEffect(() => {
|
||||
if (phoneNumberList) setRecentSentNumber(phoneNumberList);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!chkAgreeBtn) {
|
||||
if (recentSentNumber && recentSentNumber.length > 0) {
|
||||
@@ -260,10 +260,13 @@ export default function MobileSendPopUp({
|
||||
(_, index) => index !== selectedIndex
|
||||
);
|
||||
setRecentSentNumber(updateItems);
|
||||
|
||||
const encryptedNumbers = updateItems.map(encryptPhoneNumber);
|
||||
|
||||
dispatch(
|
||||
changeLocalSettings({
|
||||
phoneNumbers: {
|
||||
phoneNumberList: updateItems,
|
||||
phoneNumberList: encryptedNumbers,
|
||||
},
|
||||
})
|
||||
);
|
||||
@@ -282,13 +285,6 @@ export default function MobileSendPopUp({
|
||||
naturalNumber = "82" + naturalNumber;
|
||||
}
|
||||
|
||||
const encryptPhoneNumber = (phoneNumber) => {
|
||||
if(typeof window === 'object'){
|
||||
return window.CryptoJS.AES.encrypt(phoneNumber, SECRET_KEY).toString();
|
||||
}
|
||||
return phoneNumber;
|
||||
};
|
||||
|
||||
if (recentSentNumber && recentSentNumber.length > 0) {
|
||||
const updatedNumbers = [...recentSentNumber];
|
||||
|
||||
@@ -518,18 +514,10 @@ export default function MobileSendPopUp({
|
||||
|
||||
useEffect(() => {
|
||||
if (phoneNumberList) {
|
||||
const decryptPhoneNumber = (encryptedPhoneNumber) => {
|
||||
if(typeof window === 'object'){
|
||||
const bytes = window.CryptoJS.AES.decrypt(encryptedPhoneNumber, SECRET_KEY);
|
||||
return bytes.toString(window.CryptoJS.enc.Utf8);
|
||||
}
|
||||
return encryptedPhoneNumber;
|
||||
};
|
||||
|
||||
const decryptedNumbers = phoneNumberList.map(decryptPhoneNumber);
|
||||
setRecentSentNumber(decryptedNumbers);
|
||||
}
|
||||
}, []);
|
||||
}, [phoneNumberList]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user