From 3917c6a48222af2e249e44be9c443ebcfe522262 Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 5 Apr 2024 10:28:09 +0700 Subject: [PATCH 1/2] MOB-1950 - Updated some API hosts --- .../ApiRequestBuilder.swift | 64 +++++++------------ .../NFTsAPIRequestBuilder.swift | 2 +- .../NetworkEnvironment/NetworkConfig.swift | 20 ++---- .../XMTP/XMTPPushNotificationsHelper.swift | 4 +- .../NetworkService+ProfilesApi.swift | 2 - .../Services/Networking/NetworkService.swift | 2 +- 6 files changed, 30 insertions(+), 64 deletions(-) diff --git a/unstoppable-ios-app/domains-manager-ios/NetworkEnvironment/ApiRequestBuilder.swift b/unstoppable-ios-app/domains-manager-ios/NetworkEnvironment/ApiRequestBuilder.swift index f4610fa8f..9dcfad392 100644 --- a/unstoppable-ios-app/domains-manager-ios/NetworkEnvironment/ApiRequestBuilder.swift +++ b/unstoppable-ios-app/domains-manager-ios/NetworkEnvironment/ApiRequestBuilder.swift @@ -609,16 +609,14 @@ extension Endpoint { static let expirationPeriodMin: TimeInterval = 5 static func getPublicProfile(for domain: DomainItem, fields: Set) -> Endpoint { - // https://profile.ud-staging.com/api/public/aaron.x return getPublicProfile(for: domain.name, fields: fields) } static func getPublicProfile(for domainName: DomainName, fields: Set) -> Endpoint { - // https://profile.ud-staging.com/api/public/aaron.x let fieldsQuery = fields.map({ $0.rawValue }).joined(separator: ",") return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/public/\(domainName)", queryItems: fields.isEmpty ? [] : [URLQueryItem(name: "fields", value: fieldsQuery)], body: "" @@ -626,9 +624,8 @@ extension Endpoint { } static func getBadgesInfo(for domainName: DomainName) -> Endpoint { - //https://profile.unstoppabledomains.com/api/public/aaronquirk.x/badges return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/public/\(domainName)/badges", queryItems: [], body: "" @@ -645,9 +642,8 @@ extension Endpoint { } static func getBadgeDetailedInfo(for badge: BadgesInfo.BadgeInfo) -> Endpoint { - // https://profile.unstoppabledomains.com/api/badges/opensea-tothemoonalisa return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/badges/\(badge.code)", queryItems: [], body: "" @@ -662,7 +658,7 @@ extension Endpoint { .init(name: "reverse-resolution-required", value: String(shouldBeSetAsRR))] return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/search", queryItems: queryItems, body: "" @@ -671,10 +667,9 @@ extension Endpoint { static let yearInSecs: TimeInterval = 60 * 60 * 24 * 356 static func getGeneratedMessageToRetrieve(for domain: DomainItem) -> Endpoint { - // https://profile.ud-staging.com/api/user/aaron.x/signature?expiry=1765522015090 let expiry = Int( (Date().timeIntervalSince1970 + yearInSecs) * 1000) return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/user/\(domain.name)/signature", queryItems: [URLQueryItem(name: "expiry", value: String(expiry)), URLQueryItem(name: "device", value: String(true))], /// This flag will allow signature to be used in all profile API endpoints for this domain @@ -694,7 +689,6 @@ extension Endpoint { expires: UInt64, signature: String, fields: Set) throws -> Endpoint { - // https://profile.ud-staging.com/api/user/aaron.x let expiresString = "\(expires)" let headers = [ SignatureComponentHeaders.CodingKeys.domain.rawValue: domain.name, @@ -703,7 +697,7 @@ extension Endpoint { ] let fieldsQuery = fields.map({ $0.rawValue }).joined(separator: ",") return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/user/\(domain.name)", queryItems: [URLQueryItem(name: "fields", value: fieldsQuery)], body: "", @@ -712,10 +706,9 @@ extension Endpoint { } static func getGeneratedMessageToUpdate(for domain: DomainItem, body: String) -> Endpoint { - // https://profile.ud-staging.com/api/user/aaron.x/signature?expiry=1765522015090 let expiry = Int( (Date().timeIntervalSince1970 + 60_000_000) * 1000) return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/user/\(domain.name)/signature", queryItems: [URLQueryItem(name: "expiry", value: String(expiry))], body: body @@ -726,7 +719,6 @@ extension Endpoint { with message: GeneratedMessage, signature: String, body: String) throws -> Endpoint { - // https://profile.ud-staging.com/api/user/aaron.x let expires = "\(message.headers.expires)" let headers = [ SignatureComponentHeaders.CodingKeys.domain.rawValue: domain.name, @@ -734,7 +726,7 @@ extension Endpoint { SignatureComponentHeaders.CodingKeys.signature.rawValue: signature ] return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/user/\(domain.name)", queryItems: [], body: body, @@ -746,7 +738,6 @@ extension Endpoint { expires: UInt64, signature: String, body: String = "") throws -> Endpoint { - // https://profile.ud-staging.com/api/user/aaron.x let expiresString = "\(expires)" let headers = [ SignatureComponentHeaders.CodingKeys.domain.rawValue: domain.name, @@ -754,7 +745,7 @@ extension Endpoint { SignatureComponentHeaders.CodingKeys.signature.rawValue: signature ] return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/user/\(domain.name)/notifications/preferences", queryItems: [], body: body, @@ -764,9 +755,8 @@ extension Endpoint { static func getFollowingStatus(for followerDomain: DomainName, followingDomain: DomainName) -> Endpoint { - //https://api.unstoppabledomains.com/profile/followers/lisa.x/follow-status/oleg.x return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/followers/\(followingDomain)/follow-status/\(followerDomain)", queryItems: [], body: "" @@ -777,14 +767,13 @@ extension Endpoint { relationshipType: DomainProfileFollowerRelationshipType, count: Int, cursor: Int?) -> Endpoint { - //https://api.unstoppabledomains.com/profile/followers/oleg.x?relationship_type=followers&cursor=4266&take=50 var queryItems: [URLQueryItem] = [.init(name: "relationship_type", value: relationshipType.rawValue), .init(name: "take", value: "\(count)")] if let cursor { queryItems.append(.init(name: "cursor", value: "\(cursor)")) } return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/followers/\(domain)", queryItems: queryItems, body: "" @@ -797,7 +786,6 @@ extension Endpoint { expires: UInt64, signature: String, body: String) -> Endpoint { - // https://profile.ud-staging.com/api/user/aaron.x let expiresString = "\(expires)" let headers = [ SignatureComponentHeaders.CodingKeys.domain.rawValue: domain, @@ -805,7 +793,7 @@ extension Endpoint { SignatureComponentHeaders.CodingKeys.signature.rawValue: signature ] return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/followers/\(domainNameToFollow)", queryItems: [], body: body, @@ -815,29 +803,26 @@ extension Endpoint { static func joinBadgeCommunity(body: String) -> Endpoint { - //https://messaging.ud-staging.com/api/push/group/join return Endpoint( - host: NetworkConfig.baseMessagingHost, - path: "/api/push/group/join", + host: NetworkConfig.baseAPIHost, + path: "/messaging/push/group/join", queryItems: [], body: body ) } static func leaveBadgeCommunity(body: String) -> Endpoint { - //https://messaging.ud-staging.com/api/push/group/leave return Endpoint( - host: NetworkConfig.baseMessagingHost, - path: "/api/push/group/leave", + host: NetworkConfig.baseAPIHost, + path: "/messaging/push/group/leave", queryItems: [], body: body ) } static func getSpamStatus(for address: HexAddress) -> Endpoint { - //https://api.unstoppabledomains.com/messaging/xmtp/spam/0x9B4Ed628640A73154895e369AE39a93732535924 return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/messaging/xmtp/spam/\(address)", queryItems: [], body: "" @@ -847,7 +832,6 @@ extension Endpoint { static func uploadRemoteAttachment(for domain: DomainItem, with timedSignature: PersistedTimedSignature, body: String) throws -> Endpoint { - // https://profile.ud-staging.com/api/user/aaron.x/attachment let expires = "\(timedSignature.expires)" let signature = timedSignature.sign let headers = [ @@ -856,7 +840,7 @@ extension Endpoint { SignatureComponentHeaders.CodingKeys.signature.rawValue: signature ] return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/user/\(domain.name)/attachment", queryItems: [], body: body, @@ -866,9 +850,8 @@ extension Endpoint { static func getProfileConnectionSuggestions(for domain: DomainName, filterFollowings: Bool) -> Endpoint { - //https://api.unstoppabledomains.com/profile/public/oleg.x/connections return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/public/\(domain)/connections", queryItems: [.init(name: "recommendationsOnly", value: String(filterFollowings))], body: "" @@ -876,9 +859,8 @@ extension Endpoint { } static func getProfileFollowersRanking(count: Int) -> Endpoint { - //https://api.unstoppabledomains.com/profile/followers/rankings?count=20 return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/followers/rankings", queryItems: [.init(name: "count", value: String(count))], body: "" @@ -889,11 +871,10 @@ extension Endpoint { // MARK: - Open methods extension Endpoint { static func getCryptoPortfolio(for wallet: String) -> Endpoint { - //https://api.ud-staging.com/profile/user/0xcd0dadab45baf9a06ce1279d1342ecc3f44845af/wallets let queryItems: [URLQueryItem] = [.init(name: "walletFields", value: "native,token"), .init(name: "forceRefresh", value: String(Int(Date().timeIntervalSince1970)))] return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/user/\(wallet)/wallets", queryItems: queryItems, body: "", @@ -905,7 +886,6 @@ extension Endpoint { cursor: String?, chain: String?, forceRefresh: Bool) -> Endpoint { - //https://api.ud-staging.com/profile/user/0xcd0dadab45baf9a06ce1279d1342ecc3f44845af/transactions var queryItems: [URLQueryItem] = [] if let cursor { queryItems.append(URLQueryItem(name: "cursor", value: cursor)) @@ -918,7 +898,7 @@ extension Endpoint { headers = headers.appending(dict2: ["refreshCache" : String(Date().timeIntervalSince1970)]) } return Endpoint( - host: NetworkConfig.baseProfileHost, + host: NetworkConfig.baseAPIHost, path: "/profile/user/\(wallet)/transactions", queryItems: queryItems, body: "", diff --git a/unstoppable-ios-app/domains-manager-ios/NetworkEnvironment/NFTsAPIRequestBuilder.swift b/unstoppable-ios-app/domains-manager-ios/NetworkEnvironment/NFTsAPIRequestBuilder.swift index adf9286cc..4d5d42b7f 100644 --- a/unstoppable-ios-app/domains-manager-ios/NetworkEnvironment/NFTsAPIRequestBuilder.swift +++ b/unstoppable-ios-app/domains-manager-ios/NetworkEnvironment/NFTsAPIRequestBuilder.swift @@ -32,6 +32,6 @@ final class NFTsAPIRequestBuilder { } private func baseURL() -> String { - "https://" + NetworkConfig.baseProfileHost + "/profile/user" + "https://" + NetworkConfig.baseAPIHost + "/profile/user" } } diff --git a/unstoppable-ios-app/domains-manager-ios/NetworkEnvironment/NetworkConfig.swift b/unstoppable-ios-app/domains-manager-ios/NetworkEnvironment/NetworkConfig.swift index 839510c8f..e78bdc870 100644 --- a/unstoppable-ios-app/domains-manager-ios/NetworkEnvironment/NetworkConfig.swift +++ b/unstoppable-ios-app/domains-manager-ios/NetworkEnvironment/NetworkConfig.swift @@ -59,14 +59,10 @@ struct NetworkConfig { } static var baseResolveUrl: String { - if User.instance.getSettings().isTestnetUsed { - return "https://resolve.ud-staging.com" - } else { - return "https://resolve.unstoppabledomains.com" - } + baseAPIUrl + "/resolve" } - static var baseProfileHost: String { + static var baseAPIHost: String { if User.instance.getSettings().isTestnetUsed { return "api.ud-staging.com" } else { @@ -74,16 +70,8 @@ struct NetworkConfig { } } - static var baseProfileUrl: String { - "https://\(baseProfileHost)" - } - - static var baseMessagingHost: String { - if User.instance.getSettings().isTestnetUsed { - return "messaging.ud-staging.com" - } else { - return "messaging.unstoppabledomains.com" - } + static var baseAPIUrl: String { + "https://\(baseAPIHost)" } private static let StagingAccessApiKey = "mob-01-stg-8792ed66-f0d6-463d-b08b-7f5667980676" diff --git a/unstoppable-ios-app/domains-manager-ios/Services/MessagingService/XMTP/XMTPPushNotificationsHelper.swift b/unstoppable-ios-app/domains-manager-ios/Services/MessagingService/XMTP/XMTPPushNotificationsHelper.swift index ea16eacdd..d7010f50f 100644 --- a/unstoppable-ios-app/domains-manager-ios/Services/MessagingService/XMTP/XMTPPushNotificationsHelper.swift +++ b/unstoppable-ios-app/domains-manager-ios/Services/MessagingService/XMTP/XMTPPushNotificationsHelper.swift @@ -23,8 +23,8 @@ struct XMTPPushNotificationsHelper { private extension XMTPPushNotificationsHelper { static func makeRequestFor(topics: [String], accepted: Bool?, blocked: Bool?, by client: Client) async throws { do { - let url = URL(string: "https://\(NetworkConfig.baseMessagingHost)/api/xmtp/topics/register")! - let subReq = try await buildSubscribeRequestFor(topics: topics, + let url = URL(string: "https://\(NetworkConfig.baseAPIHost)/messaging/xmtp/topics/register")! + let subReq = try await buildSubscribeRequestFor(topics: topics, accepted: accepted, blocked: blocked, by: client) diff --git a/unstoppable-ios-app/domains-manager-ios/Services/Networking/NetworkService+ProfilesApi.swift b/unstoppable-ios-app/domains-manager-ios/Services/Networking/NetworkService+ProfilesApi.swift index 05e9c1a13..4fb51ea07 100644 --- a/unstoppable-ios-app/domains-manager-ios/Services/Networking/NetworkService+ProfilesApi.swift +++ b/unstoppable-ios-app/domains-manager-ios/Services/Networking/NetworkService+ProfilesApi.swift @@ -44,7 +44,6 @@ extension NetworkService: DomainProfileNetworkServiceProtocol { } public func fetchBadgesInfo(for domainName: DomainName) async throws -> BadgesInfo { - // https://profile.unstoppabledomains.com/api/public/aaronquirk.x/badges guard let url = Endpoint.getBadgesInfo(for: domainName).url else { throw NetworkLayerError.creatingURLFailed } @@ -69,7 +68,6 @@ extension NetworkService: DomainProfileNetworkServiceProtocol { } public func fetchBadgeDetailedInfo(for badge: BadgesInfo.BadgeInfo) async throws -> BadgeDetailedInfo { - // https://profile.unstoppabledomains.com/api/badges/opensea-tothemoonalisa guard let url = Endpoint.getBadgeDetailedInfo(for: badge).url else { throw NetworkLayerError.creatingURLFailed } diff --git a/unstoppable-ios-app/domains-manager-ios/Services/Networking/NetworkService.swift b/unstoppable-ios-app/domains-manager-ios/Services/Networking/NetworkService.swift index b4698ec08..b96d51ee5 100644 --- a/unstoppable-ios-app/domains-manager-ios/Services/Networking/NetworkService.swift +++ b/unstoppable-ios-app/domains-manager-ios/Services/Networking/NetworkService.swift @@ -466,7 +466,7 @@ extension NetworkService { /// This function will return UD/ENS/Null name and corresponding PFP if available OR throw 404 func fetchGlobalReverseResolution(for identifier: HexAddress) async throws -> GlobalRR? { do { - guard let url = URL(string: "\(NetworkConfig.baseProfileUrl)/profile/resolve/\(identifier)") else { return nil } // User's input contains not allowed characters + guard let url = URL(string: "\(NetworkConfig.baseAPIUrl)/profile/resolve/\(identifier)") else { return nil } // User's input contains not allowed characters let data = try await NetworkService().fetchData(for: url, method: .get) From 577a4e19866ae27aab638b2a5d6df5ac3ac9e84b Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 5 Apr 2024 10:44:12 +0700 Subject: [PATCH 2/2] Updated User-Agent header in network service --- .../Public profile view/PublicProfileViewModel.swift | 7 ------- .../Services/Networking/NetworkService.swift | 7 +++++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/unstoppable-ios-app/domains-manager-ios/Modules/DomainProfile/Public Profile/Public profile view/PublicProfileViewModel.swift b/unstoppable-ios-app/domains-manager-ios/Modules/DomainProfile/Public Profile/Public profile view/PublicProfileViewModel.swift index d0b61daca..f46e8404b 100644 --- a/unstoppable-ios-app/domains-manager-ios/Modules/DomainProfile/Public Profile/Public profile view/PublicProfileViewModel.swift +++ b/unstoppable-ios-app/domains-manager-ios/Modules/DomainProfile/Public Profile/Public profile view/PublicProfileViewModel.swift @@ -303,10 +303,3 @@ extension PublicProfileView { } } - -func loadImageFrom(url: URL) async -> UIImage? { - let urlRequest = URLRequest(url: url) - guard let (imageData, _) = try? await URLSession.shared.data(for: urlRequest) else { return nil } - - return UIImage(data: imageData) -} diff --git a/unstoppable-ios-app/domains-manager-ios/Services/Networking/NetworkService.swift b/unstoppable-ios-app/domains-manager-ios/Services/Networking/NetworkService.swift index b96d51ee5..3566e4c74 100644 --- a/unstoppable-ios-app/domains-manager-ios/Services/Networking/NetworkService.swift +++ b/unstoppable-ios-app/domains-manager-ios/Services/Networking/NetworkService.swift @@ -251,8 +251,11 @@ struct NetworkService { } extraHeaders.forEach { urlRequest.addValue($0.value, forHTTPHeaderField: $0.key)} - urlRequest.addValue(Version.getCurrentAppVersionString() ?? "version n/a", forHTTPHeaderField: Self.appVersionHeaderKey) - + let version = Version.getCurrentAppVersionString() ?? "version n/a" + urlRequest.addValue(version, forHTTPHeaderField: Self.appVersionHeaderKey) + let userAgent = "UnstoppableDomainsMobile/<\(version)>" + urlRequest.setValue(userAgent, forHTTPHeaderField: "User-Agent") + Debugger.printInfo(topic: .Network, "--- REQUEST TO ENDPOINT") Debugger.printInfo(topic: .Network, "METHOD: \(method) | URL: \(url.absoluteString)") Debugger.printInfo(topic: .Network, "BODY: \(body)")