Skip to content

Commit

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

The Blockchain API URL can be hard-coded since it is constant throughout
the envs.
  • Loading branch information
AntonioVentilii-DFINITY authored Nov 4, 2024
1 parent 9e67396 commit f7e7e2c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 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_BLOCKCHAIN_API_URL=https://blockchain.info
VITE_BLOCKSTREAM_API_URL=https://blockstream.info/api
VITE_EXCHANGE_DISABLED=true
VITE_JUNO_SATELLITE_ID=
Expand Down
1 change: 0 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ VITE_INFURA_API_KEY=
VITE_ALCHEMY_API_KEY=
VITE_WALLET_CONNECT_PROJECT_ID=
VITE_OISY_URL=https://oisy.com
VITE_BLOCKCHAIN_API_URL=https://blockchain.info
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_BLOCKCHAIN_API_URL=https://blockchain.info" >> $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 @@ -103,7 +102,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_BLOCKCHAIN_API_URL=https://blockchain.info" >> $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/blockchain.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 BLOCKCHAIN_API_URL = safeParse({
schema: UrlSchema,
value: 'https://blockchain.info'
});
5 changes: 2 additions & 3 deletions src/frontend/src/lib/rest/blockchain.rest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BLOCKCHAIN_API_URL } from '$env/rest/blockchain.env';
import type { BitcoinAddressData, BlockchainBtcAddressDataParams } from '$lib/types/blockchain';

const API_URL = import.meta.env.VITE_BLOCKCHAIN_API_URL;

/**
* Get BTC address data (including transactions).
*
Expand All @@ -17,7 +16,7 @@ export const btcAddressData = ({
});

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

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

0 comments on commit f7e7e2c

Please sign in to comment.