Files
tripz-llc/apps/driver_new/lib/features/wallet/cubit/wallet_cubit.dart
T
Hamza-AyedandClaude Opus 5 096acae74e feat(apps): الدراور وطبقتا الميزات والإشعارات — المرحلة 6
## طبقتا الميزات مُطبَّقتان معاً
AppDrawer يفحص: Features.wallet && context.tenantHas('wallet')
- Features.x ثابت const: يقرّر ما يُبنى في الـbinary. إطفاؤه يحذف الكود
  فلا يُستخرج (docs/23 §5)
- tenantHas من GET /tenant/config/:slug: يقرّر ما يُعرض ممّا بُني حسب اشتراك
  المستأجر (docs/38 §10)
هذا هو ربط lite/pro/max عملياً. TenantCubit يعرض النسخة المخزّنة فوراً ثم
يحدّثها: إقلاع بلا إنترنت يعرض الميزات المعروفة آخر مرة لا شاشة فارغة.

## الشاشات
الدراور · تعديل الحساب · سجلّ الرحلات · الإعدادات (مظهر + لغة) · المساعدة.
الرقم في تعديل الحساب معطّل مع سبب معروض لا مخفي: هو هوية الحساب على الخادم
وتغييره يعني حساباً آخر (docs/38 §1).

## الإشعارات
PushService معزول — الملف الوحيد الذي يعرف Firebase. التسجيل بعد إثبات
الجلسة عبر خطّاف في SessionCubit، ومع اشتراك onTokenRefresh: بدونه تتوقّف
الإشعارات بصمت بعد أسابيع. الإعداد الأصلي كان جاهزاً مسبقاً.

## تصحيحات بنيوية كشفها فحص آلي
docs/23 §1 يمنع أن تستورد ميزة من أخرى — وكانت خمس مخالفات:
1. features/history أُدمجت في features/trip — السجلّ جزء من ميزة الرحلة
2. AppDrawer صعد إلى core/ui — هيكل تطبيق لا ميزة
3. AuthFailure → core/api/api_failure.dart، ومترجمه → core/ui/failure_text.dart
4. AuthHeader → core/ui/form_header.dart
5. ProfileRepository مستقلّ عن AuthRepository: تعديل الملف ليس مصادقة

flutter analyze نظيف · الراكب 98 ملف/7,497 سطر · السائق 95 ملف/6,931 سطر.
فحوص آلية نظيفة: صفر استيراد بين ميزتين · core يستورد features من di و
router وحدهما · Firebase و intaleq_maps و geolocator و socket_io كلٌّ معزول.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-04 23:52:27 +03:00

49 lines
1.4 KiB
Dart

import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../core/api/api_exception.dart';
import '../../../core/ui/view_status.dart';
import '../data/wallet_repository.dart';
import 'wallet_state.dart';
class WalletCubit extends Cubit<WalletState> {
WalletCubit(this._repo) : super(const WalletState());
final WalletRepository _repo;
Future<void> load() async {
emit(state.copyWith(status: ViewStatus.loading));
try {
final wallet = await _repo.wallet();
final txns = await _repo.transactions();
if (isClosed) return;
emit(state.copyWith(
status: ViewStatus.success,
wallet: wallet,
transactions: txns,
));
} on ApiException catch (e) {
if (!isClosed) {
emit(state.copyWith(status: ViewStatus.error, error: e.message));
}
}
}
Future<void> topup(num amount) async {
if (amount <= 0) return;
emit(state.copyWith(action: WalletAction.toppingUp));
try {
await _repo.topup(amount);
if (isClosed) return;
emit(state.copyWith(action: WalletAction.topupDone));
// الرصيد يُعاد جلبه من الخادم لا يُحسب محلياً: المال لا يُقدَّر
// في التطبيق (docs/23 §0.2).
await load();
} on ApiException {
if (!isClosed) emit(state.copyWith(action: WalletAction.topupFailed));
}
}
}