-
Notifications
You must be signed in to change notification settings - Fork 603
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
Update flipping logic in SwapInputsController #5948
Conversation
3d07ca9
to
dc8068a
Compare
417d199
to
caef684
Compare
…matter after flip
@@ -640,6 +611,74 @@ export function useSwapInputsController({ | |||
} | |||
); | |||
|
|||
/** |
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.
NOTE: this is not all brand new logic - this is mostly moving this animatedReaction from line 812 to here so that it's ahead of another animatedReaction that reacts to maxSwappableAmount changes
}); | ||
} else { | ||
// If the assets were flipped | ||
updateInputValuesAfterFlip({ |
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 is the "main" change for this function for when the assets are flipped - the logic is in the other file
@@ -30,36 +30,7 @@ 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({ |
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.
I just moved this out to a separate file to make it easier for testing later - no changes
import { ExtendedAnimatedAssetWithColors } from '@/__swaps__/types/assets'; | ||
import { divWorklet, equalWorklet, greaterThanWorklet, mulWorklet } from '@/__swaps__/safe-math/SafeMath'; | ||
|
||
export function getInputValuesForSliderPositionWorklet({ |
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 is the function that was just directly moved over from the useSwapInputsController
- no changes
}; | ||
} | ||
|
||
export const updateInputValuesAfterFlip = ({ |
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 is the main logic that is new / updated for how to handle input values after a flip
…ll actually be used
inputNativeValue: mulWorklet(newInputAmount, inputNativePrice), | ||
}; | ||
}); | ||
return; |
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.
only for slider do we return early since we do not want to update the outputAmount
and outputNativeValue
like all the other flows; we just want to modify the inputAmount
and inputNativeValue
}); | ||
newInputAmount = inputAmountBasedOnSlider; | ||
inputMethod.value = 'slider'; | ||
lastTypedInput.value = '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.
only for the slider do we need to update the lastTypedInput
and focusedInput
back to be input based
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.
🔥
…inbow into brody/enable-android-tests * 'brody/enable-android-tests' of github.com:rainbow-me/rainbow: degen mode feature flag (#5969) Fix Android dapp browser gestures (#5964) Add Degen Mode, swap settings panel (#5963) Update flipping logic in SwapInputsController (#5948) Hold to swap button (#5920)
Fixes APP-1675
Fixes APP-1699
More comments are inline in the code files changed below.
What changed (plus any additional context for devs)
maxSwappableAmount
value as this was causing the reliance of "did the user intend to use max" check unreliableOverall, the flipping logic will try to figure out which values to used in this priority order:
Screen recordings / screenshots
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-07-26.at.00.26.03.mp4
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-07-26.at.00.29.00.mp4
BEFORE: "7.5e-8" bug
https://github.com/user-attachments/assets/ce2fc0c9-64c0-41f8-8f08-e4ff81689190
AFTER fixing "7.5e-8" bug
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-07-26.at.00.23.37.mp4
What to test