Skip to content

Commit

Permalink
Add configurations for widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
ealymbaev committed Oct 24, 2023
1 parent b86525d commit a5c8315
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 44 deletions.
4 changes: 4 additions & 0 deletions UnstoppableWallet/IntentExtension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>HsProviderApiKey</key>
<string>$(hs_provider_api_key)</string>
<key>MarketApiUrl</key>
<string>${market_api_url}</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
Expand Down
2 changes: 1 addition & 1 deletion UnstoppableWallet/IntentExtension/IntentHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Intents

class IntentHandler: INExtension, SingleCoinPriceIntentHandling {
func provideSelectedCoinOptionsCollection(for _: SingleCoinPriceIntent) async throws -> INObjectCollection<WidgetCoin> {
let provider = ApiProvider(baseUrl: "https://api-dev.blocksdecoded.com")
let provider = ApiProvider()

let coins = try await provider.topCoins(limit: 100)

Expand Down
50 changes: 18 additions & 32 deletions UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct CoinPriceListProvider: IntentTimelineProvider {
private func fetch(sortType: SortType, family: WidgetFamily) async throws -> CoinPriceListEntry {
let storage = SharedLocalStorage()
let currency = CurrencyManager(storage: storage).baseCurrency
let apiProvider = ApiProvider(baseUrl: "https://api-dev.blocksdecoded.com")
let apiProvider = ApiProvider()

let listType: ApiProvider.ListType
let listOrder: ApiProvider.ListOrder
Expand Down
4 changes: 4 additions & 0 deletions UnstoppableWallet/Widget/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>HsProviderApiKey</key>
<string>$(hs_provider_api_key)</string>
<key>MarketApiUrl</key>
<string>${market_api_url}</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
Expand Down
19 changes: 10 additions & 9 deletions UnstoppableWallet/Widget/Misc/ApiProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ class ApiProvider {
private let networkManager = NetworkManager()
private let headers: HTTPHeaders

init(baseUrl: String) {
self.baseUrl = baseUrl
init() {
baseUrl = WidgetConfig.marketApiUrl

var headers = HTTPHeaders()
headers.add(name: "widget", value: "true")
headers.add(name: "app_platform", value: "ios")
// headers.add(name: "app_version", value: appVersion)
headers.add(name: "app_version", value: WidgetConfig.appVersion)

// if let appId {
// headers.add(name: "app_id", value: appId)
// }
if let appId = WidgetConfig.appId {
headers.add(name: "app_id", value: appId)
}

// if let apiKey {
// headers.add(name: "apikey", value: apiKey)
// }
if let apiKey = WidgetConfig.hsProviderApiKey {
headers.add(name: "apikey", value: apiKey)
}

self.headers = headers
}
Expand Down
20 changes: 20 additions & 0 deletions UnstoppableWallet/Widget/Misc/WidgetConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Foundation
import UIKit

struct WidgetConfig {
static var appVersion: String {
Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
}

static var appId: String? {
UIDevice.current.identifierForVendor?.uuidString
}

static var marketApiUrl: String {
(Bundle.main.object(forInfoDictionaryKey: "MarketApiUrl") as? String) ?? ""
}

static var hsProviderApiKey: String? {
(Bundle.main.object(forInfoDictionaryKey: "HsProviderApiKey") as? String).flatMap { $0.isEmpty ? nil : $0 }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct SingleCoinPriceProvider: IntentTimelineProvider {

private func fetch(coinUid: String) async throws -> SingleCoinPriceEntry {
let currency = CurrencyManager(storage: SharedLocalStorage()).baseCurrency
let apiProvider = ApiProvider(baseUrl: "https://api-dev.blocksdecoded.com")
let apiProvider = ApiProvider()

let coin = try await apiProvider.coinWithPrice(uid: coinUid, currencyCode: currency.code)

Expand Down

0 comments on commit a5c8315

Please sign in to comment.