Fixes for PostHog
This commit is contained in:
@@ -11,6 +11,8 @@ class CommonConstants {
|
||||
static String apiEndpoint = '/api/v1';
|
||||
static String amplitudeSecret = 'c3d75b3e2520d708440acbb16b923e79';
|
||||
static String amplitudeServerZone = 'EU';
|
||||
static String posthogApiKey = '';
|
||||
static String posthogHost = 'https://eu.i.posthog.com';
|
||||
static Locale defaultLocale = const Locale('en');
|
||||
static String defaultCurrency = 'EUR';
|
||||
static int defaultDimensionLength = 500;
|
||||
@@ -36,6 +38,8 @@ class CommonConstants {
|
||||
apiEndpoint = configJson['apiEndpoint'] ?? apiEndpoint;
|
||||
amplitudeSecret = configJson['amplitudeSecret'] ?? amplitudeSecret;
|
||||
amplitudeServerZone = configJson['amplitudeServerZone'] ?? amplitudeServerZone;
|
||||
posthogApiKey = configJson['posthogApiKey'] ?? posthogApiKey;
|
||||
posthogHost = configJson['posthogHost'] ?? posthogHost;
|
||||
defaultLocale = Locale(configJson['defaultLocale'] ?? defaultLocale.languageCode);
|
||||
defaultCurrency = configJson['defaultCurrency'] ?? defaultCurrency;
|
||||
wsProto = configJson['wsProto'] ?? wsProto;
|
||||
|
||||
@@ -15,6 +15,8 @@ class Constants extends CommonConstants {
|
||||
static String get currentOrgKey => CommonConstants.currentOrgKey;
|
||||
static String get apiUrl => CommonConstants.apiUrl;
|
||||
static String get serviceUrl => CommonConstants.serviceUrl;
|
||||
static String get posthogApiKey => CommonConstants.posthogApiKey;
|
||||
static String get posthogHost => CommonConstants.posthogHost;
|
||||
static int get defaultDimensionLength => CommonConstants.defaultDimensionLength;
|
||||
static String get deviceIdStorageKey => CommonConstants.deviceIdStorageKey;
|
||||
static String get nilObjectRef => CommonConstants.nilObjectRef;
|
||||
|
||||
@@ -21,6 +21,8 @@ extension AppConfigExtension on AppConfig {
|
||||
external String? get apiEndpoint;
|
||||
external String? get amplitudeSecret;
|
||||
external String? get amplitudeServerZone;
|
||||
external String? get posthogApiKey;
|
||||
external String? get posthogHost;
|
||||
external String? get defaultLocale;
|
||||
external String? get wsProto;
|
||||
external String? get wsEndpoint;
|
||||
@@ -40,6 +42,8 @@ class Constants extends CommonConstants {
|
||||
static String get currentOrgKey => CommonConstants.currentOrgKey;
|
||||
static String get apiUrl => CommonConstants.apiUrl;
|
||||
static String get serviceUrl => CommonConstants.serviceUrl;
|
||||
static String get posthogApiKey => CommonConstants.posthogApiKey;
|
||||
static String get posthogHost => CommonConstants.posthogHost;
|
||||
static int get defaultDimensionLength => CommonConstants.defaultDimensionLength;
|
||||
static String get deviceIdStorageKey => CommonConstants.deviceIdStorageKey;
|
||||
static String get nilObjectRef => CommonConstants.nilObjectRef;
|
||||
@@ -57,6 +61,8 @@ class Constants extends CommonConstants {
|
||||
'apiEndpoint': config.apiEndpoint,
|
||||
'amplitudeSecret': config.amplitudeSecret,
|
||||
'amplitudeServerZone': config.amplitudeServerZone,
|
||||
'posthogApiKey': config.posthogApiKey,
|
||||
'posthogHost': config.posthogHost,
|
||||
'defaultLocale': config.defaultLocale,
|
||||
'wsProto': config.wsProto,
|
||||
'wsEndpoint': config.wsEndpoint,
|
||||
|
||||
@@ -79,6 +79,10 @@ enum ResourceType {
|
||||
@JsonValue('payments')
|
||||
payments,
|
||||
|
||||
/// Represents payment orchestration service
|
||||
@JsonValue('payment_orchestrator')
|
||||
paymentOrchestrator,
|
||||
|
||||
@JsonValue('payment_methods')
|
||||
paymentMethods,
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
@@ -20,6 +22,9 @@ import 'package:pshared/utils/exception.dart';
|
||||
|
||||
|
||||
class AccountProvider extends ChangeNotifier {
|
||||
AccountProvider({Future<void> Function(Account?)? onAccountChanged})
|
||||
: _onAccountChanged = onAccountChanged;
|
||||
|
||||
static String get currentUserRef => Constants.nilObjectRef;
|
||||
|
||||
// The resource now wraps our Account? state along with its loading/error state.
|
||||
@@ -27,6 +32,8 @@ class AccountProvider extends ChangeNotifier {
|
||||
Resource<Account?> get resource => _resource;
|
||||
late LocaleProvider _localeProvider;
|
||||
PendingLogin? _pendingLogin;
|
||||
Future<void>? _restoreFuture;
|
||||
Future<void> Function(Account?)? _onAccountChanged;
|
||||
|
||||
Account? get account => _resource.data;
|
||||
PendingLogin? get pendingLogin => _pendingLogin;
|
||||
@@ -53,11 +60,21 @@ class AccountProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
// Private helper to update the resource and notify listeners.
|
||||
void setAccountChangedListener(Future<void> Function(Account?)? listener) => _onAccountChanged = listener;
|
||||
|
||||
void _setResource(Resource<Account?> newResource) {
|
||||
final previousAccount = _resource.data;
|
||||
_resource = newResource;
|
||||
_notifyAccountChanged(previousAccount, newResource.data);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _notifyAccountChanged(Account? previous, Account? current) {
|
||||
if (previous == current) return;
|
||||
final handler = _onAccountChanged;
|
||||
if (handler != null) unawaited(handler(current));
|
||||
}
|
||||
|
||||
void updateProvider(LocaleProvider localeProvider) => _localeProvider = localeProvider;
|
||||
|
||||
void _pickupLocale(String locale) => _localeProvider.setLocale(Locale(locale));
|
||||
@@ -220,4 +237,11 @@ class AccountProvider extends ChangeNotifier {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> restoreIfPossible() {
|
||||
return _restoreFuture ??= AuthorizationService.isAuthorizationStored().then<void>((hasAuth) async {
|
||||
if (!hasAuth) return;
|
||||
await restore();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ class PermissionsProvider extends ChangeNotifier {
|
||||
Resource<UserAccess> _userAccess = Resource(data: null, isLoading: false, error: null);
|
||||
late OrganizationsProvider _organizations;
|
||||
bool _isLoaded = false;
|
||||
bool _errorHandled = false;
|
||||
|
||||
void update(OrganizationsProvider venue) {
|
||||
_organizations = venue;
|
||||
@@ -44,6 +45,7 @@ class PermissionsProvider extends ChangeNotifier {
|
||||
/// Load the [UserAccess] for the current venue.
|
||||
Future<UserAccess?> load() async {
|
||||
_userAccess = _userAccess.copyWith(isLoading: true, error: null);
|
||||
_errorHandled = false;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
@@ -67,6 +69,12 @@ class PermissionsProvider extends ChangeNotifier {
|
||||
return _userAccess.data;
|
||||
}
|
||||
|
||||
bool get hasUnhandledError => error != null && !_errorHandled;
|
||||
|
||||
void markErrorHandled() {
|
||||
_errorHandled = true;
|
||||
}
|
||||
|
||||
Future<UserAccess?> changeRole(String accountRef, String newRoleDescRef) async {
|
||||
final currentRole = roles.firstWhereOrNull((r) => r.accountRef == accountRef);
|
||||
final currentDesc = currentRole != null
|
||||
|
||||
Reference in New Issue
Block a user