diff --git a/src/__swaps__/screens/Swap/components/SwapInputAsset.tsx b/src/__swaps__/screens/Swap/components/SwapInputAsset.tsx index decbb93c326..35c33bfbe75 100644 --- a/src/__swaps__/screens/Swap/components/SwapInputAsset.tsx +++ b/src/__swaps__/screens/Swap/components/SwapInputAsset.tsx @@ -83,8 +83,6 @@ function SwapInputAmount() { } function SwapInputIcon() { - const { internalSelectedInputAsset } = useSwapContext(); - return ( @@ -93,7 +91,7 @@ function SwapInputIcon() { } function InputAssetBalanceBadge() { - const { internalSelectedInputAsset } = useSwapContext(); + const { internalSelectedInputAsset, SwapInputController } = useSwapContext(); const label = useDerivedValue(() => { const asset = internalSelectedInputAsset.value; @@ -103,7 +101,11 @@ function InputAssetBalanceBadge() { return asset ? balance : TOKEN_TO_SWAP_LABEL; }); - return ; + return ( + + + + ); } export function SwapInputAsset() { diff --git a/src/__swaps__/screens/Swap/components/SwapOutputAsset.tsx b/src/__swaps__/screens/Swap/components/SwapOutputAsset.tsx index b5c78909528..41006a54686 100644 --- a/src/__swaps__/screens/Swap/components/SwapOutputAsset.tsx +++ b/src/__swaps__/screens/Swap/components/SwapOutputAsset.tsx @@ -13,9 +13,9 @@ import { SwapActionButton } from '@/__swaps__/screens/Swap/components/SwapAction import { SwapInput } from '@/__swaps__/screens/Swap/components/SwapInput'; import { TokenList } from '@/__swaps__/screens/Swap/components/TokenList/TokenList'; import { BASE_INPUT_WIDTH, INPUT_INNER_WIDTH, INPUT_PADDING, THICK_BORDER_WIDTH } from '@/__swaps__/screens/Swap/constants'; +import { IS_ANDROID, IS_IOS } from '@/env'; import { useSwapContext } from '@/__swaps__/screens/Swap/providers/swap-provider'; import { ChainId } from '@/__swaps__/types/chains'; -import { IS_ANDROID, IS_IOS } from '@/env'; import * as i18n from '@/languages'; import { useNavigation } from '@/navigation'; import Routes from '@/navigation/routesNames'; diff --git a/src/__swaps__/screens/Swap/components/SwapSlider.tsx b/src/__swaps__/screens/Swap/components/SwapSlider.tsx index 2eb044d56c2..5919a88da4b 100644 --- a/src/__swaps__/screens/Swap/components/SwapSlider.tsx +++ b/src/__swaps__/screens/Swap/components/SwapSlider.tsx @@ -22,7 +22,7 @@ import { SPRING_CONFIGS, TIMING_CONFIGS } from '@/components/animations/animatio import { AnimatedText, Bleed, Box, Column, Columns, Inline, globalColors, useColorMode, useForegroundColor } from '@/design-system'; import { IS_IOS } from '@/env'; import { triggerHapticFeedback } from '@/screens/points/constants'; -import { equalWorklet, greaterThanWorklet } from '@/__swaps__/safe-math/SafeMath'; +import { greaterThanWorklet } from '@/__swaps__/safe-math/SafeMath'; import { SCRUBBER_WIDTH, SLIDER_COLLAPSED_HEIGHT, @@ -418,29 +418,7 @@ export const SwapSlider = ({ { - 'worklet'; - SwapInputController.inputMethod.value = 'slider'; - - const currentInputValue = SwapInputController.inputValues.value.inputAmount; - const maxSwappableAmount = internalSelectedInputAsset.value?.maxSwappableAmount; - - const isAlreadyMax = maxSwappableAmount ? equalWorklet(currentInputValue, maxSwappableAmount) : false; - const exceedsMax = maxSwappableAmount ? greaterThanWorklet(currentInputValue, maxSwappableAmount) : false; - - if (isAlreadyMax) { - runOnJS(triggerHapticFeedback)('impactMedium'); - } else { - SwapInputController.quoteFetchingInterval.stop(); - if (exceedsMax) sliderXPosition.value = width * 0.999; - - sliderXPosition.value = withSpring(width, SPRING_CONFIGS.snappySpringConfig, isFinished => { - if (isFinished) { - runOnJS(onChangeWrapper)(1); - } - }); - } - }} + onPressWorklet={SwapInputController.setValueToMaxSwappableAmount} style={{ margin: -12, padding: 12 }} ref={maxButtonRef} > diff --git a/src/__swaps__/screens/Swap/hooks/useSwapInputsController.ts b/src/__swaps__/screens/Swap/hooks/useSwapInputsController.ts index 2ccf4a5167c..3b697a4c466 100644 --- a/src/__swaps__/screens/Swap/hooks/useSwapInputsController.ts +++ b/src/__swaps__/screens/Swap/hooks/useSwapInputsController.ts @@ -28,6 +28,8 @@ import { queryClient } from '@/react-query'; import { useAccountSettings } from '@/hooks'; import { analyticsV2 } from '@/analytics'; import { divWorklet, equalWorklet, greaterThanWorklet, isNumberStringWorklet, mulWorklet } from '@/__swaps__/safe-math/SafeMath'; +import { SPRING_CONFIGS } from '@/components/animations/animationConfigs'; +import { triggerHapticFeedback } from '@/screens/points/constants'; function getInputValuesForSliderPositionWorklet({ selectedInputAsset, @@ -561,6 +563,36 @@ export function useSwapInputsController({ { leading: false, trailing: true } ); + const setValueToMaxSwappableAmount = () => { + 'worklet'; + + const currentInputValue = inputValues.value.inputAmount; + const maxSwappableAmount = internalSelectedInputAsset.value?.maxSwappableAmount; + if (!maxSwappableAmount || equalWorklet(maxSwappableAmount, 0)) { + runOnJS(triggerHapticFeedback)('impactMedium'); + return; + } + + const isAlreadyMax = maxSwappableAmount ? equalWorklet(currentInputValue, maxSwappableAmount) : false; + const exceedsMax = maxSwappableAmount ? greaterThanWorklet(currentInputValue, maxSwappableAmount) : false; + if (isAlreadyMax) { + runOnJS(triggerHapticFeedback)('impactMedium'); + return; + } + + quoteFetchingInterval.stop(); + isQuoteStale.value = 1; + inputMethod.value = 'slider'; + + if (exceedsMax) sliderXPosition.value = SLIDER_WIDTH * 0.999; + + sliderXPosition.value = withSpring(SLIDER_WIDTH, SPRING_CONFIGS.snappySpringConfig, isFinished => { + if (isFinished) { + runOnJS(onChangedPercentage)(1); + } + }); + }; + const resetValuesToZeroWorklet = (inputKey?: inputKeys) => { 'worklet'; quoteFetchingInterval.stop(); @@ -889,5 +921,6 @@ export function useSwapInputsController({ quoteFetchingInterval, fetchQuoteAndAssetPrices, setQuote, + setValueToMaxSwappableAmount, }; }