Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: envis for txd and checkout-service URLs #580

Merged
merged 6 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use different env for the different deployments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ggera Can you confirm?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unable to override a variable on Amplify at the moment. HODL

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

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`);
}