From 2473ef55d33eda77f048fed86ef41040f9011ed2 Mon Sep 17 00:00:00 2001 From: Kwonhyukjoon Date: Wed, 28 Jun 2023 23:51:46 +0900 Subject: [PATCH] [APP-781] Update neutron vesting amount calculating (#327) --- Cosmostation/Controller/Main/MainTabViewController.swift | 2 +- Cosmostation/Dao/Cw20NeutronVestingRes.swift | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cosmostation/Controller/Main/MainTabViewController.swift b/Cosmostation/Controller/Main/MainTabViewController.swift index e64e12b51..04d0db256 100644 --- a/Cosmostation/Controller/Main/MainTabViewController.swift +++ b/Cosmostation/Controller/Main/MainTabViewController.swift @@ -1242,7 +1242,7 @@ class MainTabViewController: UITabBarController, UITabBarControllerDelegate, Acc } if let response = try? Cosmwasm_Wasm_V1_QueryClient(channel: channel).smartContractState(req, callOptions: BaseNetWork.getCallOptions()).response.wait() { let neutronVesting = try? JSONDecoder().decode(Cw20NeutronVestingRes.self, from: response.data) - BaseData.instance.mNeutronVesting = NSDecimalNumber(string: neutronVesting?.allocated_amount) + BaseData.instance.mNeutronVesting = neutronVesting?.getNeutronVestingAmount() ?? NSDecimalNumber.zero BaseData.instance.mNeutronDuration = neutronVesting?.schedule?.getVestingDuration() } try channel.close().wait() diff --git a/Cosmostation/Dao/Cw20NeutronVestingRes.swift b/Cosmostation/Dao/Cw20NeutronVestingRes.swift index dd748061b..06775dd73 100644 --- a/Cosmostation/Dao/Cw20NeutronVestingRes.swift +++ b/Cosmostation/Dao/Cw20NeutronVestingRes.swift @@ -12,6 +12,13 @@ public struct Cw20NeutronVestingRes : Codable { var allocated_amount: String? var withdrawn_amount: String? var schedule: VestingSchedule? + + func getNeutronVestingAmount() -> NSDecimalNumber { + if (allocated_amount != nil && withdrawn_amount != nil) { + return NSDecimalNumber(string: allocated_amount).subtracting(NSDecimalNumber(string: withdrawn_amount)) + } + return NSDecimalNumber.zero + } } public struct VestingSchedule : Codable {