Skip to content

Commit

Permalink
check for nil response data
Browse files Browse the repository at this point in the history
  • Loading branch information
jonator committed Sep 18, 2024
1 parent 8956a00 commit f94aa6d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/server/src/queries/complex/assets/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function makeMarketActivityFromTokenData(tokenData: TokenData) {
: undefined,
denom: tokenData.denom,
symbol: tokenData.symbol,
liquidity: new PricePretty(DEFAULT_VS_CURRENCY, tokenData.liquidity),
liquidity: new PricePretty(DEFAULT_VS_CURRENCY, tokenData.liquidity ?? 0),
liquidity24hChange:
tokenData.liquidity_24h_change !== null
? new RatePretty(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Dec } from "@keplr-wallet/unit";
import { Asset } from "@osmosis-labs/types";
import { isNil } from "@osmosis-labs/utils";
import cachified, { CacheEntry } from "cachified";
import { LRUCache } from "lru-cache";

Expand Down Expand Up @@ -30,8 +31,8 @@ function getBatchLoader() {
ttl: 1000 * 60 * 10, // 10 minutes
getFreshValue: () =>
new EdgeDataLoader(
(coinMinimalDenoms: readonly string[]) => {
return queryPrices(coinMinimalDenoms as string[]).then((priceMap) =>
(coinMinimalDenoms: readonly string[]) =>
queryPrices(coinMinimalDenoms as string[]).then((priceMap) =>
coinMinimalDenoms.map((baseCoinMinimalDenom) => {
try {
const price =
Expand All @@ -40,6 +41,12 @@ function getBatchLoader() {
// trim to 18 decimals to silence Dec warnings
const p = price.replace(/(\.\d{18})\d*/, "$1");

if (isNil(p)) {
return new Error(
`No SQS price result for ${baseCoinMinimalDenom} and USDC`
);
}

if (new Dec(p).isZero())
return new Error(
`No SQS price result for ${baseCoinMinimalDenom} and USDC`
Expand All @@ -51,8 +58,7 @@ function getBatchLoader() {
);
}
})
);
},
),
{
// SQS imposes a limit on URI length from its Nginx configuration, so we impose a limit to avoid hitting that limit.
maxBatchSize: 100,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/queries/data-services/token-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface TokenData {
denom: string;
symbol: string;
main: boolean;
liquidity: number;
liquidity: number | null;
liquidity_24h_change: number | null;
volume_24h: number;
volume_24h_change: number | null;
Expand Down

0 comments on commit f94aa6d

Please sign in to comment.