Skip to content

Commit

Permalink
fix: asset service
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Oct 17, 2022
1 parent 938a71b commit 5968d23
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/sdk-ui-ts/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 2 additions & 2 deletions packages/sdk-ui-ts/src/token/TokenPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -165,7 +165,7 @@ export class TokenPrice {

private async initCache(): Promise<void> {
try {
const pricesResponse = (await this.httpClient.get('price', {
const pricesResponse = (await this.httpClient.get('coin/price', {
coinIds: commonlyUsedCoinGeckoIds.join(','),
currency: 'usd',
})) as {
Expand Down
16 changes: 15 additions & 1 deletion packages/token-utils/src/asset-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 5968d23

Please sign in to comment.