Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/core/services/mirrornode/__tests__/unit/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ export const createMockExchangeRateResponse = (
): ExchangeRateResponse => ({
current_rate: {
cent_equivalent: 12,
expiration_time: '2024-01-01T12:00:00.000Z',
expiration_time: 1774962000,
hbar_equivalent: 1,
},
next_rate: {
cent_equivalent: 12,
expiration_time: '2024-01-01T12:00:00.000Z',
expiration_time: 1774965600,
hbar_equivalent: 1,
},
timestamp: '2024-01-01T12:00:00.000Z',
timestamp: '1774958462.794936000',
...overrides,
});

Expand Down
7 changes: 6 additions & 1 deletion src/core/services/mirrornode/hedera-mirrornode-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { handleMirrorNodeErrorResponse } from '@/core/utils/handle-mirror-node-e
import {
AccountAPIResponseSchema,
ContractInfoSchema,
ExchangeRateResponseSchema,
GetAccountsAPIResponseSchema,
NftInfoSchema,
TokenAirdropsResponseSchema,
Expand Down Expand Up @@ -567,7 +568,11 @@ export class HederaMirrornodeServiceDefaultImpl implements HederaMirrornodeServi
);
}

return (await response.json()) as ExchangeRateResponse;
return parseWithSchema(
ExchangeRateResponseSchema,
await response.json(),
'Mirror Node GET /network/exchangerate',
);
} catch (error) {
if (error instanceof CliError) throw error;
throw new NetworkError('Failed to fetch exchange rate', {
Expand Down
14 changes: 14 additions & 0 deletions src/core/services/mirrornode/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type AccountListItemBalance,
type AccountListItemTokenBalance,
type ContractInfo,
type ExchangeRateResponse,
type GetAccountsAPIResponse,
MirrorNodeKeyType,
type NftInfo,
Expand Down Expand Up @@ -231,6 +232,19 @@ export const ContractInfoSchema: z.ZodType<ContractInfo> = z.object({
stake_period_start: nullableStringKey,
});

const exchangeRateBandSchema = z.object({
cent_equivalent: z.number(),
expiration_time: z.number(),
hbar_equivalent: z.number(),
});

export const ExchangeRateResponseSchema: z.ZodType<ExchangeRateResponse> =
z.object({
current_rate: exchangeRateBandSchema,
next_rate: exchangeRateBandSchema,
timestamp: z.string(),
});

const transactionTransferItemSchema: z.ZodType<TransactionTransferItem> =
z.object({
account: z.string(),
Expand Down
4 changes: 2 additions & 2 deletions src/core/services/mirrornode/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ export interface TokenAirdropsResponse {
export interface ExchangeRateResponse {
current_rate: {
cent_equivalent: number;
expiration_time: string;
expiration_time: number;
hbar_equivalent: number;
};
next_rate: {
cent_equivalent: number;
expiration_time: string;
expiration_time: number;
hbar_equivalent: number;
};
timestamp: string;
Expand Down
Loading