mirror of
https://github.com/we-promise/sure.git
synced 2026-08-05 16:42:18 +00:00
* feat(mobile): add transaction metadata editing * fix(mobile): preserve explicit metadata clears * fix(mobile): derive persisted tag metadata state * fix(mobile): avoid logging transaction details * fix(mobile): harden transaction edit sync Pass the edited transaction context through provider updates, refresh or fall back after empty update responses, surface field-level API errors, and avoid forced metadata refetches on every edit screen open. * fix(mobile): keep transaction edit selects ci-compatible Use the DropdownButtonFormField API supported by the Flutter version pinned in upstream mobile CI.
63 lines
1.7 KiB
Dart
63 lines
1.7 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import '../models/merchant.dart';
|
|
import '../services/log_service.dart';
|
|
import '../services/merchants_service.dart';
|
|
|
|
class MerchantsProvider with ChangeNotifier {
|
|
final MerchantsService _merchantsService = MerchantsService();
|
|
final LogService _log = LogService.instance;
|
|
|
|
List<Merchant> _merchants = [];
|
|
bool _isLoading = false;
|
|
String? _error;
|
|
bool _hasFetched = false;
|
|
|
|
List<Merchant> get merchants => List.unmodifiable(_merchants);
|
|
bool get isLoading => _isLoading;
|
|
String? get error => _error;
|
|
bool get hasFetched => _hasFetched;
|
|
|
|
Future<void> fetchMerchants({
|
|
required String accessToken,
|
|
bool forceRefresh = false,
|
|
}) async {
|
|
if (_isLoading || (_hasFetched && !forceRefresh)) return;
|
|
|
|
_isLoading = true;
|
|
_error = null;
|
|
notifyListeners();
|
|
|
|
try {
|
|
final result = await _merchantsService.getMerchants(
|
|
accessToken: accessToken,
|
|
);
|
|
|
|
if (result['success'] == true) {
|
|
_merchants =
|
|
(result['merchants'] as List? ?? const []).cast<Merchant>();
|
|
_hasFetched = true;
|
|
_log.info(
|
|
'MerchantsProvider',
|
|
'Fetched ${_merchants.length} merchants',
|
|
);
|
|
} else {
|
|
_error = result['error'] as String?;
|
|
_log.error('MerchantsProvider', 'Failed to fetch merchants: $_error');
|
|
}
|
|
} catch (e) {
|
|
_error = 'Failed to load merchants';
|
|
_log.error('MerchantsProvider', 'Exception fetching merchants: $e');
|
|
} finally {
|
|
_isLoading = false;
|
|
notifyListeners();
|
|
}
|
|
}
|
|
|
|
void clear() {
|
|
_merchants = [];
|
|
_hasFetched = false;
|
|
_error = null;
|
|
notifyListeners();
|
|
}
|
|
}
|