From df65d40504091c438ab3689e0ac8679780867b80 Mon Sep 17 00:00:00 2001 From: esteblock Date: Wed, 18 Sep 2024 12:33:56 -0300 Subject: [PATCH] fix now sdex is default true and when protocolls change in settings, the trade gets reset --- src/functions/generateRoute.ts | 14 +++++++++++--- src/hooks/useBestTrade.ts | 5 +++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/functions/generateRoute.ts b/src/functions/generateRoute.ts index 6508da6c..c47cd26f 100644 --- a/src/functions/generateRoute.ts +++ b/src/functions/generateRoute.ts @@ -42,6 +42,7 @@ export interface GenerateRouteProps { quoteAsset: TokenType; amount: string; tradeType: TradeType; + currentProtocolsStatus: { key: string; value: boolean }[]; } const queryNetworkDict: { [x: string]: 'MAINNET' | 'TESTNET' } = { @@ -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; } @@ -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 }, ]; } } @@ -162,6 +168,7 @@ export const useRouterSDK = () => { quoteAsset, amount, tradeType, + currentProtocolsStatus, }: GenerateRouteProps) => { if (!factory) throw new Error('Factory address not found'); const currencyAmount = fromAddressAndAmountToCurrencyAmount( @@ -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, diff --git a/src/hooks/useBestTrade.ts b/src/hooks/useBestTrade.ts index 63c37c88..33a5e459 100644 --- a/src/hooks/useBestTrade.ts +++ b/src/hooks/useBestTrade.ts @@ -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, @@ -57,6 +57,7 @@ export function useBestTrade( tradeType === TradeType.EXACT_INPUT ? SdkTradeType.EXACT_INPUT : SdkTradeType.EXACT_OUTPUT, + currentProtocolsStatus: protocolsStatus, }), { revalidateIfStale: true,