Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SampleAppSwiftUI/Configs/AppStore.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

base_url = https:/$()/min-api.cryptocompare.com/data/

webSocket_base_url = wss:/$()/streamer.cryptocompare.com/v2?api_key=%@
webSocket_base_url = wss:/$()/streamer.cryptocompare.com/v2

personal_api =
2 changes: 1 addition & 1 deletion SampleAppSwiftUI/Configs/Development.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ PRODUCT_BUNDLE_IDENTIFIER = com.adesso.SampleAppSwiftUI.development

base_url = https:/$()/min-api.cryptocompare.com/data/

webSocket_base_url = wss:/$()/streamer.cryptocompare.com/v2?api_key=%@
webSocket_base_url = wss:/$()/streamer.cryptocompare.com/v2

personal_api =
2 changes: 1 addition & 1 deletion SampleAppSwiftUI/Configs/Production.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ PRODUCT_BUNDLE_IDENTIFIER = com.adesso.SampleAppSwiftUI.prod

base_url = https:/$()/min-api.cryptocompare.com/data/

webSocket_base_url = wss:/$()/streamer.cryptocompare.com/v2?api_key=%@
webSocket_base_url = wss:/$()/streamer.cryptocompare.com/v2

personal_api =
2 changes: 1 addition & 1 deletion SampleAppSwiftUI/Network/WebSocket/WebSocketEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum WebSocketEndpoint: TargetEndpointProtocol {
var path: String {
switch self {
case .baseCoinApi:
return String(format: Constants.webSocketEndpoint, Constants.apiKey)
return Constants.webSocketEndpoint
}
}
}
4 changes: 3 additions & 1 deletion SampleAppSwiftUI/Network/WebSocket/WebSocketProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class WebSocketProvider: NSObject {
init? (endPoint: TargetEndpointProtocol = WebSocketEndpoint.baseCoinApi,
session: URLSession = URLSession.shared ) {
guard let url = URL(string: WebSocketEndpoint.baseCoinApi.path) else { return nil }
self.socket = WebSocketStream(url: url,
let query = URLQueryItem(name: "api_key", value: Configuration.coinApiKey)
let finalURL = url.appending(queryItems: [query])
self.socket = WebSocketStream(url: finalURL,
session: session)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class WebSocketSubscription<S: Subscriber>: Subscription where S.Input == URLSes
_ = subscriber.receive(message)
}
} catch {
debugPrint("Someting went wrong")
debugPrint("Something went wrong")
}
}
}
5 changes: 3 additions & 2 deletions SampleAppSwiftUI/Resources/Constants/URLs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import Foundation

enum URLs {
enum Icons {
static let baseURL = "https://assets.coincap.io/assets/icons/"
static let baseURL = "https://assets.coincap.io"
static let iconPath = "/assets/icons/"
static let scaleURL = "@2x.png"

static func getURL(from coinCode: CoinCode) -> URL? {
URL(string: "\(baseURL)\(coinCode.lowercased())\(scaleURL)")
URL(string: "\(baseURL)\(iconPath)\(coinCode.lowercased())\(scaleURL)")
}
}
}
10 changes: 6 additions & 4 deletions SampleAppSwiftUI/Scenes/Favorites/FavoritesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ class FavoritesViewModel: ObservableObject {
}

func fetchFavorites() {
DispatchQueue.main.async {
self.isLoading = false
self.getFavoriteCoinList()
self.startSocketConnection()
if Configuration.coinApiKey.isNotEmpty {
DispatchQueue.main.async {
self.isLoading = false
self.getFavoriteCoinList()
self.startSocketConnection()
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions SampleAppSwiftUI/Utility/Extensions/ArrayExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ extension Array: RawRepresentable where Element: Codable {
}
return result
}

public var isNotEmpty: Bool {
!self.isEmpty
}
}
4 changes: 4 additions & 0 deletions SampleAppSwiftUI/Utility/Extensions/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ extension String {
static var empty: Self {
""
}

public var isNotEmpty: Bool {
!self.isEmpty
}
}