Frontend first draft

This commit is contained in:
Arseni
2025-11-13 15:06:15 +03:00
parent e47f343afb
commit ddb54ddfdc
504 changed files with 25498 additions and 1 deletions

View File

@@ -0,0 +1,47 @@
import 'package:flutter/material.dart';
class CommonConstants {
static String apiProto = const String.fromEnvironment('API_PROTO', defaultValue: 'http');
static String apiHost = const String.fromEnvironment('API_HOST', defaultValue: 'localhost');
// static String apiHost = 'localhost';
// static String apiHost = '10.0.2.2';
static String apiEndpoint = '/api/v1';
static String amplitudeSecret = 'c3d75b3e2520d708440acbb16b923e79';
static String amplitudeServerZone = 'EU';
static Locale defaultLocale = const Locale('en');
static String defaultCurrency = 'EUR';
static int defaultDimensionLength = 500;
static String clientId = '';
static String wsProto = 'ws';
static String wsEndpoint = '/ws';
static Color themeColor = Color.fromARGB(255, 80, 63, 224);
static String nilObjectRef = '000000000000000000000000';
// Public getters for shared properties
static String get serviceUrl => '$apiProto://$apiHost';
static String get apiUrl => '$serviceUrl$apiEndpoint';
static String get wsUrl => '$wsProto://$apiHost$apiEndpoint$wsEndpoint';
static const String accessTokenStorageKey = 'access_token';
static const String refreshTokenStorageKey = 'refresh_token';
static const String currentOrgKey = 'current_org';
static const String deviceIdStorageKey = 'device_id';
// Method to apply the configuration, called by platform-specific implementations
static void applyConfiguration(Map<String, dynamic> configJson) {
apiProto = configJson['apiProto'] ?? apiProto;
apiHost = configJson['apiHost'] ?? apiHost;
apiEndpoint = configJson['apiEndpoint'] ?? apiEndpoint;
amplitudeSecret = configJson['amplitudeSecret'] ?? amplitudeSecret;
amplitudeServerZone = configJson['amplitudeServerZone'] ?? amplitudeServerZone;
defaultLocale = Locale(configJson['defaultLocale'] ?? defaultLocale.languageCode);
defaultCurrency = configJson['defaultCurrency'] ?? defaultCurrency;
wsProto = configJson['wsProto'] ?? wsProto;
wsEndpoint = configJson['wsEndpoint'] ?? wsEndpoint;
defaultDimensionLength = configJson['defaultDimensionLength'] ?? defaultDimensionLength;
clientId = configJson['clientId'] ?? clientId;
if (configJson.containsKey('themeColor')) {
themeColor = Color(int.parse(configJson['themeColor']));
}
}
}

View File

@@ -0,0 +1,2 @@
export 'mobile.dart'
if (dart.library.html) 'web.dart';

View File

@@ -0,0 +1,35 @@
import 'dart:convert';
import 'dart:io';
import 'dart:ui';
import 'package:pshared/config/common.dart';
class Constants extends CommonConstants {
static const String _clientIdMobile = 'com.profee.pay.mobile-3f9c3b76-2f89-4e9e-95a2-1a5b705b7a1d';
static Locale get defaultLocale => CommonConstants.defaultLocale;
static String get clientId => _clientIdMobile;
static String get accessTokenStorageKey => CommonConstants.accessTokenStorageKey;
static String get refreshTokenStorageKey => CommonConstants.refreshTokenStorageKey;
static String get currentOrgKey => CommonConstants.currentOrgKey;
static String get apiUrl => CommonConstants.apiUrl;
static String get serviceUrl => CommonConstants.serviceUrl;
static int get defaultDimensionLength => CommonConstants.defaultDimensionLength;
static String get deviceIdStorageKey => CommonConstants.deviceIdStorageKey;
static String get nilObjectRef => CommonConstants.nilObjectRef;
static Color get themeColor => CommonConstants.themeColor;
static Future<void> initialize() async {
var configFile = File('./config/config.json');
if (await configFile.exists()) {
var configJson = jsonDecode(await configFile.readAsString());
CommonConstants.applyConfiguration({
...configJson,
'clientId': configJson['clientId'] ?? _clientIdMobile,
});
} else {
CommonConstants.clientId = _clientIdMobile;
}
}
}

View File

@@ -0,0 +1,75 @@
import 'dart:ui';
import 'dart:js_interop';
import 'package:pshared/config/common.dart';
/// Bind to the global JS `appConfig` (if it exists).
@JS()
external AppConfig? get appConfig;
/// A staticInterop class for the JS object returned by `appConfig`.
@JS()
@staticInterop
class AppConfig {}
/// Extension methods to expose each property on `AppConfig`.
extension AppConfigExtension on AppConfig {
external String? get apiProto;
external String? get apiHost;
external String? get apiEndpoint;
external String? get amplitudeSecret;
external String? get amplitudeServerZone;
external String? get defaultLocale;
external String? get wsProto;
external String? get wsEndpoint;
external int? get defaultDimensionLength;
external String? get themeColor;
external String? get clientId;
}
class Constants extends CommonConstants {
static const String _clientIdWeb = 'com.profee.pay.web-4b6e8a0f-9b5c-4f57-b3a6-3c456e9bb2cd';
// Just re-expose these from CommonConstants:
static Locale get defaultLocale => CommonConstants.defaultLocale;
static String get clientId => _clientIdWeb;
static String get accessTokenStorageKey => CommonConstants.accessTokenStorageKey;
static String get refreshTokenStorageKey => CommonConstants.refreshTokenStorageKey;
static String get currentOrgKey => CommonConstants.currentOrgKey;
static String get apiUrl => CommonConstants.apiUrl;
static String get serviceUrl => CommonConstants.serviceUrl;
static int get defaultDimensionLength => CommonConstants.defaultDimensionLength;
static String get deviceIdStorageKey => CommonConstants.deviceIdStorageKey;
static String get nilObjectRef => CommonConstants.nilObjectRef;
static Color get themeColor => CommonConstants.themeColor;
static Future<void> initialize() async {
// Try to grab the JS `appConfig` if it exists:
final config = appConfig;
if (config != null) {
// Build a Dart Map from the JS objects properties:
final configJson = <String, dynamic>{
'apiProto': config.apiProto,
'apiHost': config.apiHost,
'apiEndpoint': config.apiEndpoint,
'amplitudeSecret': config.amplitudeSecret,
'amplitudeServerZone': config.amplitudeServerZone,
'defaultLocale': config.defaultLocale,
'wsProto': config.wsProto,
'wsEndpoint': config.wsEndpoint,
'defaultDimensionLength': config.defaultDimensionLength,
'themeColor': config.themeColor,
// If the JS side didnt supply a clientId, fall back to our Dart constant
'clientId': config.clientId ?? _clientIdWeb,
};
CommonConstants.applyConfiguration(configJson);
} else {
// No appConfig on JS side → just use the default Dart client ID.
CommonConstants.clientId = _clientIdWeb;
}
}
}