-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify SwapInputController animated reaction logic for responding to input value changes #5923
Simplify SwapInputController animated reaction logic for responding to input value changes #5923
Conversation
'worklet'; | ||
// If the user enters a new inputAmount, update the slider position ahead of the quote fetch, because | ||
// we can derive the slider position directly from the entered amount. | ||
if (inputKey === 'inputAmount') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code was only used for when the inputKey
is the inputAmount
and is already done on lines 741-752 before the function is called, so it is redundant.
@@ -915,10 +834,13 @@ export function useSwapInputsController({ | |||
const inputNativePrice = internalSelectedInputAsset.value?.nativePrice || internalSelectedInputAsset.value?.price?.value || 0; | |||
const outputNativePrice = internalSelectedOutputAsset.value?.nativePrice || internalSelectedOutputAsset.value?.price?.value || 0; | |||
|
|||
const prevInputNativeValue = inputValues.value.inputNativeValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pulling these variables out for readability as it can get confusing when you've flipped assets that the native price corresponds to the "new" input / output assets while the inputValues correspond to the previous input/output assets.
outputAmount: | ||
outputNativePrice > 0 ? divWorklet(inputValues.value.outputNativeValue, outputNativePrice) : inputValues.value.inputAmount, | ||
outputNativeValue: inputValues.value.outputNativeValue, | ||
inputNativeValue: mulWorklet(newInputAmount, inputNativePrice), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated input/outputNativeValue
to use the mulWorklet
so that it is more precise and based on the new inputAmount and the new native price.
b72db94
to
4884847
Compare
…y used for when the amount is > 0
4884847
to
8570f1f
Compare
…o input value changes (#5923) * Remove redundant sliderXPosition update in debounced onTypedNumber * Remove redundant preservedAmount argument in onTypedNumber as the default is true * Pull out resetToZero as its own worklet to reduce redundant code * Remove unnecessary check for amount > 0 now that onTypedNumber is only used for when the amount is > 0 * Replace onTypedNumber with debouncedFetchQuote function * Pull out variables for prev input / output native values for code readability * Calculate native value based on the new amounts and native prices to be more accurate * Simplify resetToZeroValues logic
* Insufficient Gas * Update bitrise.yml with latest from bitrise.io (#5940) * insufficient native symbol * Prevent crashing on remote cards code (#5924) * Return undefined from cards store if data is missing * deal with undefined card obj --------- Co-authored-by: Christian Baroni <[email protected]> * fix keyboard dismisses option to copy contract address or view on etherscan (#5908) * fix * keyboardShouldPersistTaps * ContextMenuButton * Simplify SwapInputController animated reaction logic for responding to input value changes (#5923) * Remove redundant sliderXPosition update in debounced onTypedNumber * Remove redundant preservedAmount argument in onTypedNumber as the default is true * Pull out resetToZero as its own worklet to reduce redundant code * Remove unnecessary check for amount > 0 now that onTypedNumber is only used for when the amount is > 0 * Replace onTypedNumber with debouncedFetchQuote function * Pull out variables for prev input / output native values for code readability * Calculate native value based on the new amounts and native prices to be more accurate * Simplify resetToZeroValues logic * Convert swap warning to derived value (#5930) * Convert swap warning to derived value * Move out noWarning to NO_WARNING out of derived value * Tidy up swapInputsController repeated logic around `niceIncrementFormatter` (#5931) * Simplify the calls to niceIncrementFormatter Also removes the niceIncrementFormatter call in formattedInputAmount since the input amount has already been set using the niceIncrementFormatter for the cases it cares about. * Remove incrementDecimalPlaces and niceIncrement as shared values as they are only used in the niceIncrementFormatter function * Upgrade react-native-gesture-handler to v2.17.1 (#5925) * Upgrade reanimated to fix crash * Fix type errors from reanimated upgrade * lint * Fix HourglassAnimation * Revert "move nft fetching logic to graphql worker (#5421)" This reverts commit fff25a6. * Bump reanimated to v3.7.1 * Upgrade react-native-gesture-handler to v2.15.0 * Imports * Android * Merge branch '@christian/upgrade-reanimated' into @christian/upgrade-gesture-handler * Fix android build - remove old reanimated shim * Fix RNGH and ZoomableButton Couldn't get these changes to apply via patch-package, so at least for now had to fork RNGH to apply them: rainbow-me/react-native-gesture-handler@0c4b8be * Fix RNGH install * Bump RNGH, bump reanimated patch * Patch GH instead of forking * Fix native Android ZoomableButton Will follow up with some code cleanup but everything should be working. This also removes a bunch of unnecessary wrapper views and layout recalculations in the Android ButtonPressAnimation component. * Delete unneeded @ts-expect-errors * Remove unneeded @ts-expect-error --------- Co-authored-by: Ben Goldberg <[email protected]> Co-authored-by: Ibrahim Taveras <[email protected]> * Update inputMethod to inputAmount anytime the asset changes (#5934) * Update bitrise.yml with latest from bitrise.io (#5940) * :) * Update src/languages/en_US.json Co-authored-by: Matthew Wall <[email protected]> * Update src/__swaps__/screens/Swap/providers/swap-provider.tsx Co-authored-by: Matthew Wall <[email protected]> * Update src/__swaps__/screens/Swap/providers/swap-provider.tsx Co-authored-by: Matthew Wall <[email protected]> * ah😮 * Update src/__swaps__/screens/Swap/providers/swap-provider.tsx Co-authored-by: Matthew Wall <[email protected]> * idk --------- Co-authored-by: Jin <[email protected]> Co-authored-by: Bruno Barbieri <[email protected]> Co-authored-by: Christian Baroni <[email protected]> Co-authored-by: Ben Goldberg <[email protected]> Co-authored-by: Ibrahim Taveras <[email protected]> Co-authored-by: Matthew Wall <[email protected]>
What changed (plus any additional context for devs)
What to test
Screen recordings / screenshots
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-07-09.at.17.29.37.mp4