From 7f38085f34fe12dc1c30351431f1c94a558e62d6 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Sat, 30 Mar 2024 12:50:07 -0300 Subject: [PATCH] Fix: isistrade return can be null --- package.json | 2 +- src/connectors/isistrade.ts | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index a15a1ec..ea7cb79 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@coinsamba/js-exchanges-connector", "description": "Collection of JavaScript implementations of cryptocurrency exchange APIs", - "version": "2.1.16", + "version": "2.1.17", "repository": "git@github.com:coinsambacom/js-exchanges-connector.git", "author": "Gustavo ", "license": "MIT", diff --git a/src/connectors/isistrade.ts b/src/connectors/isistrade.ts index 81779ea..c61eaa4 100644 --- a/src/connectors/isistrade.ts +++ b/src/connectors/isistrade.ts @@ -8,7 +8,7 @@ import { parseBRLNumberString } from "../utils/utils"; interface BaseRes { success: boolean; message: string; - result: T; + result: T | null; } interface IsisTradeOrderbookOrder { @@ -49,15 +49,17 @@ export class isistrade extends Exchange { > >(`${this.baseUrl}/public/marketsummaries?basemarket=${quote}`); - return res.result.map((t) => ({ - exchangeId: this.id, - base: t.marketAsset, - quote: t.baseAsset, - ask: parseBRLNumberString(t.ask), - bid: parseBRLNumberString(t.bid), - last: parseBRLNumberString(t.last), - vol: parseBRLNumberString(t.volume), - })); + return ( + res.result?.map((t) => ({ + exchangeId: this.id, + base: t.marketAsset, + quote: t.baseAsset, + ask: parseBRLNumberString(t.ask), + bid: parseBRLNumberString(t.bid), + last: parseBRLNumberString(t.last), + vol: parseBRLNumberString(t.volume), + })) ?? [] + ); } private parseOrder({ @@ -81,8 +83,8 @@ export class isistrade extends Exchange { ); return { - asks: res.result.sell.map(this.parseOrder), - bids: res.result.buy.map(this.parseOrder), + asks: res.result?.sell.map(this.parseOrder) ?? [], + bids: res.result?.buy.map(this.parseOrder) ?? [], }; } }