Skip to content
Open
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
17 changes: 0 additions & 17 deletions frontend/app/.env

This file was deleted.

36 changes: 24 additions & 12 deletions frontend/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { QueryClient, QueryClientProvider } from 'react-query';
import { ChakraProvider } from '@chakra-ui/react';
import { WalletProvider } from './wallet/walletContext';
import { WalletInterface } from './interfaces';
import { initTezos, setWalletProvider } from './contracts/client';
import { APP_NAME, NETWORK, RPC_URL, RPC_PORT, CTEZ_ADDRESS } from './utils/globals';
import { setWalletProvider } from './contracts/client';
import { APP_NAME, NETWORK, CTEZ_ADDRESS } from './utils/globals';
import { getBeaconInstance, isWalletConnected } from './wallet';
import { AppRouter } from './router';
import { initCTez } from './contracts/ctez';
import { logger } from './utils/logger';
import { getNodePort, getNodeURL } from './utils/settingUtils';
import { initializeRpcUrl } from './utils/rpcManager';
import ModalContainer from './components/modals/ModalContainer';
import theme from './theme/theme';
import ErrorBoundary from './components/ErrorBoundary';
Expand All @@ -28,25 +28,37 @@ const App: React.FC = () => {
const walletData = await getBeaconInstance(APP_NAME, true, NETWORK);
walletData?.wallet && setWalletProvider(walletData.wallet);
walletData && setWallet(walletData);
return walletData;
}
return null;
};

const nodeUrl = wallet.pkh ? getNodeURL(wallet.pkh) : RPC_URL;
const nodePort = wallet.pkh ? getNodePort(wallet.pkh) : RPC_PORT;

useEffect(() => {
const setup = async () => {
try {
initTezos(nodeUrl ?? RPC_URL, nodePort ?? RPC_PORT);
await checkWalletConnection();
CTEZ_ADDRESS && (await initCTez(CTEZ_ADDRESS));
CFMM_ADDRESS && (await initCfmm(CFMM_ADDRESS));
const walletData = await checkWalletConnection();
const walletAddress = walletData?.pkh || wallet.pkh;
const nodeUrl = initializeRpcUrl(walletAddress);

if (nodeUrl && (nodeUrl.startsWith('http://') || nodeUrl.startsWith('https://'))) {

if (CTEZ_ADDRESS) {
await initCTez(CTEZ_ADDRESS);
}

if (CFMM_ADDRESS) {
await initCfmm(CFMM_ADDRESS);
}
} else {
logger.warn('Invalid RPC URL, skipping contract initialization:', nodeUrl);
}
} catch (error: any) {
logger.error(error);
logger.error('Failed to initialize contracts:', error);
}
};

setup();
}, [wallet.pkh, nodeUrl, nodePort]);
}, [wallet.pkh]);

return (
<Suspense fallback="Loading...">
Expand Down
9 changes: 7 additions & 2 deletions frontend/app/src/api/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { sub, format } from 'date-fns';
import { getActualCtezStorage, getUserHalfDexLqtBalance } from '../contracts/ctez';
import { getCtezFa12TotalSupply } from '../contracts/fa12';
import { BaseStats, CTezStorage, CTezTzktStorage, OvenBalance, UserLQTData } from '../interfaces';
import { CTEZ_CONTRACT_BIGMAP, RPC_URL } from '../utils/globals';
import { getCurrentRpcUrl, isRpcInitialized } from '../utils/rpcManager';
import { getOvenCtezOutstandingAndFeeIndex, getUpdatedDexFeeIndex } from '../utils/ovenUtils';
import { getCTezTzktStorage, getLastBlockOfTheDay, getUserOvensAPI } from './tzkt';
import { CTEZ_CONTRACT_BIGMAP } from '../utils/globals';

export const getPrevCTezStorage = async (
days = 7,
Expand All @@ -19,7 +20,11 @@ export const getPrevCTezStorage = async (
return storage;
};
export const getCurrentBlock = async () => {
const response = await axios.get(`${RPC_URL}/chains/main/blocks/head`);
if (!isRpcInitialized()) {
throw new Error('RPC not initialized. Please wait for initialization to complete.');
}
const rpcUrl = getCurrentRpcUrl();
const response = await axios.get(`${rpcUrl}/chains/main/blocks/head`);

return response.data.header.level;
};
Expand Down
7 changes: 5 additions & 2 deletions frontend/app/src/api/queries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AxiosError } from 'axios';
import { useQueries, useQuery } from 'react-query';
import { UseQueryResult } from 'react-query/types/react/types';
import { getCurrentRpcUrl } from '../utils/rpcManager';
import {
getActualCtezStorage,
getAllOvens,
Expand Down Expand Up @@ -48,8 +49,9 @@ export const useCtezBaseStats = (userAddress?: string) => {
};

export const useUserBalance = (userAddress?: string) => {
const rpcUrl = getCurrentRpcUrl();
return useQuery<UserBalance | undefined, AxiosError, UserBalance | undefined>(
[`user-balance-${userAddress}`],
[`user-balance-${userAddress}-${rpcUrl}`],
() => {
if (userAddress) {
return getUserBalance(userAddress);
Expand Down Expand Up @@ -181,8 +183,9 @@ export const useOvenDelegate = (ovenAddress?: string) => {
};

export const useUserLqtData = (userAddress?: string) => {
const rpcUrl = getCurrentRpcUrl();
return useQuery<UserLQTData | undefined, AxiosError, UserLQTData | undefined>(
['userLqtData', userAddress],
['userLqtData', userAddress, rpcUrl],
async () => {
if (userAddress) {
return getUserLQTData(userAddress);
Expand Down
1 change: 1 addition & 0 deletions frontend/app/src/assets/images/icons/settings.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading