Skip to content

Commit

Permalink
✨Fetch aggregator contract addres from github repo
Browse files Browse the repository at this point in the history
  • Loading branch information
MattPoblete committed Sep 24, 2024
1 parent 85e531a commit 8b29f09
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/hooks/useAggregator.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -11,20 +12,23 @@ export const useAggregator = () => {
const [address, setAddress] = useState<string>();
const [isEnabled, setIsAggregatorEnabled] = useState<boolean>(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 };
Expand Down

0 comments on commit 8b29f09

Please sign in to comment.