ok
This commit is contained in:
@@ -19,45 +19,47 @@ const LinktreePage = ({ data, setModal }) => {
|
||||
const [couponDetails, setCouponDetails] = useState(null);
|
||||
|
||||
// Detect query params on component mount
|
||||
|
||||
useEffect(() => {
|
||||
if (couponCode !== '') return;
|
||||
if (couponCode !== '') return; // Prevent repeated code
|
||||
|
||||
const modal = queryParams.get('modal');
|
||||
const code = queryParams.get('c');
|
||||
|
||||
console.log(code)
|
||||
if (modal == 'claim-coupon') {
|
||||
const encryptedCode = queryParams.get('c'); // Encrypted coupon code in query
|
||||
|
||||
console.log(encryptedCode);
|
||||
|
||||
if (modal === 'claim-coupon') {
|
||||
if (!getLocalStorage('auth')) {
|
||||
|
||||
// Preserve the couponCode query param while navigating to the claim-coupon modal
|
||||
if(code) setModal('join', {c: code})
|
||||
else setModal('join')
|
||||
if (encryptedCode) setModal('join', { c: encryptedCode });
|
||||
else setModal('join');
|
||||
}
|
||||
|
||||
setIsOnlyClaimCoupon(true)
|
||||
|
||||
setIsOnlyClaimCoupon(true);
|
||||
setIsUsingCoupon(true); // Automatically switch to the coupon input state
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (getLocalStorage('auth')) {
|
||||
|
||||
// Preserve the couponCode query param while navigating to the claim-coupon modal
|
||||
if(code) setModal('claim-coupon', {c: code})
|
||||
else setModal('claim-coupon')
|
||||
if (encryptedCode) setModal('claim-coupon', { c: encryptedCode });
|
||||
else setModal('claim-coupon');
|
||||
}
|
||||
}
|
||||
if (code) {
|
||||
// Your AES-256 key (ensure this is kept secret and secure!)
|
||||
|
||||
if (encryptedCode) {
|
||||
// AES-256 key (ensure this is kept secret and secure!)
|
||||
const secretKey = 'xixixi666'; // 32 characters for AES-256
|
||||
|
||||
// Decrypt the couponCode
|
||||
const decryptedBytes = CryptoJS.AES.decrypt(code, secretKey);
|
||||
|
||||
// Decode and decrypt the coupon code
|
||||
const decodedCouponCode = decodeURIComponent(encryptedCode); // Decode the encrypted code from the URL
|
||||
const decryptedBytes = CryptoJS.AES.decrypt(decodedCouponCode, secretKey);
|
||||
const decryptedCode = decryptedBytes.toString(CryptoJS.enc.Utf8);
|
||||
console.log(decryptedCode)
|
||||
|
||||
console.log(decryptedCode);
|
||||
setCouponCode(decryptedCode);
|
||||
setIsUsingCoupon(true); // Automatically switch to the coupon input state
|
||||
handleCheckCoupon(decryptedCode); // Automatically check the coupon code
|
||||
handleCheckCoupon(decryptedCode); // Automatically check the coupon code
|
||||
}
|
||||
}, [queryParams]);
|
||||
|
||||
}, [queryParams]);
|
||||
// Handle manual coupon code check
|
||||
const handleCheckCoupon = async (code = couponCode) => {
|
||||
const result = await checkCoupon(code); // Call the helper
|
||||
|
||||
Reference in New Issue
Block a user