diff --git a/packages/sdk-ui-ts/src/constants.ts b/packages/sdk-ui-ts/src/constants.ts index 5e3185970..84953ce06 100644 --- a/packages/sdk-ui-ts/src/constants.ts +++ b/packages/sdk-ui-ts/src/constants.ts @@ -68,4 +68,6 @@ export const peggyGraphQlEndpointForNetwork = (network: Network): string => { } export const ASSET_PRICE_SERVICE_URL = - 'https://k8s.mainnet.asset.injective.network/asset-price/v1/coin/' + 'https://k8s.mainnet.asset.injective.network/asset-price/v1' +export const DEVNET_ASSET_PRICE_SERVICE_URL = + 'https://devnet.api.injective.dev/asset-price/v1' diff --git a/packages/sdk-ui-ts/src/token/TokenPrice.ts b/packages/sdk-ui-ts/src/token/TokenPrice.ts index f7ef8f02d..813b2400b 100644 --- a/packages/sdk-ui-ts/src/token/TokenPrice.ts +++ b/packages/sdk-ui-ts/src/token/TokenPrice.ts @@ -70,7 +70,7 @@ export class TokenPrice { } try { - const pricesResponse = (await this.httpClient.get('price', { + const pricesResponse = (await this.httpClient.get('coin/price', { coinIds: coinId, currency: 'usd', })) as { @@ -165,7 +165,7 @@ export class TokenPrice { private async initCache(): Promise { try { - const pricesResponse = (await this.httpClient.get('price', { + const pricesResponse = (await this.httpClient.get('coin/price', { coinIds: commonlyUsedCoinGeckoIds.join(','), currency: 'usd', })) as { diff --git a/packages/token-utils/src/asset-service/index.ts b/packages/token-utils/src/asset-service/index.ts index 0063ad2b0..a7e6d9eea 100644 --- a/packages/token-utils/src/asset-service/index.ts +++ b/packages/token-utils/src/asset-service/index.ts @@ -26,7 +26,21 @@ export class InjectiveAssetService { } } - return pricesResponse.data.data + if (pricesResponse.data.data.length === 0) { + throw new HttpRequestException( + new Error(`The price for ${coinId} could not be fetched`), + ) + } + + const [response] = pricesResponse.data.data + + if (!response) { + throw new HttpRequestException( + new Error(`The price for ${coinId} could not be fetched`), + ) + } + + return response } catch (e: unknown) { throw new HttpRequestException(new Error((e as any).message), { contextModule: 'asset-service',