feat(apps): التقييم والمحفظتان ومسار الرحلة — المرحلة 5
## التقييم مفروض لا اختياري
SessionCubit يفحص GET /trips/rating/pending بعد إثبات الجلسة، ووجود رحلة
معلّقة يحجز التطبيق كله عند /rating حتى تُحسم. دور المستخدم في الرحلة يأتي
من الخادم لا من نوع التطبيق — نفس الرقم قد يكون له حسابان (docs/38 §1).
التقييم المزدوج يرجّع 400، وهو نجاح من منظور المستخدم: الرحلة مُقيَّمة فعلاً
فلا يُحبس في شاشة بلا مخرج.
الجلسة تحتاج معرفة التقييم المعلّق، و core لا يجوز أن يستورد ميزة التقييم —
فأُضيفت الطريقة لواجهة SessionSource ونفّذها AuthRepository.
## core/format/money.dart
كل المبالغ تصل نصوصاً ("0.000")؛ التحويل والعرض من نقطة واحدة. عدد المنازل
من العملة (JOD ثلاث)، والعملة من إعداد المستأجر لا من ثابت في التطبيق.
## المحفظتان لا تُوحَّدان
- الراكب WalletPage: رصيد + شحن = التزام على المنصّة
- السائق EarningsPage: أرباح + سحب = إيراد له
شكلهما متقارب وحسابهما مختلف؛ دمجهما خطأ محاسبي لا اختصار (docs/39 §4).
## السحب بخطوتين
request يرسل رمزاً بلا خصم، و confirm هو ما يخصم ويحجز. شاشة سيرو كانت خطوة
واحدة ولم تُقلَّد. الرمز الخاطئ لا يُرجع المستخدم لخطوة المبلغ.
الرصيد التشغيلي معروض منفصلاً عن الأرباح: منه تُخصم العمولة ونفاده يوقف
وصول الطلبات — خلطه بالأرباح يخفي سبب توقّف العمل عن السائق.
FareSummary يعرض رقم كلّ طرف: price_for_passenger للراكب و price_for_driver
للسائق — حقلان منفصلان والفرق عمولة (docs/38 §4).
الإلغاء بتأكيد صريح مع سبب؛ السبب لا يقبله عقد الخادم بعد لكن السؤال يخفض
الإلغاء العرضي ويجهّز الحقل.
flutter analyze نظيف · الراكب 86 ملف/6,280 سطر · السائق 83 ملف/5,818 سطر.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
1156299d09
commit
66e28acc58
@@ -0,0 +1,88 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../core/api/api_exception.dart';
|
||||
import '../data/wallet_repository.dart';
|
||||
|
||||
/// خطوتا السحب (docs/38 §6): `request` يرسل رمزاً **بلا خصم**، و`confirm`
|
||||
/// هو ما يخصم ويحجز. شاشة سيرو كانت خطوة واحدة — لا تُقلَّد (docs/39 §4).
|
||||
enum PayoutStep { amount, code, done }
|
||||
|
||||
enum PayoutFailure { none, insufficient, rejected, network }
|
||||
|
||||
class PayoutState {
|
||||
const PayoutState({
|
||||
this.step = PayoutStep.amount,
|
||||
this.busy = false,
|
||||
this.payoutId,
|
||||
this.devCode,
|
||||
this.failure = PayoutFailure.none,
|
||||
});
|
||||
|
||||
final PayoutStep step;
|
||||
final bool busy;
|
||||
final String? payoutId;
|
||||
|
||||
/// يعود من الخادم في وضع التطوير وحده — يملأ الحقل لتسريع الاختبار.
|
||||
final String? devCode;
|
||||
|
||||
final PayoutFailure failure;
|
||||
|
||||
PayoutState copyWith({
|
||||
PayoutStep? step,
|
||||
bool? busy,
|
||||
String? payoutId,
|
||||
String? devCode,
|
||||
PayoutFailure? failure,
|
||||
}) {
|
||||
return PayoutState(
|
||||
step: step ?? this.step,
|
||||
busy: busy ?? this.busy,
|
||||
payoutId: payoutId ?? this.payoutId,
|
||||
devCode: devCode ?? this.devCode,
|
||||
failure: failure ?? this.failure,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PayoutCubit extends Cubit<PayoutState> {
|
||||
PayoutCubit(this._repo) : super(const PayoutState());
|
||||
|
||||
final WalletRepository _repo;
|
||||
|
||||
Future<void> request({required num amount, required String channel}) async {
|
||||
if (amount <= 0) return;
|
||||
emit(state.copyWith(busy: true, failure: PayoutFailure.none));
|
||||
try {
|
||||
final res = await _repo.requestPayout(amount: amount, channel: channel);
|
||||
emit(state.copyWith(
|
||||
busy: false,
|
||||
step: PayoutStep.code,
|
||||
payoutId: res.payoutId,
|
||||
devCode: res.devCode,
|
||||
));
|
||||
} on ApiException catch (e) {
|
||||
emit(state.copyWith(
|
||||
busy: false,
|
||||
failure: e.statusCode == 400
|
||||
? PayoutFailure.insufficient
|
||||
: PayoutFailure.network,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> confirm(String code) async {
|
||||
final id = state.payoutId;
|
||||
if (id == null || code.isEmpty) return;
|
||||
emit(state.copyWith(busy: true, failure: PayoutFailure.none));
|
||||
try {
|
||||
await _repo.confirmPayout(id, code);
|
||||
emit(state.copyWith(busy: false, step: PayoutStep.done));
|
||||
} on ApiException {
|
||||
// الرمز الخاطئ لا يُرجع المستخدم لخطوة المبلغ: يبقى على الرمز ويعيد
|
||||
// المحاولة — الطلب قائم على الخادم أصلاً.
|
||||
emit(state.copyWith(busy: false, failure: PayoutFailure.rejected));
|
||||
}
|
||||
}
|
||||
|
||||
void reset() => emit(const PayoutState());
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
import '../../../core/ui/view_status.dart';
|
||||
import '../data/models/wallet.dart';
|
||||
import '../data/models/wallet_txn.dart';
|
||||
|
||||
enum WalletAction { none, toppingUp, topupFailed, topupDone }
|
||||
|
||||
class WalletState extends Equatable {
|
||||
const WalletState({
|
||||
this.status = ViewStatus.idle,
|
||||
this.wallet,
|
||||
this.transactions = const [],
|
||||
this.action = WalletAction.none,
|
||||
this.error,
|
||||
});
|
||||
|
||||
final ViewStatus status;
|
||||
final Wallet? wallet;
|
||||
final List<WalletTxn> transactions;
|
||||
|
||||
/// فعلٌ جارٍ داخل الشاشة — منفصل عن [status] كي لا يُخفي الشحنُ الرصيدَ
|
||||
/// المعروض خلفه.
|
||||
final WalletAction action;
|
||||
|
||||
final String? error;
|
||||
|
||||
String get currency => wallet?.currency ?? '';
|
||||
|
||||
WalletState copyWith({
|
||||
ViewStatus? status,
|
||||
Wallet? wallet,
|
||||
List<WalletTxn>? transactions,
|
||||
WalletAction? action,
|
||||
String? error,
|
||||
}) {
|
||||
return WalletState(
|
||||
status: status ?? this.status,
|
||||
wallet: wallet ?? this.wallet,
|
||||
transactions: transactions ?? this.transactions,
|
||||
action: action ?? this.action,
|
||||
error: error ?? this.error,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [status, wallet, transactions, action, error];
|
||||
}
|
||||
Reference in New Issue
Block a user