fix(register): hide or require referral from settings like other apps
Also keep exact trade grams from rial and poll colleague wait every 10s. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+52
-6
@@ -25,9 +25,12 @@ export const TRADE_GRAM_STORAGE_DECIMALS = 10
|
||||
/** حداکثر اعشار نمایش به کاربر در اپ */
|
||||
export const TRADE_GRAM_DISPLAY_DECIMALS = 8
|
||||
|
||||
/** اعشار فیلد گرم وقتی از ریال تبدیل میشود (فقط نمایش همان فیلد) */
|
||||
/** اعشار فیلد گرم وقتی از ریال تبدیل میشود (فقط نمایش همان فیلد؛ مقدار دقیق جداست) */
|
||||
export const TRADE_GRAM_INPUT_DECIMALS = 3
|
||||
|
||||
/** حداکثر اعشاری که کاربر میتواند در فیلد گرم تایپ کند */
|
||||
export const TRADE_GRAM_TYPING_DECIMALS = 6
|
||||
|
||||
/** زیر این مقدار (گرم)، معادل گرم در فیلد ورودی نشان داده نمیشود */
|
||||
export const TRADE_GRAM_MIN_DISPLAY_GRAMS = 0.0001
|
||||
|
||||
@@ -65,7 +68,7 @@ export function formatTradeGramInputValue(grams?: number | null): string | undef
|
||||
return value.toFixed(TRADE_GRAM_INPUT_DECIMALS)
|
||||
}
|
||||
|
||||
/** متن اینپوت گرم — فقط نمایش سهرقمی؛ منبع حقیقت همان گرم دقیق است */
|
||||
/** متن اینپوت گرم وقتی مقدار از ریال آمده — فقط نمایش سهرقمی؛ منبع حقیقت همان گرم دقیق است */
|
||||
export function tradeGramInputDisplay(exactGrams?: number | string | null): string {
|
||||
if (exactGrams === undefined || exactGrams === null || exactGrams === '') return ''
|
||||
const n = Number(exactGrams)
|
||||
@@ -73,6 +76,43 @@ export function tradeGramInputDisplay(exactGrams?: number | string | null): stri
|
||||
return formatTradeGramInputValue(n) ?? ''
|
||||
}
|
||||
|
||||
/** متن اینپوت گرم وقتی خود کاربر وزن زده — تا ۶ رقم، بدون پد اجباری */
|
||||
export function tradeGramTypedDisplay(exactGrams?: number | string | null): string {
|
||||
if (exactGrams === undefined || exactGrams === null || exactGrams === '') return ''
|
||||
const n = Number(exactGrams)
|
||||
if (!Number.isFinite(n) || n <= 0) return ''
|
||||
return trimTrailingDecimalZeros(n.toFixed(TRADE_GRAM_TYPING_DECIMALS))
|
||||
}
|
||||
|
||||
export function tradeGramFieldText(
|
||||
exactGrams: number | string | null | undefined,
|
||||
inputLock: TradeInputLock,
|
||||
draft: string | null,
|
||||
): string {
|
||||
if (draft !== null) return draft
|
||||
if (inputLock === 'rial') return tradeGramInputDisplay(exactGrams)
|
||||
return tradeGramTypedDisplay(exactGrams)
|
||||
}
|
||||
|
||||
/** هنگام تایپ در فیلد گرم: حداکثر شش رقم اعشار؛ نقطهٔ انتهایی برای «۱۲.» نگه داشته میشود */
|
||||
export function sanitizeTradeGramTypingText(raw: unknown): string {
|
||||
const text = String(raw ?? '')
|
||||
if (text === '') return ''
|
||||
const firstDot = text.indexOf('.')
|
||||
if (firstDot === -1) return text
|
||||
const intPart = text.slice(0, firstDot)
|
||||
const decRaw = text.slice(firstDot + 1).replace(/\./g, '')
|
||||
if (decRaw === '') return `${intPart}.`
|
||||
return `${intPart}.${decRaw.slice(0, TRADE_GRAM_TYPING_DECIMALS)}`
|
||||
}
|
||||
|
||||
/** متن شروع ویرایش وقتی فیلد از روی ریال پر شده (۱.۰۰۰ → ۱) */
|
||||
export function tradeGramInputEditText(exactGrams?: number | string | null): string {
|
||||
const shown = tradeGramInputDisplay(exactGrams)
|
||||
if (!shown) return ''
|
||||
return shown.replace(/\.?0+$/, '')
|
||||
}
|
||||
|
||||
/** گرم دقیق از درصد کیف — بدون رند نمایشی اینپوت */
|
||||
export function exactGoldFromWalletPercent(balance: number, percent: number): number {
|
||||
if (!(Number(percent) > 0) || !(Number(balance) > 0)) return 0
|
||||
@@ -88,15 +128,21 @@ export function goldFromGramInputDisplay(
|
||||
exactGrams?: number | string | null
|
||||
): number | undefined {
|
||||
if (raw === '' || raw == null) return undefined
|
||||
const text = String(raw).trim()
|
||||
if (text === '') return undefined
|
||||
const typed = Number(text)
|
||||
const text = sanitizeTradeGramTypingText(raw).trim()
|
||||
if (text === '' || text === '.') return undefined
|
||||
const forNumber = text.endsWith('.') ? text.slice(0, -1) : text
|
||||
if (forNumber === '') return undefined
|
||||
const typed = Number(forNumber)
|
||||
if (!Number.isFinite(typed) || typed <= 0) return undefined
|
||||
|
||||
const exact = Number(exactGrams)
|
||||
if (Number.isFinite(exact) && exact > 0) {
|
||||
const shown = formatTradeGramInputValue(exact)
|
||||
if (shown != null && text === shown) {
|
||||
const typedShown = tradeGramTypedDisplay(exact)
|
||||
if (
|
||||
(shown != null && (text === shown || text === shown.replace(/\.?0+$/, ''))) ||
|
||||
text === typedShown
|
||||
) {
|
||||
return normalizeOrderGoldAmount(exact)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user