Fixes & Updates - 2026-06-01: Integrate Back-End v3 updates, fix call/connection issues across apps
This commit is contained in:
@@ -6,7 +6,21 @@ import '../functions/crud.dart';
|
||||
class ComplaintController extends GetxController {
|
||||
var complaintList = [].obs;
|
||||
var isLoading = false.obs;
|
||||
var showOnlyDelayed = false.obs;
|
||||
final CRUD _crud = CRUD();
|
||||
|
||||
List<dynamic> get delayedComplaints {
|
||||
final weekAgo = DateTime.now().subtract(const Duration(days: 7));
|
||||
return complaintList.where((c) {
|
||||
if (c['statusComplaint'] == 'Resolved') return false;
|
||||
try {
|
||||
final date = DateTime.parse(c['date_filed']);
|
||||
return date.isBefore(weekAgo);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
|
||||
@@ -6,10 +6,8 @@ import 'package:sefer_admin1/constant/links.dart';
|
||||
import 'package:sefer_admin1/controller/functions/crud.dart';
|
||||
import 'package:sefer_admin1/controller/auth/otp_helper.dart';
|
||||
|
||||
import '../../constant/api_key.dart';
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../main.dart';
|
||||
import '../../print.dart';
|
||||
|
||||
class DashboardController extends GetxController {
|
||||
bool isLoading = false;
|
||||
@@ -38,7 +36,6 @@ class DashboardController extends GetxController {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (res != 'failure' && res != null) {
|
||||
try {
|
||||
var d = res is String ? jsonDecode(res) : res;
|
||||
|
||||
@@ -16,8 +16,8 @@ class DashboardV2Controller extends GetxController {
|
||||
super.onInit();
|
||||
fetchRealtimeData();
|
||||
fetchSmartAlerts();
|
||||
// Auto refresh every 30 seconds
|
||||
_timer = Timer.periodic(const Duration(seconds: 30), (timer) {
|
||||
// Auto refresh every 2 minutes
|
||||
_timer = Timer.periodic(const Duration(minutes: 2), (timer) {
|
||||
fetchRealtimeData();
|
||||
fetchSmartAlerts();
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ import '../../print.dart';
|
||||
|
||||
class FinancialV2Controller extends GetxController {
|
||||
bool isLoading = true;
|
||||
|
||||
|
||||
Map<String, dynamic> stats = {};
|
||||
List<dynamic> settlements = [];
|
||||
|
||||
@@ -19,19 +19,20 @@ class FinancialV2Controller extends GetxController {
|
||||
Future<void> fetchAllFinancials() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
|
||||
|
||||
await Future.wait([
|
||||
fetchStats(),
|
||||
fetchSettlements(),
|
||||
]);
|
||||
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> fetchStats() async {
|
||||
try {
|
||||
var res = await CRUD().get(link: AppLink.financialStatsV2, payload: {});
|
||||
var res =
|
||||
await CRUD().getWallet(link: AppLink.financialStatsV2, payload: {});
|
||||
if (res != 'failure' && res != null) {
|
||||
var d = res is String ? jsonDecode(res) : res;
|
||||
if (d['status'] == 'success') {
|
||||
@@ -45,7 +46,8 @@ class FinancialV2Controller extends GetxController {
|
||||
|
||||
Future<void> fetchSettlements() async {
|
||||
try {
|
||||
var res = await CRUD().get(link: AppLink.settlementsV2, payload: {});
|
||||
var res =
|
||||
await CRUD().getWallet(link: AppLink.settlementsV2, payload: {});
|
||||
if (res != 'failure' && res != null) {
|
||||
var d = res is String ? jsonDecode(res) : res;
|
||||
if (d['status'] == 'success') {
|
||||
|
||||
@@ -191,7 +191,7 @@ class OtpHelper extends GetxController {
|
||||
textConfirm: 'تحقق',
|
||||
confirmTextColor: Colors.white,
|
||||
onConfirm: () {
|
||||
if (otpCode.length >= 5) {
|
||||
if (otpCode.length >= 3) {
|
||||
Get.back();
|
||||
verifyLoginOtp(phone, otpCode, password, fingerprint);
|
||||
} else {
|
||||
|
||||
@@ -116,48 +116,6 @@ class CRUD {
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> getWallet({
|
||||
required String link,
|
||||
Map<String, dynamic>? payload,
|
||||
}) async {
|
||||
var s = await getJwtWallet();
|
||||
final hmac = box.read(BoxName.hmac);
|
||||
var url = Uri.parse(link);
|
||||
|
||||
// إضافة الـ HMAC للـ payload لزيادة التوافقية
|
||||
if (payload != null && hmac != null) {
|
||||
payload['hmac'] = hmac.toString();
|
||||
}
|
||||
|
||||
var response = await http.post(
|
||||
url,
|
||||
body: payload,
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
'Authorization': 'Bearer $s',
|
||||
'X-HMAC-Auth': hmac.toString(),
|
||||
'X-Device-FP': box.read(BoxName.fingerPrint) ?? '',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
try {
|
||||
var jsonData = jsonDecode(response.body);
|
||||
if (jsonData['status'] == 'success') {
|
||||
return jsonData;
|
||||
}
|
||||
return jsonData['status'] ?? 'failure';
|
||||
} catch (e) {
|
||||
return 'failure';
|
||||
}
|
||||
} else if (response.statusCode == 401) {
|
||||
await getJwtWallet();
|
||||
return 'token_expired';
|
||||
} else {
|
||||
return 'failure';
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> post(
|
||||
{required String link, Map<String, dynamic>? payload}) async {
|
||||
var url = Uri.parse(link);
|
||||
@@ -248,7 +206,8 @@ class CRUD {
|
||||
mainToken = mainTokenEnc.toString().split(AppInformation.addd)[0];
|
||||
}
|
||||
Log.print('Wallet SSO mainToken length: ${mainToken.length}');
|
||||
Log.print('Wallet SSO token starts with: ${mainToken.substring(0, mainToken.length > 10 ? 10 : mainToken.length)}');
|
||||
Log.print(
|
||||
'Wallet SSO token starts with: ${mainToken.substring(0, mainToken.length > 10 ? 10 : mainToken.length)}');
|
||||
|
||||
// استخدام الـ SSO للسيرفر الرئيسي إذا كان الأدمن مسجل دخوله
|
||||
var response1 = await http.post(
|
||||
@@ -307,6 +266,68 @@ class CRUD {
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<dynamic> getWallet({
|
||||
required String link,
|
||||
Map<String, dynamic>? payload,
|
||||
bool isRetry = false,
|
||||
}) async {
|
||||
var s = await getJwtWallet();
|
||||
final hmac = box.read(BoxName.hmac);
|
||||
var url = Uri.parse(link);
|
||||
|
||||
Log.print('--- getWallet Execution ---');
|
||||
Log.print('URL: $url');
|
||||
Log.print('JWT: $s');
|
||||
Log.print('HMAC: $hmac');
|
||||
Log.print('Is Retry: $isRetry');
|
||||
Log.print('Payload: $payload');
|
||||
|
||||
if (payload != null && hmac != null) {
|
||||
payload['hmac'] = hmac.toString();
|
||||
}
|
||||
|
||||
try {
|
||||
var response = await http.post(
|
||||
url,
|
||||
body: payload,
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
'Authorization': 'Bearer $s',
|
||||
'X-HMAC-Auth': hmac.toString(),
|
||||
'X-Device-FP': box.read(BoxName.fingerPrint) ?? '',
|
||||
},
|
||||
);
|
||||
|
||||
Log.print('Status Code: ${response.statusCode}');
|
||||
Log.print('Response Body: ${response.body}');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
try {
|
||||
var jsonData = jsonDecode(response.body);
|
||||
if (jsonData['status'] == 'success') {
|
||||
return jsonData;
|
||||
}
|
||||
Log.print('Logic Error: Status is not success. Data: $jsonData');
|
||||
return jsonData['status'] ?? 'failure';
|
||||
} catch (e) {
|
||||
Log.print('JSON Decode Error in getWallet: $e');
|
||||
return 'failure';
|
||||
}
|
||||
} else if (response.statusCode == 401 && !isRetry) {
|
||||
Log.print('Token expired (401). Clearing cache and retrying...');
|
||||
await box.remove('wallet_jwt');
|
||||
await box.remove('wallet_jwt_expiry');
|
||||
return await getWallet(link: link, payload: payload, isRetry: true);
|
||||
} else {
|
||||
Log.print('HTTP Error in getWallet. Status: ${response.statusCode}');
|
||||
return 'failure';
|
||||
}
|
||||
} catch (e) {
|
||||
Log.print('HTTP Request Exception in getWallet: $e');
|
||||
return 'failure';
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> postWallet(
|
||||
{required String link, Map<String, dynamic>? payload}) async {
|
||||
var s = await getJwtWallet();
|
||||
|
||||
Reference in New Issue
Block a user