From ecb1dc3a656d30b32ae8f820d113701eca5ceb46 Mon Sep 17 00:00:00 2001 From: Thunnini Date: Tue, 20 Apr 2021 17:02:47 +0900 Subject: [PATCH] Temporary fix for the sifchain #84 #81 --- .../src/query/cosmos/supply/inflation.ts | 97 ++++++++++--------- 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/packages/stores/src/query/cosmos/supply/inflation.ts b/packages/stores/src/query/cosmos/supply/inflation.ts index c6839ef143..fb20259d9f 100644 --- a/packages/stores/src/query/cosmos/supply/inflation.ts +++ b/packages/stores/src/query/cosmos/supply/inflation.ts @@ -41,56 +41,65 @@ export class ObservableQueryInflation { // If the staking pool info is fetched, this will consider this info for calculating the more accurate value. @computed get inflation(): IntPretty { - let dec: Dec | undefined; + try { + let dec: Dec | undefined; - // XXX: Hard coded part for the iris hub and sifchain. - // TODO: Remove this part. - const chainInfo = this.chainGetter.getChain(this.chainId); - if (chainInfo.chainId.startsWith("irishub")) { - dec = new Dec( - this._queryIrisMint.response?.data.result.inflation ?? "0" - ).mul(DecUtils.getPrecisionDec(2)); - } else if (chainInfo.chainId.startsWith("sifchain")) { - return new IntPretty( - new Dec(this._querySifchainAPY.liquidityAPY.toString()) - ); - } else { - dec = new Dec(this._queryMint.response?.data.result ?? "0").mul( - DecUtils.getPrecisionDec(2) - ); - } + // XXX: Hard coded part for the iris hub and sifchain. + // TODO: Remove this part. + const chainInfo = this.chainGetter.getChain(this.chainId); + if (chainInfo.chainId.startsWith("irishub")) { + dec = new Dec( + this._queryIrisMint.response?.data.result.inflation ?? "0" + ).mul(DecUtils.getPrecisionDec(2)); + } else if (chainInfo.chainId.startsWith("sifchain")) { + return new IntPretty( + new Dec(this._querySifchainAPY.liquidityAPY.toString()) + ); + } else { + dec = new Dec(this._queryMint.response?.data.result ?? "0").mul( + DecUtils.getPrecisionDec(2) + ); + } - if (!dec || dec.equals(new Dec(0))) { - return new IntPretty(new Int(0)).ready(false); - } + if (!dec || dec.equals(new Dec(0))) { + return new IntPretty(new Int(0)).ready(false); + } - if ( - this._queryPool.response && - this._querySupplyTotal.getQueryStakeDenom().response - ) { - const bondedToken = new Dec( - this._queryPool.response.data.result.bonded_tokens - ); - const totalStr = (() => { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const response = this._querySupplyTotal.getQueryStakeDenom().response! - .data.result; + if ( + this._queryPool.response && + this._querySupplyTotal.getQueryStakeDenom().response + ) { + const bondedToken = new Dec( + this._queryPool.response.data.result.bonded_tokens + ); + const totalStr = (() => { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const response = this._querySupplyTotal.getQueryStakeDenom().response! + .data.result; - if (typeof response === "string") { - return response; - } else { - return response.amount; - } - })(); - const total = new Dec(totalStr); - if (total.gt(new Dec(0))) { - const ratio = bondedToken.quo(total); + if (typeof response === "string") { + return response; + } else { + return response.amount; + } + })(); + const total = new Dec(totalStr); + if (total.gt(new Dec(0))) { + const ratio = bondedToken.quo(total); - dec = dec.quo(ratio); - // TODO: Rounding? + dec = dec.quo(ratio); + // TODO: Rounding? + } } - } - return new IntPretty(dec); + return new IntPretty(dec); + } catch (e) { + console.log(e); + // XXX: There have been reported errors regarding Sifchain. + // However, I wasn’t able to reproduce the error so exact cause haven’t been identified. + // For now, use try-catch on suspect parts to resolve the issue. Will be on a lookout for a more permanent solution in the future. + + return new IntPretty(new Int(0)).ready(false); + } } }