Skip to content

Commit

Permalink
refactor(frontend): Blockstream API URL is hard-coded (#3266)
Browse files Browse the repository at this point in the history
# Motivation

The Blockstream API URL can be hard-coded since it is constant
throughout the envs.
  • Loading branch information
AntonioVentilii-DFINITY authored Nov 4, 2024
1 parent f7e7e2c commit 0acd9ac
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ VITE_ALCHEMY_API_KEY=
VITE_WALLET_CONNECT_PROJECT_ID=
VITE_OISY_URL=https://oisy.com
VITE_COINGECKO_API_KEY=
VITE_BLOCKSTREAM_API_URL=https://blockstream.info/api
VITE_EXCHANGE_DISABLED=true
VITE_JUNO_SATELLITE_ID=
VITE_JUNO_ORBITER_ID=
Expand Down
1 change: 0 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ VITE_INFURA_API_KEY=
VITE_ALCHEMY_API_KEY=
VITE_WALLET_CONNECT_PROJECT_ID=
VITE_OISY_URL=https://oisy.com
VITE_BLOCKSTREAM_API_URL=https://blockstream.info/api
VITE_JUNO_SATELLITE_ID=
VITE_JUNO_ORBITER_ID=
2 changes: 0 additions & 2 deletions .github/workflows/deploy-to-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ jobs:
echo "VITE_AUTH_ALTERNATIVE_ORIGINS=${{ secrets.VITE_AUTH_ALTERNATIVE_ORIGINS_STAGING }}" >> $GITHUB_ENV
echo "VITE_AUTH_DERIVATION_ORIGIN=${{ secrets.VITE_AUTH_DERIVATION_ORIGIN_STAGING }}" >> $GITHUB_ENV
echo "VITE_BTC_TO_CKBTC_EXCHANGE_ENABLED=${{ secrets.VITE_BTC_TO_CKBTC_EXCHANGE_ENABLED_STAGING }}" >> $GITHUB_ENV
echo "VITE_BLOCKSTREAM_API_URL=https://blockstream.info/api" >> $GITHUB_ENV
echo "VITE_ONRAMPER_API_KEY_DEV=${{ secrets.VITE_ONRAMPER_API_KEY_DEV_STAGING }}" >> $GITHUB_ENV
echo "VITE_ONRAMPER_API_KEY_PROD=${{ secrets.VITE_ONRAMPER_API_KEY_PROD_STAGING }}" >> $GITHUB_ENV
{
Expand All @@ -102,7 +101,6 @@ jobs:
echo "VITE_AUTH_ALTERNATIVE_ORIGINS=${{ secrets.VITE_AUTH_ALTERNATIVE_ORIGINS_BETA }}" >> $GITHUB_ENV
echo "VITE_AUTH_DERIVATION_ORIGIN=${{ secrets.VITE_AUTH_DERIVATION_ORIGIN_BETA }}" >> $GITHUB_ENV
echo "VITE_BTC_TO_CKBTC_EXCHANGE_ENABLED=${{ secrets.VITE_BTC_TO_CKBTC_EXCHANGE_ENABLED_BETA }}" >> $GITHUB_ENV
echo "VITE_BLOCKSTREAM_API_URL=https://blockstream.info/api" >> $GITHUB_ENV
echo "VITE_ONRAMPER_API_KEY_DEV=${{ secrets.VITE_ONRAMPER_API_KEY_DEV_BETA }}" >> $GITHUB_ENV
echo "VITE_ONRAMPER_API_KEY_PROD=${{ secrets.VITE_ONRAMPER_API_KEY_PROD_BETA }}" >> $GITHUB_ENV
{
Expand Down
7 changes: 7 additions & 0 deletions src/frontend/src/env/rest/blockstream.env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { UrlSchema } from '$lib/validation/url.validation';
import { safeParse } from '$lib/validation/utils.validation';

export const BLOCKSTREAM_API_URL = safeParse({
schema: UrlSchema,
value: 'https://blockstream.info/api'
});
4 changes: 2 additions & 2 deletions src/frontend/src/lib/rest/blockstream.rest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const API_URL = import.meta.env.VITE_BLOCKSTREAM_API_URL;
import { BLOCKSTREAM_API_URL } from '$env/rest/blockstream.env';

/**
* Get latest mined BTC block height. Used for calculating the number of confirmations for a BTC transaction.
Expand All @@ -13,7 +13,7 @@ export const btcLatestBlockHeight = (): Promise<number> =>
});

const fetchBlockstreamApi = async <T>({ endpointPath }: { endpointPath: string }): Promise<T> => {
const response = await fetch(`${API_URL}/${endpointPath}`);
const response = await fetch(`${BLOCKSTREAM_API_URL}/${endpointPath}`);

if (!response.ok) {
throw new Error('Blockstream API response not ok.');
Expand Down

0 comments on commit 0acd9ac

Please sign in to comment.