Skip to content

Commit

Permalink
feat: replace bitcoin usd price fetch api url (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 authored Feb 14, 2025
1 parent b5978ce commit adfc6f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
18 changes: 7 additions & 11 deletions src/app/hooks/use-bitcoin-price.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import { BitcoinError } from '@models/error-types';
import { useQuery } from '@tanstack/react-query';
import { UseQueryResult, useQuery } from '@tanstack/react-query';

interface UseBitcoinPriceReturnType {
bitcoinPrice: number | undefined;
}

export function useBitcoinPrice(): UseBitcoinPriceReturnType {
export function useBitcoinPrice(): UseQueryResult<number, BitcoinError> {
const fetchBitcoinPrice = async (): Promise<number> => {
try {
const response = await fetch('https://api.coindesk.com/v1/bpi/currentprice.json');
const response = await fetch(
'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd'
);
const data = await response.json();
return data.bpi.USD.rate_float;
return data.bitcoin.usd;
} catch (error) {
throw new BitcoinError(`Error fetching Bitcoin price: ${error}`);
}
};

const { data: bitcoinPrice } = useQuery<number, BitcoinError>({
return useQuery<number, BitcoinError>({
queryKey: ['bitcoinPrice'],
queryFn: fetchBitcoinPrice,
refetchInterval: 60000,
});

return { bitcoinPrice };
}
2 changes: 1 addition & 1 deletion src/app/providers/proof-of-reserve-context-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const ProofOfReserveContext = createContext<ProofOfReserveContextProvider
export function ProofOfReserveContextProvider({ children }: HasChildren): React.JSX.Element {
const proofOfReserve = useProofOfReserve();
const { totalSupply } = useTotalSupply();
const { bitcoinPrice } = useBitcoinPrice();
const { data: bitcoinPrice } = useBitcoinPrice();
const { allMintBurnEvents, merchantMintBurnEvents } = useMintBurnEvents();
const { depositLimit } = useDepositLimits();

Expand Down

0 comments on commit adfc6f9

Please sign in to comment.