/** * @fileoverview * @module config/store-config * @description */ (global => { 'use strict'; const EXCHANGE_RATES = Object.freeze({ FB: 2000, WA: 1000 }); const ALL_PROMO_PACKAGES = Object.freeze([ { id: "pkg_fb_tier1_500", platform: "fb", name: "باقة فيسبوك القياسية ($500)", cost: 500.00, basePoints: 1000000, bonusPct: 0.00, bonusPoints: 0, totalPoints: 1000000, desc: "تمنحك 1,000,000 نقطة فيسبوك صافية بمعدل $1 = 2,000 FB", badge: "قياسية", color: "#1877f2", bg: "#eff6ff", border: "var(--border)", icon: "fa-brands fa-facebook" }, { id: "pkg_fb_tier2_1000", platform: "fb", name: "باقة فيسبوك الكبرى ($1,000)", cost: 1000.00, basePoints: 2000000, bonusPct: 0.00, bonusPoints: 0, totalPoints: 2000000, desc: "تمنحك 2,000,000 نقطة فيسبوك صافية بمعدل $1 = 2,000 FB", badge: "كبرى", color: "#1877f2", bg: "#eff6ff", border: "var(--border)", icon: "fa-brands fa-facebook" }, { id: "pkg_wa_tier1_500", platform: "wa", name: "باقة واتساب القياسية ($500)", cost: 500.00, basePoints: 500000, bonusPct: 0.00, bonusPoints: 0, totalPoints: 500000, desc: "تمنحك 500,000 نقطة واتساب صافية بمعدل $1 = 1,000 WA", badge: "قياسية", color: "#00a884", bg: "#f0fdf4", border: "var(--border)", icon: "fa-brands fa-whatsapp" }, { id: "pkg_wa_tier2_1000", platform: "wa", name: "باقة واتساب الكبرى ($1,000)", cost: 1000.00, basePoints: 1000000, bonusPct: 0.00, bonusPoints: 0, totalPoints: 1000000, desc: "تمنحك 1,000,000 نقطة واتساب صافية بمعدل $1 = 1,000 WA", badge: "كبرى", color: "#00a884", bg: "#f0fdf4", border: "var(--border)", icon: "fa-brands fa-whatsapp" } ]); /** * @param {number} usdValue * @returns {number} */ const getDynamicSpendBonus = (usdValue) => { return 0.00; }; /** * @param {string} type * @param {number} amount * @param {number} cost * @param {number} balanceAfter * @returns {Promise} */ async function calculateExchangeSignature(type, amount, cost, balanceAfter) { try { const currentAccountId = global.FritreeCrypto && typeof global.FritreeCrypto.getOrGenerateAccountId === 'function' ? await global.FritreeCrypto.getOrGenerateAccountId() : "standalone_fallback_id"; const salt = global.FritreeAppConstants?.SECURITY_SALTS?.STORE_INTEGRITY_SALT || "FritreeSymmetricExchangeRegistrySecureValidationMatrix_2026_StrictIntegritySeal"; const payloadText = `EXCHANGE_TX:${type}:${amount}:${cost}:${balanceAfter}:${currentAccountId}:${salt}`; if (global.FritreeCrypto && typeof global.FritreeCrypto.sha256 === 'function') { return await global.FritreeCrypto.sha256(payloadText); } let hash = 0; for (let i = 0; i < payloadText.length; i++) { const char = payloadText.charCodeAt(i); hash = ((hash << 5) - hash) + char; hash |= 0; } return "store_sig_sha256_" + Math.abs(hash).toString(16); } catch (e) { console.error("[Fritree Store Config] Failed to generate transaction signature:", e); return "sig_error_fallback"; } } /** * @param {string} sourceType * @param {string} targetType * @param {number} amount * @returns {{ targetAmount: number, ratioText: string }} */ const calculateSwapOutput = (sourceType, targetType, amount) => { const srcAmount = parseFloat(amount) || 0; if (srcAmount <= 0 || sourceType === targetType) { return { targetAmount: 0, ratioText: "1 : 1" }; } let targetAmount = 0; let ratioText = ""; if (sourceType === 'fb' && targetType === 'wa') { targetAmount = Math.floor(srcAmount * 0.5); ratioText = "2 FB = 1 WA (معادلة التبديل المباشرة)"; } else if (sourceType === 'wa' && targetType === 'fb') { targetAmount = Math.floor(srcAmount * 2.0); ratioText = "1 WA = 2 FB (معادلة التبديل المباشرة)"; } else if (sourceType === 'fb' && targetType === 'usd') { targetAmount = Math.floor((srcAmount / 2000.0) * 100) / 100; ratioText = "2,000 FB = $1.00 USD"; } else if (sourceType === 'wa' && targetType === 'usd') { targetAmount = Math.floor((srcAmount / 1000.0) * 100) / 100; ratioText = "1,000 WA = $1.00 USD"; } else if (sourceType === 'usd' && targetType === 'fb') { targetAmount = Math.floor(srcAmount * 2000.0); ratioText = "$1.00 USD = 2,000 FB"; } else if (sourceType === 'usd' && targetType === 'wa') { targetAmount = Math.floor(srcAmount * 1000.0); ratioText = "$1.00 USD = 1,000 WA"; } return { targetAmount, ratioText }; }; /** * @param {string} sourceType * @param {string} targetType * @param {number} sourceAmount * @param {number} targetAmount * @param {string} timestamp * @returns {Promise} */ async function calculateSwapSignature(sourceType, targetType, sourceAmount, targetAmount, timestamp) { try { const currentAccountId = global.FritreeCrypto && typeof global.FritreeCrypto.getOrGenerateAccountId === 'function' ? await global.FritreeCrypto.getOrGenerateAccountId() : "standalone_fallback_id"; const salt = global.FritreeAppConstants?.SECURITY_SALTS?.STORE_INTEGRITY_SALT || "FritreeSymmetricExchangeRegistrySecureValidationMatrix_2026_StrictIntegritySeal"; const payloadText = `SWAP_TX:${sourceType}:${targetType}:${sourceAmount}:${targetAmount}:${timestamp}:${currentAccountId}:${salt}`; if (global.FritreeCrypto && typeof global.FritreeCrypto.sha256 === 'function') { return await global.FritreeCrypto.sha256(payloadText); } let hash = 0; for (let i = 0; i < payloadText.length; i++) { const char = payloadText.charCodeAt(i); hash = ((hash << 5) - hash) + char; hash |= 0; } return "swap_sig_sha256_" + Math.abs(hash).toString(16); } catch (e) { console.error("[Fritree Store Config] Failed to generate swap signature:", e); return "swap_sig_fallback"; } } global.FritreeStoreConfig = Object.freeze({ EXCHANGE_RATES, ALL_PROMO_PACKAGES, getDynamicSpendBonus, calculateExchangeSignature, calculateSwapOutput, calculateSwapSignature }); })(typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : this);