Skip to content
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

Merged
merged 8 commits into from
Jul 15, 2024

Conversation

jinchung
Copy link
Member

@jinchung jinchung commented Jul 9, 2024

What changed (plus any additional context for devs)

  • This work is a precursor for adding in logic for handling native amount changes
  • This removes redundant code and simplifies the logic, making it easier to modify and grok in the future
  • Easiest way to review this PR is going commit-by-commit

What to test

  • Updating input amount, slider, output amount should behave as expected

Screen recordings / screenshots

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-07-09.at.17.29.37.mp4

'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') {
Copy link
Member Author

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.

@jinchung jinchung changed the title @jin/input controller animated reaction update Simplify SwapInputController animated reaction logic for responding to input value changes Jul 9, 2024
@@ -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;
Copy link
Member Author

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),
Copy link
Member Author

@jinchung jinchung Jul 10, 2024

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.

@jinchung jinchung marked this pull request as ready for review July 10, 2024 13:22
@jinchung jinchung force-pushed the @jin/input-controller-animated-reaction-update branch from b72db94 to 4884847 Compare July 11, 2024 19:13
Base automatically changed from @jin/decimal-cleanup to develop July 11, 2024 20:25
@jinchung jinchung force-pushed the @jin/input-controller-animated-reaction-update branch from 4884847 to 8570f1f Compare July 11, 2024 20:29
@jinchung jinchung removed the request for review from brunobar79 July 15, 2024 15:52
@jinchung jinchung requested a review from greg-schrammel July 15, 2024 16:00
@jinchung jinchung merged commit dfcf476 into develop Jul 15, 2024
6 checks passed
@jinchung jinchung deleted the @jin/input-controller-animated-reaction-update branch July 15, 2024 17:41
greg-schrammel pushed a commit that referenced this pull request Jul 19, 2024
…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
greg-schrammel added a commit that referenced this pull request Jul 22, 2024
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants