Skip to content

Commit

Permalink
feat: envis for txd and checkout-service URLs (#580)
Browse files Browse the repository at this point in the history
New environment variables:

REACT_APP_CHECKOUT_URL
REACT_APP_TXD_URL
  • Loading branch information
kilted-andres authored Oct 23, 2024
1 parent bfbb8f1 commit 82801b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
36 changes: 12 additions & 24 deletions src/Utils/useTXDTransmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,15 @@ import ky from 'ky';

import { type KiltAddress } from '@kiltprotocol/sdk-js';

import { endpoint } from './claimWeb3name-helpers';

const txdUrls: Record<string, string> = {
'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<string, string> = {
'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<Output>(key: Key) {
return useSWR<Output, string | Error>(
Expand All @@ -29,15 +20,12 @@ function useApi<Output>(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`);
}

0 comments on commit 82801b1

Please sign in to comment.