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

fix: SwapSlippageInput was visually resetting to default value on error #1250

Merged
merged 4 commits into from
Sep 15, 2024

Conversation

cpcramer
Copy link
Contributor

What changed? Why?

Notes to reviewers

How has it been tested?

Copy link

vercel bot commented Sep 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
onchainkit-coverage ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 14, 2024 9:53pm
onchainkit-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 14, 2024 9:53pm
onchainkit-routes ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 14, 2024 9:53pm

@cpcramer cpcramer changed the title Fix fix: SwapSlippageInput was visually resetting to default on error Sep 12, 2024
@@ -169,7 +169,6 @@ type SwapSettingsSlippageDescriptionReact = {
```ts
type SwapSettingsSlippageInputReact = {
className?: string; // Optional className override for top div element.
defaultSlippage?: number; // Optional default slippage value in pecentage.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are now using Config from Leo's change this morning

Comment on lines 17 to 21
if (lifeCycleStatus.statusName !== 'error') {
return lifeCycleStatus.statusData.maxSlippage;
}
return defaultSlippage;
}, [lifeCycleStatus.statusName, lifeCycleStatus.statusData, defaultSlippage]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for all these checks post lifecycleStatusShared update.

@@ -67,10 +64,10 @@ export function SwapSettingsSlippageInput({
(setting: string) => {
setSlippageSetting(setting);
if (setting === SLIPPAGE_SETTINGS.AUTO) {
updateSlippage(defaultSlippage);
updateSlippage(DEFAULT_MAX_SLIPPAGE);
Copy link
Contributor Author

@cpcramer cpcramer Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to use shared const

@@ -245,7 +245,6 @@ export type SwapSettingsSlippageDescriptionReact = {
*/
export type SwapSettingsSlippageInputReact = {
className?: string; // Optional className override for top div element.
defaultSlippage?: number; // Optional default slippage value in pecentage.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are now using Config from Leo's change this morning

@cpcramer cpcramer changed the title fix: SwapSlippageInput was visually resetting to default on error fix: SwapSlippageInput was visually resetting to default value on error Sep 12, 2024
@@ -74,26 +68,6 @@ describe('SwapSettingsSlippageInput', () => {
expect(screen.getByRole('textbox')).toBeDisabled();
});

it('switches between Auto and Custom modes', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have replacement tests for using the values from the config? and why did we remove this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests were using the old defaultSlippage input param. I was going to remove and write new ones but we are still getting 100% test coverage 👀


// Set initial slippage values to match previous selection or default,
// ensuring consistency when dropdown is reopened
const [slippage, setSlippage] = useState(getMaxSlippage());
const [slippageSetting, setSlippageSetting] = useState(
getMaxSlippage() === defaultSlippage
getMaxSlippage() === DEFAULT_MAX_SLIPPAGE
Copy link
Contributor Author

@cpcramer cpcramer Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use config.maxSlippage.

The default max slippage can be customized using the config parameter.

It might be nice to add and track the defaultMaxSlippage in LifecycleStatusDataShared.

type LifecycleStatusDataShared = {
  defaultMaxSlippage: number; // set using config.maxSlippage and does not change. 
  isMissingRequiredField: boolean;
  maxSlippage: number; // set using config.maxSlippage but updates when slippage is customized. This will remain what slippage value we use. 
};

Thoughts? @0xAlec

Copy link
Contributor

@Zizzamia Zizzamia Sep 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config should not be part of LifecycleStatusDataShared, as LifecycleStatusDataShared is meant to change, where config is meant to stay still.

return defaultSlippage;
}, [lifecycleStatus.statusName, lifecycleStatus.statusData, defaultSlippage]);
return lifecycleStatus.statusData.maxSlippage;
}, [lifecycleStatus.statusData]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note, for next PR, I don't think we even need getMaxSlippage anymore. Right?

or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, we can remove it!

I suppose the only benefit is minor performance improvements using memoization from useCallback

@Zizzamia Zizzamia merged commit fdeba9c into main Sep 15, 2024
16 checks passed
@Zizzamia Zizzamia deleted the paul/fix-slipppage-on-error branch September 15, 2024 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation pkg: swap
Development

Successfully merging this pull request may close these issues.

3 participants