check
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../core/config/api_config.dart';
|
||||
import '../core/config/sync_config.dart';
|
||||
import '../core/services/connectivity_service.dart';
|
||||
import '../core/services/receipt_service.dart';
|
||||
@@ -8,7 +7,6 @@ import '../core/services/sound_service.dart';
|
||||
import '../data/datasources/local_store.dart';
|
||||
import '../data/repositories/customer_repository_impl.dart';
|
||||
import '../data/repositories/product_repository_impl.dart';
|
||||
import '../data/remote/auth_api.dart';
|
||||
import '../data/remote/catalogue_source.dart';
|
||||
import '../data/remote/http_catalogue_source.dart';
|
||||
import '../data/remote/simulated_catalogue_source.dart';
|
||||
@@ -91,30 +89,14 @@ final catalogueSourceProvider = Provider<CatalogueSource>((ref) {
|
||||
/// exists to prevent.
|
||||
final syncConfigProvider = StateProvider<SyncConfig>((ref) {
|
||||
final terminal = ref.watch(terminalIdentityProvider);
|
||||
final session = ref.watch(apiSessionProvider);
|
||||
|
||||
return SyncConfig(
|
||||
transport: TransportKind.http,
|
||||
httpBaseUrl: ApiConfig.baseUrl,
|
||||
// The location the sign-in was scoped to, falling back to whatever this
|
||||
// device was last pointed at. Never a literal: two outlets sharing a
|
||||
// store id would post sales into each other's books.
|
||||
storeId: session?.storeId ?? terminal.storeId,
|
||||
httpBaseUrl: 'https://fiesta.nearle.app/live/api/v1/pos',
|
||||
storeId: terminal.storeId,
|
||||
terminalId: terminal.code,
|
||||
// The bearer token from `POST /login`. Held here rather than in the
|
||||
// keystore because it expires — see `LoginSession.expiresAt` — so it
|
||||
// belongs to the session and goes when the session does.
|
||||
apiKey: session?.token,
|
||||
);
|
||||
});
|
||||
|
||||
/// Signs the terminal in. Owns its own HTTP client, closed with the provider.
|
||||
final authApiProvider = Provider<AuthApi>((ref) {
|
||||
final api = AuthApi();
|
||||
ref.onDispose(api.dispose);
|
||||
return api;
|
||||
});
|
||||
|
||||
/// Real network state, folded with the Settings offline switch.
|
||||
final connectivityServiceProvider = Provider<ConnectivityService>((ref) {
|
||||
final service = ConnectivityService(
|
||||
@@ -180,15 +162,11 @@ final storeRepositoryProvider = Provider<StoreRepositoryImpl>(
|
||||
);
|
||||
|
||||
/// The outlet, refreshed whenever staff or details change.
|
||||
final storeAccountProvider = FutureProvider<StoreAccount>((ref) {
|
||||
// The address the back office signed in, so Settings and the invoice header
|
||||
// show the account that actually owns this till rather than a build
|
||||
// constant. Falls back only before anyone has signed in.
|
||||
final email = ref.watch(apiSessionProvider)?.email;
|
||||
return ref.watch(storeRepositoryProvider).load(
|
||||
email: (email == null || email.isEmpty) ? DemoCredentials.email : email,
|
||||
);
|
||||
});
|
||||
final storeAccountProvider = FutureProvider<StoreAccount>(
|
||||
(ref) => ref.watch(storeRepositoryProvider).load(
|
||||
email: DemoCredentials.email,
|
||||
),
|
||||
);
|
||||
|
||||
/// Campaigns stored on this terminal.
|
||||
final promosProvider = FutureProvider<List<Promo>>(
|
||||
@@ -248,11 +226,9 @@ final terminalIdentityProvider = Provider<TerminalIdentity>((ref) {
|
||||
|
||||
final cashierSessionProvider = StateProvider<CashierSession>((ref) {
|
||||
final terminal = ref.watch(terminalIdentityProvider);
|
||||
final session = ref.watch(apiSessionProvider);
|
||||
|
||||
return CashierSession(
|
||||
name: session?.displayUserName ?? 'Operator',
|
||||
role: (session?.isAdmin ?? false) ? 'ADMIN' : 'CASHIER',
|
||||
name: 'Suriya',
|
||||
role: 'ADMIN',
|
||||
terminalId: terminal.code,
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user