This commit is contained in:
zadit
2025-02-21 07:17:46 +07:00
parent f1247dd11c
commit 43ad59a1f8
5 changed files with 47 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
// src/config.js
const API_BASE_URL = 'https://dev.api.kedaimaster.com';
const API_BASE_URL = 'https://api.kedaimaster.com';
export default API_BASE_URL;

View File

@@ -5,6 +5,11 @@ import App from './App';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root'));
// Disable console methods
console.log = () => {};
console.warn = () => {};
console.error = () => {};
root.render(
<React.StrictMode>
<App />

View File

@@ -26,31 +26,32 @@ const CreateCouponPage = () => {
const [codeExpectation, setCodeExpectation] = useState('');
const [couponUrl, setCouponUrl] = useState('');
const handleSubmit = async (e) => {
e.preventDefault();
setLoading(true);
// Call the helper function to create the coupon
const result = await createCoupon(discountType, discountValue, discountPeriods, codeExpectation);
if (result.success) {
setCouponDetails(result.coupon);
const secretKey = 'xixixi666'; // AES-256 key (32 characters)
// Encrypt the coupon code inline
const encryptedCouponCode = CryptoJS.AES.encrypt(result.coupon.code, secretKey).toString();
// Convert the encrypted code to Base64 URL-safe encoding
const base64UrlSafe = encryptedCouponCode.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
// Store the Base64 URL-safe encrypted coupon code in the query parameter
const encodedCouponCode = encodeURIComponent(base64UrlSafe); // Ensure it's safely encoded for URL use
const urlWithCoupon = `https://dev.coupon.kedaimaster.com/coupon?c=${encodedCouponCode}`;
// Encrypt the coupon code inline using CryptoJS
let encryptedCouponCode = CryptoJS.AES.encrypt(result.coupon.code, secretKey).toString().replace('+','LDNWAlASJDNdaw').replace('/','XCLZBKlaWDJ').replace('=','LDSsadANJlas');
// Encode the encrypted coupon code for URL usage:
// 1. First, encodeURIComponent to handle URL-specific characters.
// 2. Then, replace special characters like '+' and '/' that might cause issues.
let encodedCouponCode = encodeURIComponent(encryptedCouponCode);
// Construct the URL with the encoded coupon code as a query parameter
const urlWithCoupon = `https://coupon.kedaimaster.com/coupon?c=${encodedCouponCode}`;
// Optionally, set the URL to use with the coupon
setCouponUrl(urlWithCoupon);
console.log(urlWithCoupon);
console.log("Generated URL with Encrypted Coupon Code:", urlWithCoupon);
setLoading(false);
} else {
setLoading(false);
@@ -58,6 +59,8 @@ const CreateCouponPage = () => {
};
return (
<div className={styles.linktreePage}>

View File

@@ -18,20 +18,18 @@ const LinktreePage = ({ data, setModal }) => {
const [couponStatus, setCouponStatus] = useState(0);
const [couponDetails, setCouponDetails] = useState(null);
// Detect query params on component mount
useEffect(() => {
if (couponCode !== '') return; // Prevent repeated code
if (couponCode !== '') return;
const modal = queryParams.get('modal');
const encryptedCode = queryParams.get('c'); // Encrypted coupon code in query
const code = queryParams.get('c');
console.log(encryptedCode);
console.log("Received coupon code:", code);
if (modal === 'claim-coupon') {
if (!getLocalStorage('auth')) {
// Preserve the couponCode query param while navigating to the claim-coupon modal
if (encryptedCode) setModal('join', { c: encryptedCode });
if (code) setModal('join', { c: code });
else setModal('join');
}
@@ -40,26 +38,36 @@ const LinktreePage = ({ data, setModal }) => {
} else {
if (getLocalStorage('auth')) {
// Preserve the couponCode query param while navigating to the claim-coupon modal
if (encryptedCode) setModal('claim-coupon', { c: encryptedCode });
if (code) setModal('claim-coupon', { c: code });
else setModal('claim-coupon');
}
}
if (encryptedCode) {
// AES-256 key (ensure this is kept secret and secure!)
if (code) {
// URL decode the coupon code (it might be URL-encoded)
let decodedCode = code.replace('LDNWAlASJDNdaw','+').replace('XCLZBKlaWDJ','/').replace('LDSsadANJlas','=');
// Your AES-256 key (ensure this is kept secret and secure!)
const secretKey = 'xixixi666'; // 32 characters for AES-256
// Decode and decrypt the coupon code
const decodedCouponCode = decodeURIComponent(encryptedCode); // Decode the encrypted code from the URL
const decryptedBytes = CryptoJS.AES.decrypt(decodedCouponCode, secretKey);
// Decrypt the coupon code
const decryptedBytes = CryptoJS.AES.decrypt(decodedCode, secretKey);
const decryptedCode = decryptedBytes.toString(CryptoJS.enc.Utf8);
console.log(decryptedCode);
setCouponCode(decryptedCode);
setIsUsingCoupon(true); // Automatically switch to the coupon input state
handleCheckCoupon(decryptedCode); // Automatically check the coupon code
console.log("Decrypted Code:", decryptedCode);
if (decryptedCode) {
setCouponCode(decryptedCode);
setIsUsingCoupon(true); // Automatically switch to the coupon input state
handleCheckCoupon(decryptedCode); // Automatically check the coupon code
} else {
console.log("Failed to decrypt the coupon code");
}
}
}, [queryParams]);
}, [queryParams]);
// Handle manual coupon code check
const handleCheckCoupon = async (code = couponCode) => {
const result = await checkCoupon(code); // Call the helper