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

@@ -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