Skip to content

Commit

Permalink
[APP-769] kava lend bug fixed (#311)
Browse files Browse the repository at this point in the history
Co-authored-by: Kwonhyukjoon <[email protected]>
  • Loading branch information
Kwonhyukjoon and Kwonhyukjoon authored May 18, 2023
1 parent ed553c4 commit 11e935a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Cosmostation/Base/BaseNetWork.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand All @@ -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 ""
Expand Down
10 changes: 3 additions & 7 deletions Cosmostation/Controller/Main/MainTabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
32 changes: 25 additions & 7 deletions Cosmostation/Controller/Main/kava/HardDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSDictionary> {
if let coinsDic = responseResult[0].object(forKey: "coins") as? Array<NSDictionary> {
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<NSDictionary>,
let address = responseResult[0].object(forKey: "address") as? String {
self.mFetchCnt = self.mFetchCnt + 1
self.onFetchBalance_gRPC(address)
}

case .failure(let error):
Expand Down Expand Up @@ -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() });
}
}
}
14 changes: 1 addition & 13 deletions Cosmostation/Model/KavaModel/KavaIncentiveReward.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<HardClaim> = Array<HardClaim>()
var usdx_minting_claims: Array<UsdxMintingClaim> = Array<UsdxMintingClaim>()
Expand All @@ -28,7 +16,7 @@ public struct IncentiveReward {
var earn_claims: Array<EarnClaim> = Array<EarnClaim>()

init(_ dictionary: NSDictionary?) {
if let rawHardClaims = dictionary?["hard_claims"] as? Array<NSDictionary> {
if let rawHardClaims = dictionary?["hard_liquidity_provider_claims"] as? Array<NSDictionary> {
for rawHardClaim in rawHardClaims {
self.hard_claims.append(HardClaim(rawHardClaim))
}
Expand Down

0 comments on commit 11e935a

Please sign in to comment.