From 82801b1ef0ca2e1335cdac5c7fa93b6d961e5eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= <105802444+kilted-andres@users.noreply.github.com> Date: Wed, 23 Oct 2024 14:25:14 +0200 Subject: [PATCH] feat: envis for txd and checkout-service URLs (#580) New environment variables: REACT_APP_CHECKOUT_URL REACT_APP_TXD_URL --- .env.example | 2 ++ src/Utils/useTXDTransmitter.ts | 36 ++++++++++++---------------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/.env.example b/.env.example index fff208c3..87e12c50 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,6 @@ REACT_APP_CHAIN_ENDPOINT=wss://peregrine.kilt.io REACT_APP_UNIRESOLVER_ENDPOINT=https://dev-uniresolver.kilt.io +REACT_APP_CHECKOUT_URL=https://dev-checkout.kilt.io +REACT_APP_TXD_URL=https://txd-dev.trusted-entity.io REACT_APP_MAINTENANCE=false REACT_APP_IS_TEST_ENV=false diff --git a/src/Utils/useTXDTransmitter.ts b/src/Utils/useTXDTransmitter.ts index 99f567e1..e5a3925a 100644 --- a/src/Utils/useTXDTransmitter.ts +++ b/src/Utils/useTXDTransmitter.ts @@ -3,24 +3,15 @@ import ky from 'ky'; import { type KiltAddress } from '@kiltprotocol/sdk-js'; -import { endpoint } from './claimWeb3name-helpers'; - -const txdUrls: Record = { - 'wss://kilt-rpc.dwellir.com': 'https://txd.trusted-entity.io', - 'wss://spiritnet.kilt.io': 'https://txd.trusted-entity.io', - 'wss://spiritnet.api.onfinality.io/public-ws': - 'https://txd.trusted-entity.io', - 'wss://peregrine.kilt.io': 'https://dev.txd.trusted-entity.io', - 'wss://peregrine-stg.kilt.io/para': 'https://smoke.txd.trusted-entity.io', -}; +export const checkoutServiceURL = process.env.REACT_APP_CHECKOUT_URL as string; +if (!checkoutServiceURL) { + throw new Error('No URL for the Checkout Service provided.'); +} -const checkoutUrls: Record = { - 'wss://kilt-rpc.dwellir.com': 'https://checkout.kilt.io', - 'wss://spiritnet.kilt.io': 'https://checkout.kilt.io', - 'wss://spiritnet.api.onfinality.io/public-ws': 'https://checkout.kilt.io', - 'wss://peregrine.kilt.io': 'https://dev.checkout.kilt.io', - 'wss://peregrine-stg.kilt.io/para': 'https://smoke.checkout.kilt.io', -}; +const txdUrl = process.env.REACT_APP_TXD_URL as string; +if (!txdUrl) { + throw new Error('No URL for the Transaction Daemon provided.'); +} function useApi(key: Key) { return useSWR( @@ -29,15 +20,12 @@ function useApi(key: Key) { ); } -export const checkoutServiceURL = checkoutUrls[endpoint]; - -export function useApiTXDAddress() { - const txdUrl = txdUrls[endpoint]; - return useApi<{ paymentAddress: KiltAddress }>(`${txdUrl}/meta`); -} - export function useApiTXDCosts() { return useApi<{ did: string; w3n: string }>( `${checkoutServiceURL}/api/costs`, ); } + +export function useApiTXDAddress() { + return useApi<{ paymentAddress: KiltAddress }>(`${txdUrl}/meta`); +}