-
Notifications
You must be signed in to change notification settings - Fork 123
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
chore: Swap Settings Slippage fast follow #1206
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
const SLIPPAGE_SETTINGS = { | ||
AUTO: 'Auto', | ||
CUSTOM: 'Custom', | ||
}; |
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.
now we are talking
@@ -65,23 +70,22 @@ export function SwapSettingsSlippageInput({ | |||
)} | |||
> | |||
<legend className="sr-only">Slippage Setting</legend> | |||
{slippageSettings.map((slippageSetting) => ( | |||
{Object.values(SLIPPAGE_SETTINGS).map((setting) => ( |
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.
setting
is still a odd word, but I am going to approve it this for now.
type="button" | ||
className={cn( | ||
pressable.default, | ||
color.foreground, | ||
'flex-1 rounded-lg px-3 py-1 font-medium text-sm transition-colors', | ||
isAutoSlippageSetting === (slippageSetting === 'Auto') | ||
// Highlight the button if it is selected |
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.
love the comment
@@ -90,7 +94,7 @@ export function SwapSettingsSlippageInput({ | |||
background.default, | |||
border.defaultActive, | |||
'flex h-9 w-24 items-center justify-between rounded-lg border px-2 py-1', | |||
isAutoSlippageSetting && 'opacity-50', | |||
slippageSetting === SLIPPAGE_SETTINGS.AUTO && 'opacity-50', |
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.
Must be the performance perfectionist in me :)
But everytime you have code that is writtend 2+ times, it cost CPU time. No big deal, but when you see those things, you can just write something like
let isSlippageSettingAuto = false;
useEffect(() => {
isSlippageSettingAuto = slippageSetting === SLIPPAGE_SETTINGS.AUTO;
}, [slippageSetting]);
and just use isSlippageSettingAuto
evreywher. And make the code more elegant and also more efficient.
What changed? Why?
Notes to reviewers
How has it been tested?