app_config.dart 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import 'env_debug.dart';
  2. import 'env_release.dart';
  3. /// 应用配置
  4. /// 接口地址按 debug/release 自动切换,见 env_debug.dart / env_release.dart
  5. /// 也可通过 --dart-define 覆盖
  6. abstract class AppConfig {
  7. /// 是否为 Debug 构建
  8. static const bool isDebug = !bool.fromEnvironment('dart.vm.product');
  9. // ── dart-define 覆盖入口(为空则走 env 文件默认值)────
  10. static const String _overrideApiBaseUrl =
  11. String.fromEnvironment('API_BASE_URL', defaultValue: '');
  12. static const String _overrideWsUrl =
  13. String.fromEnvironment('WS_URL', defaultValue: '');
  14. static const String _overrideWsSpotUrl =
  15. String.fromEnvironment('WS_SPOT_URL', defaultValue: '');
  16. static const String _overrideWalletConnectProjectId =
  17. String.fromEnvironment('WALLETCONNECT_PROJECT_ID', defaultValue: '');
  18. static const String _overrideTronFullHost =
  19. String.fromEnvironment('TRON_FULL_HOST', defaultValue: '');
  20. static const String _overrideTronGridApiKey =
  21. String.fromEnvironment('TRONGRID_API_KEY', defaultValue: '');
  22. /// 实际使用的 API 地址
  23. static String get effectiveApiBaseUrl => _overrideApiBaseUrl.isNotEmpty
  24. ? _overrideApiBaseUrl
  25. : (isDebug ? EnvDebug.apiBaseUrl : EnvRelease.apiBaseUrl);
  26. /// 实际使用的 WS 地址
  27. static String get effectiveWsUrl => _overrideWsUrl.isNotEmpty
  28. ? _overrideWsUrl
  29. : (isDebug ? EnvDebug.wsUrl : EnvRelease.wsUrl);
  30. /// 实际使用的现货 WS 地址
  31. static String get effectiveWsSpotUrl => _overrideWsSpotUrl.isNotEmpty
  32. ? _overrideWsSpotUrl
  33. : (isDebug ? EnvDebug.wsSpotUrl : EnvRelease.wsSpotUrl);
  34. /// 兜底 Host 列表
  35. static List<String> get fallbackHosts =>
  36. isDebug ? EnvDebug.fallbackHosts : EnvRelease.fallbackHosts;
  37. /// 远程配置 JSON 地址列表(按顺序尝试,任一成功即止;仅 release 生效)
  38. static List<String> get remoteConfigUrls =>
  39. isDebug ? EnvDebug.remoteConfigUrls : EnvRelease.remoteConfigUrls;
  40. /// 是否显示客服入口(首页、设置、带单申请等)
  41. static bool get customerServiceEnabled =>
  42. isDebug ? EnvDebug.customerServiceEnabled : EnvRelease.customerServiceEnabled;
  43. /// 客服服务地址
  44. static String get customerServiceHost =>
  45. isDebug ? EnvDebug.customerServiceHost : EnvRelease.customerServiceHost;
  46. /// 客服聊天页面路径
  47. static String get customerServiceChatPath =>
  48. isDebug ? EnvDebug.customerServiceChatPath : EnvRelease.customerServiceChatPath;
  49. /// Tron FullNode(与 Web `VITE_TRON_FULL_HOST`,默认 api.trongrid.io)
  50. static String get tronFullHost {
  51. final o = _overrideTronFullHost.trim();
  52. if (o.isNotEmpty) {
  53. return o;
  54. }
  55. final e =
  56. isDebug ? EnvDebug.tronFullHost.trim() : EnvRelease.tronFullHost.trim();
  57. if (e.isNotEmpty) {
  58. return e;
  59. }
  60. return 'https://api.trongrid.io';
  61. }
  62. /// TronGrid API Key(可选,与 Web `VITE_TRONGRID_API_KEY`)
  63. static String get tronGridApiKey {
  64. final o = _overrideTronGridApiKey.trim();
  65. if (o.isNotEmpty) {
  66. return o;
  67. }
  68. return isDebug
  69. ? EnvDebug.tronGridApiKey.trim()
  70. : EnvRelease.tronGridApiKey.trim();
  71. }
  72. /// Reown / WalletConnect Project ID(与 Web 端 `VITE_WALLETCONNECT_PROJECT_ID` 一致;务经 CI / 本地 dart-define 注入)
  73. static String get walletConnectProjectId {
  74. final o = _overrideWalletConnectProjectId.trim();
  75. if (o.isNotEmpty) {
  76. return o;
  77. }
  78. return isDebug
  79. ? EnvDebug.walletConnectProjectId.trim()
  80. : EnvRelease.walletConnectProjectId.trim();
  81. }
  82. /// CDN 地址(图片资源)
  83. static const String cdnUrl = String.fromEnvironment(
  84. 'CDN_URL',
  85. defaultValue: '',
  86. );
  87. /// 应用版本号(与 pubspec.yaml version 保持一致)
  88. static const String appVersion = '4.1.4';
  89. /// 是否启用 Mock 模式
  90. static const bool enableMock = bool.fromEnvironment(
  91. 'ENABLE_MOCK',
  92. defaultValue: false,
  93. );
  94. /// 连接超时(毫秒)
  95. static const int connectTimeoutMs = 15000;
  96. /// 接收超时(毫秒)
  97. static const int receiveTimeoutMs = 15000;
  98. /// 测速超时(毫秒)
  99. static const int speedTestTimeoutMs = 3000;
  100. /// 节点故障转移连续失败阈值
  101. static const int failoverThreshold = 3;
  102. /// 熔断恢复时间(秒)
  103. static const int circuitBreakDurationSec = 60;
  104. }