From 8fea618b18b413cf932007bb20d201b2ea5711eb Mon Sep 17 00:00:00 2001 From: adonis Date: Wed, 17 Jun 2026 16:05:07 +0330 Subject: [PATCH] fix fallback base on show product --- src/utils/config.ts | 50 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/utils/config.ts b/src/utils/config.ts index 225ac4d..d371e54 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -12,6 +12,8 @@ import bazretalaNavLogo from '@/assets/img/bazretala-nav-logo.png' import bazretalaFundBg from '@/assets/img/bazretala-fund-bg.png' import bazretalaEmptyFund from '@/assets/img/bazretala-empty-fund.png' +import { useSettingsStore } from '@/store/settingsStore' + export function getConfigApp(key: string) { const config = window.__APP_CONFIG__ ? window.__APP_CONFIG__.user:{} @@ -244,6 +246,41 @@ export function getReferralShareTitle(projectName?: string | null) { return projectName ?? getConfigApp('name_fa') ?? getConfigApp('name') ?? 'طلا' } +/** جایگزینی ٪نام / %نام و ٪لینک / %لینک در قالب متن دعوت */ +export function renderInviteLinkText( + template: string, + options: { userName?: string | null; link?: string | null }, +): string { + const userName = String(options.userName ?? '').trim() + const link = String(options.link ?? '').trim() + + return template + .replace(/[%٪]\s*لینک/gu, link) + .replace(/[%٪]\s*نام/gu, userName) +} + +function resolveReferralLoginLink(referralId?: string | number | null): string { + const id = String(referralId ?? '').trim() + if (!id) return '' + + let base = '' + try { + base = String(useSettingsStore().getSettingByKey('app_url') ?? '').trim() + } catch { + base = '' + } + + if (base) { + return `${base.replace(/\/+$/, '')}/login?id=${encodeURIComponent(id)}` + } + + if (typeof window !== 'undefined' && window.location?.origin) { + return `${window.location.origin}/login?id=${encodeURIComponent(id)}` + } + + return `/login?id=${encodeURIComponent(id)}` +} + export function getReferralShareText(options: { userName?: string | null projectName?: string | null @@ -251,11 +288,22 @@ export function getReferralShareText(options: { }) { const userName = options.userName ?? '' const referralId = options.referralId ?? '' - const link = `${window.location.hostname}/login?id=${referralId}` + const link = resolveReferralLoginLink(referralId) const marketText = options.projectName ? `بازار طلای ${options.projectName}` : 'بازار طلا' + let template = '' + try { + template = String(useSettingsStore().getSettingByKey('invite_link_text') ?? '').trim() + } catch { + template = '' + } + + if (template) { + return renderInviteLinkText(template, { userName, link }) + } + if (isBoursecuProject()) { return `مس؛ فلز آینده جهان