35 lines
1.2 KiB
JavaScript
Raw Normal View History

const _baseHref = new URL(document.baseURI).pathname;
export const BASE_PATH = _baseHref.endsWith('/') ? _baseHref.slice(0, -1) : _baseHref;
const API_PREFIX = `${BASE_PATH}/api/v1`;
2025-10-17 14:46:44 +02:00
const joinUrl = (...parts) => parts.join('/').replace(/\/{2,}/g, '/');
const encodeHash = (hash) => encodeURIComponent(String(hash));
2025-10-17 14:46:44 +02:00
2025-10-20 15:42:12 +02:00
const HEALTH_ENDPOINT = joinUrl(API_PREFIX, 'health/stream');
2025-10-17 14:46:44 +02:00
const TRANSACTION_DETAIL_BY_HASH = (hash) => joinUrl(API_PREFIX, 'transactions', encodeHash(hash));
2025-10-20 15:42:12 +02:00
const TRANSACTIONS_STREAM = joinUrl(API_PREFIX, 'transactions/stream');
const BLOCK_DETAIL_BY_HASH = (hash) => joinUrl(API_PREFIX, 'blocks', encodeHash(hash));
2025-10-20 15:42:12 +02:00
const BLOCKS_STREAM = joinUrl(API_PREFIX, 'blocks/stream');
const BLOCKS_LIST = (page, pageSize) =>
`${joinUrl(API_PREFIX, 'blocks/list')}?page=${encodeURIComponent(page)}&page-size=${encodeURIComponent(pageSize)}`;
2025-10-20 15:42:12 +02:00
export const API = {
HEALTH_ENDPOINT,
TRANSACTION_DETAIL_BY_HASH,
2025-10-20 15:42:12 +02:00
TRANSACTIONS_STREAM,
BLOCK_DETAIL_BY_HASH,
2025-10-20 15:42:12 +02:00
BLOCKS_STREAM,
BLOCKS_LIST,
2025-10-20 15:42:12 +02:00
};
const BLOCK_DETAIL = (hash) => joinUrl(`${BASE_PATH}/blocks`, encodeHash(hash));
const TRANSACTION_DETAIL = (hash) => joinUrl(`${BASE_PATH}/transactions`, encodeHash(hash));
2025-10-17 14:46:44 +02:00
2025-10-20 15:42:12 +02:00
export const PAGE = {
BLOCK_DETAIL,
TRANSACTION_DETAIL,
};