Manos Chorianopoulos

fix environment handling

This diff is collapsed. Click to expand it.
...@@ -210,6 +210,9 @@ final class UserDefaultsStore { ...@@ -210,6 +210,9 @@ final class UserDefaultsStore {
210 210
211 @UserDefault(key: "isDarkModeEnabledUD", defaultValue: false) 211 @UserDefault(key: "isDarkModeEnabledUD", defaultValue: false)
212 var isDarkModeEnabled: Bool 212 var isDarkModeEnabled: Bool
213 +
214 + @UserDefault(key: "environmentUD", defaultValue: "production")
215 + var environment: String
213 } 216 }
214 217
215 // MARK: - SDK State Management 218 // MARK: - SDK State Management
...@@ -299,6 +302,9 @@ public final class WarplySDK { ...@@ -299,6 +302,9 @@ public final class WarplySDK {
299 * ``` 302 * ```
300 */ 303 */
301 public func configure(appUuid: String, merchantId: String, environment: Configuration.Environment = .production, language: String = "el") { 304 public func configure(appUuid: String, merchantId: String, environment: Configuration.Environment = .production, language: String = "el") {
305 + // Store environment for later use
306 + storage.environment = environment == .development ? "development" : "production"
307 +
302 Configuration.baseURL = environment.baseURL 308 Configuration.baseURL = environment.baseURL
303 Configuration.host = environment.host 309 Configuration.host = environment.host
304 Configuration.errorDomain = environment.host 310 Configuration.errorDomain = environment.host
...@@ -308,6 +314,8 @@ public final class WarplySDK { ...@@ -308,6 +314,8 @@ public final class WarplySDK {
308 storage.appUuid = appUuid 314 storage.appUuid = appUuid
309 storage.merchantId = merchantId 315 storage.merchantId = merchantId
310 storage.applicationLocale = language 316 storage.applicationLocale = language
317 +
318 + print("✅ [WarplySDK] Environment configured: \(storage.environment)")
311 } 319 }
312 320
313 /// Set environment (development/production) 321 /// Set environment (development/production)
...@@ -378,13 +386,15 @@ public final class WarplySDK { ...@@ -378,13 +386,15 @@ public final class WarplySDK {
378 return 386 return
379 } 387 }
380 388
381 - // Set up configuration based on appUuid 389 + // Set up configuration based on stored environment
382 - Configuration.baseURL = storage.appUuid == "f83dfde1145e4c2da69793abb2f579af" ? 390 + let currentEnvironment = storage.environment == "development" ?
383 - Configuration.Environment.development.baseURL : 391 + Configuration.Environment.development :
384 - Configuration.Environment.production.baseURL 392 + Configuration.Environment.production
385 - Configuration.host = storage.appUuid == "f83dfde1145e4c2da69793abb2f579af" ? 393 +
386 - Configuration.Environment.development.host : 394 + Configuration.baseURL = currentEnvironment.baseURL
387 - Configuration.Environment.production.host 395 + Configuration.host = currentEnvironment.host
396 +
397 + print("✅ [WarplySDK] Using stored environment: \(storage.environment)")
388 398
389 // Store appUuid in UserDefaults for NetworkService access 399 // Store appUuid in UserDefaults for NetworkService access
390 UserDefaults.standard.set(storage.appUuid, forKey: "appUuidUD") 400 UserDefaults.standard.set(storage.appUuid, forKey: "appUuidUD")
...@@ -831,6 +841,23 @@ public final class WarplySDK { ...@@ -831,6 +841,23 @@ public final class WarplySDK {
831 set { storage.isDarkModeEnabled = newValue } 841 set { storage.isDarkModeEnabled = newValue }
832 } 842 }
833 843
844 + // MARK: - Environment Access
845 +
846 + /// Get current environment
847 + public var currentEnvironment: Configuration.Environment {
848 + return storage.environment == "development" ? .development : .production
849 + }
850 +
851 + /// Check if currently in production environment
852 + public func isProductionEnvironment() -> Bool {
853 + return storage.environment == "production"
854 + }
855 +
856 + /// Check if currently in development environment
857 + public func isDevelopmentEnvironment() -> Bool {
858 + return storage.environment == "development"
859 + }
860 +
834 // MARK: - Authentication 861 // MARK: - Authentication
835 862
836 /// Register device with Warply platform 863 /// Register device with Warply platform
...@@ -2874,7 +2901,7 @@ public final class WarplySDK { ...@@ -2874,7 +2901,7 @@ public final class WarplySDK {
2874 2901
2875 /// Get market pass map URL 2902 /// Get market pass map URL
2876 public func getMarketPassMapUrl() -> String { 2903 public func getMarketPassMapUrl() -> String {
2877 - if storage.appUuid == "f83dfde1145e4c2da69793abb2f579af" { 2904 + if storage.environment == "development" {
2878 return "https://magenta-dev.supermarketdeals.eu/map?map=true" 2905 return "https://magenta-dev.supermarketdeals.eu/map?map=true"
2879 } else { 2906 } else {
2880 return "https://magenta.supermarketdeals.eu/map?map=true" 2907 return "https://magenta.supermarketdeals.eu/map?map=true"
......