diff --git a/src/hooks/useAggregator.tsx b/src/hooks/useAggregator.tsx index 0d6b10e0..71e12c5e 100644 --- a/src/hooks/useAggregator.tsx +++ b/src/hooks/useAggregator.tsx @@ -1,5 +1,6 @@ import { SorobanContextType, useSorobanReact } from '@soroban-react/core'; import { useEffect, useState } from 'react'; +import axios from 'axios'; const shouldUseAggregator = process.env.NEXT_PUBLIC_AGGREGATOR_ENABLED === 'true'; @@ -11,20 +12,23 @@ export const useAggregator = () => { const [address, setAddress] = useState(); const [isEnabled, setIsAggregatorEnabled] = useState(false); - useEffect(() => { - if (!sorobanContext) return; - if (activeChain?.id == 'mainnet') { - //TODO: Add mainnet aggregator address - setAddress('CA4VZX7N577XGPSKDG4RT24CZ6XGR37TM2652SO2AASERVUWP72N4UGZ'); - setIsAggregatorEnabled(false && shouldUseAggregator); - } else if (activeChain?.id == 'testnet') { - setAddress('CA4VZX7N577XGPSKDG4RT24CZ6XGR37TM2652SO2AASERVUWP72N4UGZ'); - setIsAggregatorEnabled(true && shouldUseAggregator); - } else { - setAddress('CA4VZX7N577XGPSKDG4RT24CZ6XGR37TM2652SO2AASERVUWP72N4UGZ'); - setIsAggregatorEnabled(false && shouldUseAggregator); - } + useEffect(() => { + const setAggregatorData = async () => { + if (!sorobanContext) return; + const { data } = await axios.get( + `https://raw.githubusercontent.com/soroswap/aggregator/refs/heads/main/public/${activeChain?.id}.contracts.json` + ).catch((error) => { + console.error('Error fetching aggregator data', error); + console.warn('No address found Aggregator is disabled'); + setIsAggregatorEnabled(false); + return { data: { ids: { aggregator: '' } } }; + }); + const aggregatorAddress = data.ids.aggregator; + setAddress(aggregatorAddress); + setIsAggregatorEnabled(shouldUseAggregator && !!aggregatorAddress); + }; + setAggregatorData(); }, [activeChain?.id, sorobanContext]); return { address, isEnabled };