added setting check
This commit is contained in:
@@ -22,6 +22,8 @@ interface SettingsResponse {
|
||||
minAmount?: number;
|
||||
maxAmount?: number;
|
||||
qrTTL?: number;
|
||||
defaultAmount?: number;
|
||||
enableAmount?: boolean;
|
||||
}
|
||||
|
||||
interface CreateQrResponse {
|
||||
@@ -58,6 +60,7 @@ export class CreatePage {
|
||||
maxAmount = signal<number>(200_000);
|
||||
|
||||
amount = signal<number | null>(null);
|
||||
private lockedAmount = signal<number | null>(null);
|
||||
note = signal<string>('');
|
||||
error = signal<string>('');
|
||||
loading = signal<boolean>(false);
|
||||
@@ -109,17 +112,26 @@ export class CreatePage {
|
||||
|
||||
private loadSettings(): void {
|
||||
// Fetch limits from /qr/settings. If the call fails, keep defaults.
|
||||
const url = `${QR_VITANOVA_API}/qr/settings`;
|
||||
const partnerqrID = this.partnerqrID;
|
||||
const url = `${QR_VITANOVA_API}/qr/settings${partnerqrID ? `?id=${encodeURIComponent(partnerqrID)}` : ''}`;
|
||||
this.http.get<SettingsResponse>(url).subscribe({
|
||||
next: (s) => {
|
||||
if (typeof s?.minAmount === 'number') this.minAmount.set(s.minAmount);
|
||||
if (typeof s?.maxAmount === 'number') this.maxAmount.set(s.maxAmount);
|
||||
|
||||
const defaultAmount = typeof s?.defaultAmount === 'number' ? s.defaultAmount : 0;
|
||||
if (s?.enableAmount === true && defaultAmount > 0) {
|
||||
this.lockedAmount.set(defaultAmount);
|
||||
this.amount.set(defaultAmount);
|
||||
} else {
|
||||
this.lockedAmount.set(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
createCheck(): void {
|
||||
const val = this.amount();
|
||||
const val = this.lockedAmount() ?? this.amount();
|
||||
if (val !== null && val < this.minAmount()) {
|
||||
this.error.set(`${this.t('errors.invalid_amount')} (мин. ${this.minAmount()} ₽)`);
|
||||
return;
|
||||
@@ -223,10 +235,19 @@ export class CreatePage {
|
||||
}
|
||||
|
||||
onAmountChange(value: number | null): void {
|
||||
if (this.lockedAmount() !== null) {
|
||||
this.amount.set(this.lockedAmount());
|
||||
return;
|
||||
}
|
||||
|
||||
this.amount.set(value || null);
|
||||
if (value && value > 0) this.error.set('');
|
||||
}
|
||||
|
||||
isAmountLocked(): boolean {
|
||||
return this.lockedAmount() !== null;
|
||||
}
|
||||
|
||||
onNoteChange(value: string): void {
|
||||
this.note.set(value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user