Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -64,6 +64,10 @@ export class FormErrorsService {
|
||||
if (errors['invalidMobile']) {
|
||||
out.push({ key: 'invalidMobile', message: `${label} معتبر نیست.` });
|
||||
}
|
||||
if (errors['invalidUsername']) {
|
||||
const info = errors['invalidUsername'];
|
||||
out.push({ key: 'invalidUsername', message: info.message ?? `${label} معتبر نیست.` });
|
||||
}
|
||||
// fallback: include any other error keys
|
||||
Object.keys(errors).forEach((k) => {
|
||||
if (
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { Maybe } from '../models';
|
||||
import { ToastService } from './toast.service';
|
||||
|
||||
@@ -42,17 +41,22 @@ export class NativeBridgeService {
|
||||
}
|
||||
|
||||
isEnabled(): boolean {
|
||||
if (!this.host) return false;
|
||||
const hostEnabled = this.host?.isEnabled;
|
||||
if (typeof hostEnabled === 'function') {
|
||||
try {
|
||||
return !!hostEnabled();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// @ts-ignore
|
||||
return !!window.NativeBridge;
|
||||
// if (window.NativeBridge) {
|
||||
|
||||
return !!environment.enableNativeBridge && !!this.host;
|
||||
// }
|
||||
// if (!this.host) return false;
|
||||
// const hostEnabled = this.host?.isEnabled;
|
||||
// if (typeof hostEnabled === 'function') {
|
||||
// try {
|
||||
// return !!hostEnabled();
|
||||
// } catch {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return !!environment.enableNativeBridge && !!this.host;
|
||||
}
|
||||
|
||||
canPay(): boolean {
|
||||
@@ -64,22 +68,40 @@ export class NativeBridgeService {
|
||||
}
|
||||
|
||||
pay(request: INativePayRequest): any {
|
||||
this.toastService.info({ text: 'در حال پردازش پرداخت...', life: 3000 });
|
||||
const fn = this.host?.pay;
|
||||
if (typeof fn !== 'function') {
|
||||
this.toastService.error({ text: 'متاسفانه پرداخت امکانپذیر نیست.', life: 3000 });
|
||||
return { success: false, error: 'متاسفانه پرداخت امکانپذیر نیست.' };
|
||||
if (request.amount <= 10_000) {
|
||||
const errorMessage = 'برای مقادیر زیر ۱۰۰ هزار ریال، پرداخت ممکن نیست.';
|
||||
this.toastService.error({ text: errorMessage, life: 3000 });
|
||||
return {
|
||||
success: false,
|
||||
error: errorMessage,
|
||||
};
|
||||
}
|
||||
|
||||
this.toastService.info({ text: 'در حال پردازش پرداخت...', life: 3000 });
|
||||
try {
|
||||
fn(request.amount, request.id);
|
||||
|
||||
// @ts-ignore
|
||||
window.NativeBridge.pay(request.amount, request.id || '');
|
||||
return { success: true };
|
||||
|
||||
// return { success: true, data: parsed ?? raw };
|
||||
} catch (error) {
|
||||
this.toastService.info({ text: (error as Error).message, life: 30000 });
|
||||
return { success: false, error: (error as Error).message };
|
||||
}
|
||||
// const fn = window.NativeBridge.pay(123, 'test');
|
||||
// if (typeof fn !== 'function') {
|
||||
// this.toastService.error({ text: 'متاسفانه پرداخت امکانپذیر نیست.', life: 3000 });
|
||||
// return { success: false, error: 'متاسفانه پرداخت امکانپذیر نیست.' };
|
||||
// }
|
||||
|
||||
// try {
|
||||
// fn(123, 'test');
|
||||
// // fn(request.amount, request.id || '');
|
||||
|
||||
// return { success: true };
|
||||
|
||||
// // return { success: true, data: parsed ?? raw };
|
||||
// } catch (error) {
|
||||
// this.toastService.info({ text: (error as Error).message, life: 30000 });
|
||||
// return { success: false, error: (error as Error).message };
|
||||
// }
|
||||
}
|
||||
|
||||
print(request: INativePrintRequest): INativeBridgeResult {
|
||||
@@ -87,17 +109,13 @@ export class NativeBridgeService {
|
||||
}
|
||||
|
||||
private invokePrint(payload: INativePrintRequest): INativeBridgeResult {
|
||||
const fn = this.host?.print;
|
||||
if (typeof fn !== 'function') {
|
||||
return { success: false, error: 'متاسفانه چاپ امکانپذیر نیست.' };
|
||||
}
|
||||
|
||||
try {
|
||||
fn(payload);
|
||||
|
||||
// @ts-ignore
|
||||
window.NativeBridge.print(JSON.stringify([payload]));
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
return { success: false, error: 'متاسفانه چاپ امکانپذیر نیست.' };
|
||||
this.toastService.info({ text: (error as Error).message, life: 30000 });
|
||||
return { success: false, error: (error as Error).message };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user