diff --git a/src/__swaps__/screens/Swap/navigateToSwaps.ts b/src/__swaps__/screens/Swap/navigateToSwaps.ts index c50749e0d95..764a090f429 100644 --- a/src/__swaps__/screens/Swap/navigateToSwaps.ts +++ b/src/__swaps__/screens/Swap/navigateToSwaps.ts @@ -1,12 +1,15 @@ import { GasSpeed } from '@/__swaps__/types/gas'; import { Navigation } from '@/navigation'; import store from '@/redux/store'; -import { SwapsState, useSwapsStore } from '@/state/swaps/swapsStore'; +import { SwapsState, swapsStore, useSwapsStore } from '@/state/swaps/swapsStore'; import { setSelectedGasSpeed } from './hooks/useSelectedGas'; import { enableActionsOnReadOnlyWallet } from '@/config'; import walletTypes from '@/helpers/walletTypes'; import { watchingAlert } from '@/utils'; import Routes from '@/navigation/routesNames'; +import { getDefaultSlippage, slippageInBipsToString } from '@/__swaps__/utils/swaps'; +import { ChainId } from '@/state/backendNetworks/types'; +import { getRemoteConfig } from '@/model/remoteConfig'; export type SwapsParams = Partial< Pick & { @@ -38,18 +41,27 @@ const getInputMethod = (params: SwapsParams) => { return 'inputAmount'; }; export function getSwapsNavigationParams() { + const state = useSwapsStore.getState(); const params = (Navigation.getActiveRoute().params || {}) as SwapsParams; const inputMethod = getInputMethod(params); + const inputAsset = params.inputAsset || state.inputAsset; + const outputAsset = params.outputAsset || state.outputAsset; + const chainId = inputAsset?.chainId || ChainId.mainnet; const lastTypedInput = inputMethod === 'slider' ? 'inputAmount' : inputMethod; + const slippage = + params.slippage && !isNaN(+params.slippage) ? slippageInBipsToString(+params.slippage) : getDefaultSlippage(chainId, getRemoteConfig()); + + // Set the slippage in the swaps store to keep it in sync with the initial value + swapsStore.getState().setSlippage(slippage); - const state = useSwapsStore.getState(); return { inputMethod, lastTypedInput, focusedInput: lastTypedInput, - inputAsset: params.inputAsset || state.inputAsset, - outputAsset: params.outputAsset || state.outputAsset, + inputAsset, + outputAsset, + slippage, ...params, } as const; } diff --git a/src/__swaps__/screens/Swap/providers/swap-provider.tsx b/src/__swaps__/screens/Swap/providers/swap-provider.tsx index a1637a2dd40..16402af4fe6 100644 --- a/src/__swaps__/screens/Swap/providers/swap-provider.tsx +++ b/src/__swaps__/screens/Swap/providers/swap-provider.tsx @@ -26,7 +26,7 @@ import { userAssetsQueryKey } from '@/__swaps__/screens/Swap/resources/assets/us import { AddressOrEth, ExtendedAnimatedAssetWithColors, ParsedSearchAsset } from '@/__swaps__/types/assets'; import { ChainId } from '@/state/backendNetworks/types'; import { SwapAssetType, inputKeys } from '@/__swaps__/types/swap'; -import { clamp, getDefaultSlippageWorklet, parseAssetAndExtend } from '@/__swaps__/utils/swaps'; +import { clamp, parseAssetAndExtend } from '@/__swaps__/utils/swaps'; import { analyticsV2 } from '@/analytics'; import { LegacyTransactionGasParamAmounts, TransactionGasParamAmounts } from '@/entities'; import { getProvider } from '@/handlers/web3'; @@ -49,13 +49,11 @@ import { haptics } from '@/utils'; import { CrosschainQuote, Quote, QuoteError, SwapType } from '@rainbow-me/swaps'; import { IS_IOS } from '@/env'; -import { Address } from 'viem'; import { clearCustomGasSettings } from '../hooks/useCustomGas'; import { getGasSettingsBySpeed, getSelectedGas } from '../hooks/useSelectedGas'; import { useSwapOutputQuotesDisabled } from '../hooks/useSwapOutputQuotesDisabled'; import { SyncGasStateToSharedValues, SyncQuoteSharedValuesToState } from './SyncSwapStateAndSharedValues'; import { performanceTracking, Screens, TimeToSignOperation } from '@/state/performance/performance'; -import { getRemoteConfig } from '@/model/remoteConfig'; import { useConnectedToAnvilStore } from '@/state/connectedToAnvil'; import { useBackendNetworksStore, getChainsNativeAssetWorklet } from '@/state/backendNetworks/backendNetworks'; import { getSwapsNavigationParams } from '../navigateToSwaps'; @@ -191,7 +189,7 @@ export const SwapProvider = ({ children }: SwapProviderProps) => { ); const configProgress = useSharedValue(NavigationSteps.INPUT_ELEMENT_FOCUSED); - const slippage = useSharedValue(getDefaultSlippageWorklet(initialSelectedInputAsset?.chainId || ChainId.mainnet, getRemoteConfig())); + const slippage = useSharedValue(initialValues.slippage); const hasEnoughFundsForGas = useSharedValue(undefined);