purple: switch local testing to staging testing

This commit is contained in:
William Casarin
2024-01-28 17:32:44 -08:00
parent 0c63f2ee26
commit ff6b19578e
8 changed files with 25 additions and 15 deletions

View File

@@ -63,7 +63,7 @@ class DamusState: HeadlessDamusState {
self.video = video
self.ndb = ndb
self.purple = purple ?? DamusPurple(
environment: settings.purple_api_local_test_mode ? .local_test : .production,
settings: settings,
keypair: keypair
)
}

View File

@@ -8,12 +8,12 @@
import Foundation
class DamusPurple: StoreObserverDelegate {
let environment: ServerEnvironment
let settings: UserSettingsStore
let keypair: Keypair
var starred_profiles_cache: [Pubkey: UserBadgeInfo]
init(environment: ServerEnvironment, keypair: Keypair) {
self.environment = environment
init(settings: UserSettingsStore, keypair: Keypair) {
self.settings = settings
self.keypair = keypair
self.starred_profiles_cache = [:]
}
@@ -23,6 +23,10 @@ class DamusPurple: StoreObserverDelegate {
return await self.profile_purple_badge_info(pubkey: pubkey)?.active
}
var environment: ServerEnvironment {
self.settings.purple_api_staging ? .staging : .production
}
func profile_purple_badge_info(pubkey: Pubkey) async -> UserBadgeInfo? {
if let cached_result = self.starred_profiles_cache[pubkey] {
return cached_result
@@ -216,12 +220,12 @@ extension DamusPurple {
extension DamusPurple {
enum ServerEnvironment {
case local_test
case staging
case production
func get_base_url() -> URL {
switch self {
case .local_test:
case .staging:
Constants.PURPLE_API_TEST_BASE_URL
case .production:
Constants.PURPLE_API_PRODUCTION_BASE_URL

View File

@@ -205,8 +205,8 @@ class UserSettingsStore: ObservableObject {
@Setting(key: "enable_experimental_purple_api", default_value: false)
var enable_experimental_purple_api: Bool
@Setting(key: "purple_api_local_test_mode", default_value: false)
var purple_api_local_test_mode: Bool
@Setting(key: "purple_api_staging", default_value: false)
var purple_api_staging: Bool
@Setting(key: "emoji_reactions", default_value: default_emoji_reactions)
var emoji_reactions: [String]

View File

@@ -43,7 +43,7 @@ func make_nip98_authenticated_request(method: HTTPMethod, url: URL, payload: Dat
createdAt: UInt32(Date().timeIntervalSince1970)
)
let auth_note_json_data: Data = try JSONEncoder().encode(auth_note)
let auth_note_json_data: Data = try encode_json_data(auth_note)
let auth_note_base64: String = base64_encode(auth_note_json_data.bytes)
request.setValue("Nostr " + auth_note_base64, forHTTPHeaderField: "Authorization")

View File

@@ -325,7 +325,13 @@ func decode_nostr_event(txt: String) -> NostrResponse? {
func encode_json<T: Encodable>(_ val: T) -> String? {
let encoder = JSONEncoder()
encoder.outputFormatting = .withoutEscapingSlashes
return (try? encoder.encode(val)).map { String(decoding: $0, as: UTF8.self) }
return (try? encode_json_data(val)).map { String(decoding: $0, as: UTF8.self) }
}
func encode_json_data<T: Encodable>(_ val: T) throws -> Data {
let encoder = JSONEncoder()
encoder.outputFormatting = .withoutEscapingSlashes
return try encoder.encode(val)
}
func decode_nostr_event_json(json: String) -> NostrEvent? {

View File

@@ -14,8 +14,8 @@ class Constants {
static let DEVICE_TOKEN_RECEIVER_TEST_URL: URL = URL(string: "http://localhost:8000/user-info")!
static let MAIN_APP_BUNDLE_IDENTIFIER: String = "com.jb55.damus2"
static let NOTIFICATION_EXTENSION_BUNDLE_IDENTIFIER: String = "com.jb55.damus2.DamusNotificationService"
static let PURPLE_API_PRODUCTION_BASE_URL: URL = URL(string: "https://purple.damus.io")!
static let PURPLE_API_TEST_BASE_URL: URL = URL(string: "http://127.0.0.1:8989")!
static let PURPLE_LANDING_PAGE_TEST_URL: URL = URL(string: "http://localhost:3000/purple")!
static let PURPLE_API_PRODUCTION_BASE_URL: URL = URL(string: "https://api.damus.io")!
static let PURPLE_API_TEST_BASE_URL: URL = URL(string: "https://api-staging.damus.io")!
static let PURPLE_LANDING_PAGE_TEST_URL: URL = URL(string: "https://staging.damus.io/purple")!
static let PURPLE_LANDING_PAGE_PRODUCTION_URL: URL = URL(string: "https://damus.io/purple")!
}

View File

@@ -412,7 +412,7 @@ struct DamusPurpleView: View {
Spacer()
Link(
NSLocalizedString("Learn more", comment: "Label for a link to the Damus Purple landing page"),
destination: damus_state.settings.purple_api_local_test_mode ? Constants.PURPLE_LANDING_PAGE_TEST_URL : Constants.PURPLE_LANDING_PAGE_PRODUCTION_URL
destination: damus_state.settings.purple_api_staging ? Constants.PURPLE_LANDING_PAGE_TEST_URL : Constants.PURPLE_LANDING_PAGE_PRODUCTION_URL
)
.foregroundColor(DamusColors.pink)
.padding()

View File

@@ -28,7 +28,7 @@ struct DeveloperSettingsView: View {
Toggle("Enable experimental Purple API support", isOn: $settings.enable_experimental_purple_api)
.toggleStyle(.switch)
Toggle("Purple API localhost test mode", isOn: $settings.purple_api_local_test_mode)
Toggle("Purple API staging mode", isOn: $settings.purple_api_staging)
.toggleStyle(.switch)
}
}