Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update tvl response and api #101

Merged
merged 1 commit into from
May 30, 2024
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
6 changes: 3 additions & 3 deletions Sources/MarketKit/Classes/Managers/CoinManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ extension CoinManager {

func defiCoins(rawDefiCoins: [DefiCoinRaw]) -> [DefiCoin] {
do {
let fullCoins = try fullCoins(coinUids: rawDefiCoins.compactMap(\.uid))
let fullCoins = try fullCoins(coinUids: rawDefiCoins.compactMap(\.coinUid))
let dictionary = fullCoins.reduce(into: [String: FullCoin]()) { $0[$1.coin.uid] = $1 }

return rawDefiCoins.map { rawDefiCoin in
rawDefiCoin.defiCoin(fullCoin: rawDefiCoin.uid.flatMap { dictionary[$0] })
return rawDefiCoins.map { raw in
raw.defiCoin(uid: raw.uid, fullCoin: raw.coinUid.flatMap { dictionary[$0] })
}
} catch {
return []
Expand Down
1 change: 1 addition & 0 deletions Sources/MarketKit/Classes/Models/DefiCoin.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation

public struct DefiCoin {
public let uid: String
public let type: DefiCoinType
public let tvl: Decimal
public let tvlRank: Int
Expand Down
9 changes: 6 additions & 3 deletions Sources/MarketKit/Classes/Models/DefiCoinRaw.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Foundation
import ObjectMapper

class DefiCoinRaw: ImmutableMappable {
let uid: String?
let uid: String
let coinUid: String?
let name: String
let logo: String
let tvl: Decimal
Expand All @@ -18,7 +19,8 @@ class DefiCoinRaw: ImmutableMappable {
let chainTvls: [String: Decimal]

required init(map: Map) throws {
uid = try? map.value("uid")
uid = try map.value("uid")
coinUid = try? map.value("coin_uid")
name = try map.value("name")
logo = try map.value("logo")
tvl = try map.value("tvl", using: Transform.stringToDecimalTransform)
Expand All @@ -34,7 +36,7 @@ class DefiCoinRaw: ImmutableMappable {
chainTvls = (try? map.value("chain_tvls", using: Transform.stringToDecimalTransform)) ?? [:]
}

func defiCoin(fullCoin: FullCoin?) -> DefiCoin {
func defiCoin(uid: String, fullCoin: FullCoin?) -> DefiCoin {
let type: DefiCoin.DefiCoinType

if let fullCoin {
Expand All @@ -44,6 +46,7 @@ class DefiCoinRaw: ImmutableMappable {
}

return DefiCoin(
uid: uid,
type: type,
tvl: tvl,
tvlRank: tvlRank,
Expand Down
2 changes: 1 addition & 1 deletion Sources/MarketKit/Classes/Providers/HsProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ extension HsProvider {
"currency": currencyCode.lowercased(),
]

return try await networkManager.fetch(url: "\(baseUrl)/v1/defi-protocols", method: .get, parameters: parameters, headers: headers)
return try await networkManager.fetch(url: "\(baseUrl)/v1/defi-protocols/list", method: .get, parameters: parameters, headers: headers)
}

// Coin Categories
Expand Down