Files
boursecu_admin/src/utils/config.ts
T

60 lines
2.0 KiB
TypeScript
Raw Normal View History

2026-01-24 17:45:54 +03:30
export function getConfigApp(key: string) {
2026-06-12 20:30:00 +03:30
const config = window.__APP_CONFIG__ ? window.__APP_CONFIG__.user : {}
2026-01-24 17:45:54 +03:30
if (config) {
return config[key]
}
return null
}
2026-06-11 22:29:28 +03:30
2026-06-12 20:30:00 +03:30
let storeModeFromSettings: boolean | null = null
2026-06-15 15:48:10 +03:30
let settingsBootstrapped = false
2026-06-12 20:30:00 +03:30
function isSwitchOn(value: string | undefined | null): boolean {
const v = (value ?? '').trim().toLowerCase()
return v === 'true' || v === '1' || v === 'yes'
}
export function setStoreModeFromSettings(value: boolean): void {
storeModeFromSettings = value
}
2026-06-15 15:48:10 +03:30
async function bootstrapSettingsFromApi(): Promise<void> {
if (settingsBootstrapped) return
2026-06-12 20:30:00 +03:30
try {
const { getConfiguration } = await import('@/api/configuration')
2026-06-15 15:48:10 +03:30
const { parseMainWalletProductIds } = await import('@/components/mobile/utils/wallet')
2026-06-12 20:30:00 +03:30
const rows = await getConfiguration()
2026-06-15 15:48:10 +03:30
const list = Array.isArray(rows) ? rows : []
const isStoreRow = list.find((item) => item.key === 'is_store')
const mainWalletRow = list.find((item) => item.key === 'main_wallet_products')
storeModeFromSettings = isStoreRow ? isSwitchOn(isStoreRow.value) : false
const { setCachedMainWalletProductIds } = await import('@/components/mobile/utils/wallet')
setCachedMainWalletProductIds(parseMainWalletProductIds(mainWalletRow?.value))
2026-06-12 20:30:00 +03:30
} catch {
storeModeFromSettings = false
2026-06-15 15:48:10 +03:30
const { setCachedMainWalletProductIds } = await import('@/components/mobile/utils/wallet')
setCachedMainWalletProductIds([])
} finally {
settingsBootstrapped = true
2026-06-12 20:30:00 +03:30
}
2026-06-15 15:48:10 +03:30
}
2026-06-12 20:30:00 +03:30
2026-06-15 15:48:10 +03:30
/** is_store و main_wallet_products از API تنظیمات — نه از get_user */
export async function initStoreModeFromSettings(): Promise<boolean> {
if (storeModeFromSettings !== null) return storeModeFromSettings
await bootstrapSettingsFromApi()
return storeModeFromSettings === true
}
export async function initWalletSettingsFromApi(): Promise<void> {
await bootstrapSettingsFromApi()
2026-06-12 20:30:00 +03:30
}
2026-06-11 22:29:28 +03:30
export function isStoreApp(): boolean {
2026-06-12 20:30:00 +03:30
return storeModeFromSettings === true
2026-06-11 22:29:28 +03:30
}