Skip to content

Commit

Permalink
feat: add updated api endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Mar 3, 2025
1 parent c31bb20 commit 4ba7e0b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 20 deletions.
6 changes: 2 additions & 4 deletions src/app/hooks/use-mint-burn-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DetailedEvent } from '@models/ethereum-models';
import { Merchant } from '@models/merchant';
import { useQuery } from '@tanstack/react-query';

import { MINT_BURN_EVENTS_API_URL } from '@shared/constants/api.constants';
import { API } from '@shared/constants/api.constants';

interface UseMintBurnEventsReturnType {
allMintBurnEvents: DetailedEvent[] | undefined;
Expand All @@ -12,9 +12,7 @@ interface UseMintBurnEventsReturnType {
export function useMintBurnEvents(): UseMintBurnEventsReturnType {
async function fetchMintBurnEvents(ethereumAddress: string): Promise<DetailedEvent[]> {
try {
const response = await fetch(
`${MINT_BURN_EVENTS_API_URL}/${appConfiguration.appEnvironment}/${ethereumAddress}`
);
const response = await fetch(`${API.MINT_BURN_EVENTS}/${ethereumAddress}`);

if (!response.ok) {
throw new Error(`Error fetching mint burn events`);
Expand Down
6 changes: 2 additions & 4 deletions src/app/hooks/use-points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PointsData } from '@models/points.models';
import { useQuery } from '@tanstack/react-query';
import { useAccount } from 'wagmi';

import { POINTS_API_URL } from '@shared/constants/api.constants';
import { API } from '@shared/constants/api.constants';

interface UsePointsReturnType {
userPoints: PointsData | undefined;
Expand All @@ -13,9 +13,7 @@ export function usePoints(): UsePointsReturnType {

async function fetchUserPoints(): Promise<PointsData | undefined> {
try {
const response = await fetch(
`${POINTS_API_URL}/${appConfiguration.appEnvironment}/${address}`
);
const response = await fetch(`${API.POINTS}/${address}`);

if (!response.ok) {
throw new Error(`Error fetching user: ${address} points`);
Expand Down
8 changes: 4 additions & 4 deletions src/app/hooks/use-proof-of-reserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useQuery } from '@tanstack/react-query';
import { unshiftValue } from 'dlc-btc-lib/utilities';
import { pluck } from 'ramda';

import { PROOF_OF_RESERVE_API_URL } from '@shared/constants/api.constants';
import { API } from '@shared/constants/api.constants';
import { NetworkType } from '@shared/constants/network.constants';

export interface UseProofOfReserveReturnType {
Expand All @@ -25,8 +25,8 @@ export function useProofOfReserve(): UseProofOfReserveReturnType {
async function fetchProofOfReserve(merchantAddress?: string): Promise<number> {
try {
const apiURL = merchantAddress
? `${PROOF_OF_RESERVE_API_URL}/${appConfiguration.appEnvironment}?address=${merchantAddress}`
: `${PROOF_OF_RESERVE_API_URL}/${appConfiguration.appEnvironment}`;
? `${API.PROOF_OF_RESERVE}?address=${merchantAddress}`
: `${API.PROOF_OF_RESERVE}`;

const response = await fetch(apiURL);

Expand Down Expand Up @@ -54,7 +54,7 @@ export function useProofOfReserve(): UseProofOfReserveReturnType {
};

const buildApiUrl = (chainParam: string): string => {
const baseUrl = `${PROOF_OF_RESERVE_API_URL}/${appConfiguration.appEnvironment}`;
const baseUrl = `${API.PROOF_OF_RESERVE}/${appConfiguration.appEnvironment}`;
return `${baseUrl}?chain=${chainParam}`;
};

Expand Down
4 changes: 2 additions & 2 deletions src/app/hooks/use-total-supply.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

import { TOTAL_SUPPLY_API_URL } from '@shared/constants/api.constants';
import { API } from '@shared/constants/api.constants';

interface UseTotalSupplyReturnType {
totalSupply: number | undefined;
Expand All @@ -9,7 +9,7 @@ interface UseTotalSupplyReturnType {
export function useTotalSupply(): UseTotalSupplyReturnType {
const fetchTotalSupply = async () => {
try {
const response = await fetch(`${TOTAL_SUPPLY_API_URL}/${appConfiguration.appEnvironment}`);
const response = await fetch(`${API.TOTAL_SUPPLY}`);

if (!response.ok) {
throw new Error(`Response was not OK: ${response.status}`);
Expand Down
30 changes: 25 additions & 5 deletions src/shared/constants/api.constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
const API_URL = 'https://api.dlc.link';
export const POINTS_API_URL = `${API_URL}/points`;
export const PROOF_OF_RESERVE_API_URL = `${API_URL}/proof-of-reserve`;
export const MINT_BURN_EVENTS_API_URL = `${API_URL}/mint-burn-events`;
export const TOTAL_SUPPLY_API_URL = `${API_URL}/dlcbtc/total-supply`;
import { AppEnvironment } from '@models/configuration';

const BASE_API_URLS = {
[AppEnvironment.MAINNET]: 'https://api.dlc.link',
[AppEnvironment.TESTNET]: 'https://testnet.api.dlc.link',
[AppEnvironment.DEVNET]: 'https://devnet.api.dlc.link',
[AppEnvironment.LOCALHOST]: 'http://localhost:3000',
};

const API_PATHS = {
POINTS: '/v1/points',
PROOF_OF_RESERVE: '/v1/ibtc/proof-of-reserve',
MINT_BURN_EVENTS: '/v1/ibtc/mint-burn-events',
TOTAL_SUPPLY: '/v1/ibtc/total-supply',
};

const getBaseApiUrl = (): string => BASE_API_URLS[appConfiguration.appEnvironment];

export const API = {
BASE: getBaseApiUrl(),
POINTS: `${getBaseApiUrl()}${API_PATHS.POINTS}`,
PROOF_OF_RESERVE: `${getBaseApiUrl()}${API_PATHS.PROOF_OF_RESERVE}`,
MINT_BURN_EVENTS: `${getBaseApiUrl()}${API_PATHS.MINT_BURN_EVENTS}`,
TOTAL_SUPPLY: `${getBaseApiUrl()}${API_PATHS.TOTAL_SUPPLY}`,
};
2 changes: 1 addition & 1 deletion src/shared/models/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum BitcoinNetworkName {
REGTEST = 'regtest',
}

enum AppEnvironment {
export enum AppEnvironment {
MAINNET = 'mainnet',
TESTNET = 'testnet',
DEVNET = 'devnet',
Expand Down

0 comments on commit 4ba7e0b

Please sign in to comment.