From 11e935a72258b5b903b17374171a113a1fae9d62 Mon Sep 17 00:00:00 2001 From: Kwonhyukjoon Date: Thu, 18 May 2023 22:35:35 +0900 Subject: [PATCH] [APP-769] kava lend bug fixed (#311) Co-authored-by: Kwonhyukjoon --- Cosmostation/Base/BaseNetWork.swift | 4 +-- .../Main/MainTabViewController.swift | 10 ++---- .../Main/kava/HardDetailViewController.swift | 32 +++++++++++++++---- .../Model/KavaModel/KavaIncentiveReward.swift | 14 +------- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/Cosmostation/Base/BaseNetWork.swift b/Cosmostation/Base/BaseNetWork.swift index af7570294..d5aeee346 100644 --- a/Cosmostation/Base/BaseNetWork.swift +++ b/Cosmostation/Base/BaseNetWork.swift @@ -143,7 +143,7 @@ class BaseNetWork { static func managerHardPoolUrl(_ chain: ChainType?) -> String { if let chainConfig = ChainFactory.getChainConfig(chain) { if (chainConfig.chainType == .KAVA_MAIN) { - return chainConfig.lcdUrl + "hard/accounts" + return chainConfig.lcdUrl + "kava/hard/v1beta1/accounts" } } return "" @@ -152,7 +152,7 @@ class BaseNetWork { static func incentiveUrl(_ chain: ChainType?) -> String { if let chainConfig = ChainFactory.getChainConfig(chain) { if (chainConfig.chainType == .KAVA_MAIN) { - return chainConfig.lcdUrl + "incentive/rewards" + return chainConfig.lcdUrl + "kava/incentive/v1beta1/rewards" } } return "" diff --git a/Cosmostation/Controller/Main/MainTabViewController.swift b/Cosmostation/Controller/Main/MainTabViewController.swift index 785e35ca4..f9773d78f 100644 --- a/Cosmostation/Controller/Main/MainTabViewController.swift +++ b/Cosmostation/Controller/Main/MainTabViewController.swift @@ -978,13 +978,9 @@ class MainTabViewController: UITabBarController, UITabBarControllerDelegate, Acc request.responseJSON { (response) in switch response.result { case .success(let res): - guard let responseData = res as? NSDictionary, let _ = responseData.object(forKey: "height") as? String else { - self.onFetchFinished() - return - } - let kavaIncentiveReward = KavaIncentiveReward.init(responseData) - BaseData.instance.mIncentiveRewards = kavaIncentiveReward.result - + if let responseData = res as? NSDictionary { + BaseData.instance.mIncentiveRewards = IncentiveReward.init(responseData) + } case .failure(let error): print("onFetchKavaIncentiveReward ", error) } diff --git a/Cosmostation/Controller/Main/kava/HardDetailViewController.swift b/Cosmostation/Controller/Main/kava/HardDetailViewController.swift index 89d0af54b..fcbaafe88 100644 --- a/Cosmostation/Controller/Main/kava/HardDetailViewController.swift +++ b/Cosmostation/Controller/Main/kava/HardDetailViewController.swift @@ -223,13 +223,10 @@ class HardDetailViewController: BaseViewController, UITableViewDelegate, UITable request.responseJSON { (response) in switch response.result { case .success(let res): - if let responseData = res as? NSDictionary, let responseResult = responseData.object(forKey: "result") as? Array { - if let coinsDic = responseResult[0].object(forKey: "coins") as? Array { - coinsDic.forEach { rawCoin in - self.mHardModuleCoins.append(Coin.init(rawCoin)) - } - BaseData.instance.mHardModuleCoins = self.mHardModuleCoins - } + if let responseData = res as? NSDictionary, let responseResult = responseData.object(forKey: "accounts") as? Array, + let address = responseResult[0].object(forKey: "address") as? String { + self.mFetchCnt = self.mFetchCnt + 1 + self.onFetchBalance_gRPC(address) } case .failure(let error): @@ -258,4 +255,25 @@ class HardDetailViewController: BaseViewController, UITableViewDelegate, UITable DispatchQueue.main.async(execute: { self.onFetchFinished() }); } } + + func onFetchBalance_gRPC(_ moduleAddress: String) { + DispatchQueue.global().async { + do { + let channel = BaseNetWork.getConnection(self.chainConfig)! + let page = Cosmos_Base_Query_V1beta1_PageRequest.with { $0.limit = 2000 } + let req = Cosmos_Bank_V1beta1_QueryAllBalancesRequest.with { $0.address = moduleAddress; $0.pagination = page } + if let response = try? Cosmos_Bank_V1beta1_QueryClient(channel: channel).allBalances(req, callOptions: BaseNetWork.getCallOptions()).response.wait() { + response.balances.forEach { balance in + self.mHardModuleCoins.append(Coin.init(balance.denom, balance.amount)) + } + BaseData.instance.mHardModuleCoins = self.mHardModuleCoins + } + try channel.close().wait() + + } catch { + print("onFetchBalance_gRPC failed: \(error)") + } + DispatchQueue.main.async(execute: { self.onFetchFinished() }); + } + } } diff --git a/Cosmostation/Model/KavaModel/KavaIncentiveReward.swift b/Cosmostation/Model/KavaModel/KavaIncentiveReward.swift index 7bf2a295f..7977e5628 100644 --- a/Cosmostation/Model/KavaModel/KavaIncentiveReward.swift +++ b/Cosmostation/Model/KavaModel/KavaIncentiveReward.swift @@ -8,18 +8,6 @@ import Foundation -public struct KavaIncentiveReward { - var height: String? - var result: IncentiveReward? - - init(_ dictionary: NSDictionary?) { - self.height = dictionary?["height"] as? String - if let rawIncentiveReward = dictionary?["result"] as? NSDictionary { - self.result = IncentiveReward.init(rawIncentiveReward) - } - } -} - public struct IncentiveReward { var hard_claims: Array = Array() var usdx_minting_claims: Array = Array() @@ -28,7 +16,7 @@ public struct IncentiveReward { var earn_claims: Array = Array() init(_ dictionary: NSDictionary?) { - if let rawHardClaims = dictionary?["hard_claims"] as? Array { + if let rawHardClaims = dictionary?["hard_liquidity_provider_claims"] as? Array { for rawHardClaim in rawHardClaims { self.hard_claims.append(HardClaim(rawHardClaim)) }