Skip to content

Commit

Permalink
Implement new collectibles API
Browse files Browse the repository at this point in the history
  • Loading branch information
vikmeup committed Aug 6, 2018
1 parent c283f2e commit 5668e6a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Trust/Core/Network/TrustNetwork.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum TrustNetworkProtocolError: LocalizedError {
}

protocol NetworkProtocol: TrustNetworkProtocol {
func assets(for address: Address) -> Promise<[NonFungibleTokenCategory]>
func collectibles() -> Promise<[NonFungibleTokenCategory]>
func tickers(with tokenPrices: [TokenPrice]) -> Promise<[CoinTicker]>

func tokensList() -> Promise<[TokenObject]>
Expand Down Expand Up @@ -100,9 +100,9 @@ final class TrustNetwork: NetworkProtocol {
}
}

func assets(for address: Address) -> Promise<[NonFungibleTokenCategory]> {
func collectibles() -> Promise<[NonFungibleTokenCategory]> {
return Promise { seal in
provider.request(.assets(address: address.description)) { result in
provider.request(.collectibles(dict)) { result in
switch result {
case .success(let response):
do {
Expand Down
14 changes: 6 additions & 8 deletions Trust/EtherClient/TrustClient/TrustAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum TrustAPI {
case prices(TokensPrice)
case getAllTransactions(addresses: [String: String])
case search(query: String, networks: [Int])
case assets(address: String)
case collectibles([String: [String]])
case getTokens([String: [String]])
case register(device: PushDevice)
case unregister(device: PushDevice)
Expand All @@ -34,8 +34,8 @@ extension TrustAPI: TargetType {
return "/notifications/register"
case .unregister:
return "/notifications/unregister"
case .assets:
return "/assets"
case .collectibles:
return "/collectibles"
case .search:
return "/tokens/list"
}
Expand All @@ -49,7 +49,7 @@ extension TrustAPI: TargetType {
case .getAllTransactions: return .post
case .register: return .post
case .unregister: return .post
case .assets: return .get
case .collectibles: return .post
case .search: return .get
}
}
Expand All @@ -66,14 +66,12 @@ extension TrustAPI: TargetType {
return .requestParameters(parameters: params, encoding: URLEncoding())
case .getAllTransactions(let addresses):
return .requestParameters(parameters: ["address": addresses], encoding: URLEncoding())
case .getTokens(let value):
return .requestJSONEncodable(value)
case .register(let device):
return .requestJSONEncodable(device)
case .unregister(let device):
return .requestJSONEncodable(device)
case .assets(let value):
return .requestParameters(parameters: ["address": value], encoding: URLEncoding())
case .collectibles(let value), .getTokens(let value):
return .requestJSONEncodable(value)
case .search(let query, let networks):
let networkString = networks.map { String($0) }.joined(separator: ",")
return .requestParameters(parameters: ["query": query, "networks": networkString], encoding: URLEncoding())
Expand Down
2 changes: 1 addition & 1 deletion Trust/Tokens/ViewModels/NonFungibleTokenViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class NonFungibleTokenViewModel {
func fetchAssets() -> Promise<[NonFungibleTokenCategory]> {
return Promise { seal in
firstly {
tokensNetwork.assets(for: self.address)
tokensNetwork.collectibles()
}.done { [weak self] tokens in
self?.storage.add(tokens: tokens)
seal.fulfill(tokens)
Expand Down

0 comments on commit 5668e6a

Please sign in to comment.