fix(payment): autoDispose payment catalog so CC edits reflect without app restart

paymentCatalogProvider was a plain FutureProvider, which Riverpod caches for the whole app session — so control-center enable/disable/create of payment methods only showed up after an app restart. Backend was already correct (every mutator calls invalidatePaymentCatalog). Switch to FutureProvider.autoDispose so the catalog is dropped when the payment page is popped and re-fetched on re-open. Only watched by the payment method screen.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-01 22:27:26 +08:00
parent 529a38ae3f
commit 22048c678f

View File

@@ -106,7 +106,15 @@ const PaymentCatalog kFallbackPaymentCatalog = _FallbackCatalog();
/// App-facing catalog. Calls `GET /api/client/payment-methods`; on 5xx or /// App-facing catalog. Calls `GET /api/client/payment-methods`; on 5xx or
/// network error returns [kFallbackPaymentCatalog] so checkout never /// network error returns [kFallbackPaymentCatalog] so checkout never
/// hard-fails. See `requirement/phase5-payment-catalog-plan.md` §5. /// hard-fails. See `requirement/phase5-payment-catalog-plan.md` §5.
final paymentCatalogProvider = FutureProvider<PaymentCatalog>((ref) async { ///
/// `autoDispose`: a plain FutureProvider caches its result for the whole app
/// session, so control-center edits to payment methods (enable/disable/create)
/// only showed up after an app restart. autoDispose drops the cached catalog
/// once the payment screen is popped (no listeners), so re-opening the payment
/// page re-fetches the now-current catalog from the backend (whose own cache is
/// invalidated on every mutation).
final paymentCatalogProvider =
FutureProvider.autoDispose<PaymentCatalog>((ref) async {
final api = ref.read(apiClientProvider); final api = ref.read(apiClientProvider);
try { try {
final res = await api.get('/api/client/payment-methods'); final res = await api.get('/api/client/payment-methods');