Skip to content

Commit

Permalink
fix now sdex is default true and when protocolls change in settings,…
Browse files Browse the repository at this point in the history
… the trade gets reset
  • Loading branch information
esteblock committed Sep 18, 2024
1 parent eeb9c7c commit df65d40
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/functions/generateRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface GenerateRouteProps {
quoteAsset: TokenType;
amount: string;
tradeType: TradeType;
currentProtocolsStatus: { key: string; value: boolean }[];
}

const queryNetworkDict: { [x: string]: 'MAINNET' | 'TESTNET' } = {
Expand All @@ -63,9 +64,14 @@ export const useRouterSDK = () => {

const getValuebyKey = (key: string) => {
let value = protocolsStatus.find((p) => p.key === key)?.value;
// Soroswap will be activatewd by defaul
if (value === undefined && key === Protocols.SOROSWAP) {
return true;
}
// SDEX will be activated by defaul
if (value === undefined && key === PlatformType.STELLAR_CLASSIC) {
return true;
}
if (typeof value === 'undefined') {
return false;
}
Expand All @@ -92,7 +98,7 @@ export const useRouterSDK = () => {
return [
{ key: Protocols.SOROSWAP, value: true },
{ key: Protocols.PHOENIX, value: false },
{ key: PlatformType.STELLAR_CLASSIC, value: false },
{ key: PlatformType.STELLAR_CLASSIC, value: true },
];
}
}
Expand Down Expand Up @@ -162,6 +168,7 @@ export const useRouterSDK = () => {
quoteAsset,
amount,
tradeType,
currentProtocolsStatus,
}: GenerateRouteProps) => {
if (!factory) throw new Error('Factory address not found');
const currencyAmount = fromAddressAndAmountToCurrencyAmount(
Expand All @@ -170,8 +177,9 @@ export const useRouterSDK = () => {
);
const quoteCurrency = fromAddressToToken(quoteAsset.contract);

const isHorizonEnabled = isProtocolEnabled(PlatformType.STELLAR_CLASSIC);
const isSoroswapEnabled = isProtocolEnabled(Protocols.SOROSWAP);
const isHorizonEnabled = currentProtocolsStatus.find((p) => p.key === PlatformType.STELLAR_CLASSIC)?.value;

const isSoroswapEnabled = currentProtocolsStatus.find((p) => p.key === Protocols.SOROSWAP)?.value;

const horizonProps = {
assetFrom: amountAsset.currency,
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useBestTrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export function useBestTrade(
isValidating,
} = useSWR(
amountSpecified && otherCurrency
? [amountSpecified, otherCurrency, tradeType, amountSpecified.value, maxHops]
? [amountSpecified, otherCurrency, tradeType, amountSpecified.value, maxHops, protocolsStatus]
: null,
([amountAsset, quoteAsset, tradeType, amount, maxHops]) =>
([amountAsset, quoteAsset, tradeType, amount, maxHops, protocolsStatus]) =>
generateRoute({
amountAsset,
quoteAsset,
Expand All @@ -57,6 +57,7 @@ export function useBestTrade(
tradeType === TradeType.EXACT_INPUT
? SdkTradeType.EXACT_INPUT
: SdkTradeType.EXACT_OUTPUT,
currentProtocolsStatus: protocolsStatus,
}),
{
revalidateIfStale: true,
Expand Down

0 comments on commit df65d40

Please sign in to comment.