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 accidental mutation of the expiring offers defaults object #2214

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function SettingsExpiringOffers(props) {
<SettingsLabel>
<Trans>Offer Expiration Time</Trans>
</SettingsLabel>
<Form methods={methods} onSubmit={methods.handleSubmit(handleSubmit)}>
<Form methods={methods} onSubmit={handleSubmit}>
<Flex flexDirection="column" gap={1}>
<Flex gap={2} sx={{ width: '100%', marginTop: 2 }}>
{fields.map((field) => (
Expand Down Expand Up @@ -79,7 +79,6 @@ export default function SettingsExpiringOffers(props) {
{isOfferExpirationDefaultTimeEnabled && (
<ButtonLoading
size="small"
type="submit"
seeden marked this conversation as resolved.
Show resolved Hide resolved
variant="outlined"
color="secondary"
onClick={handleDisable}
Expand Down
9 changes: 4 additions & 5 deletions packages/gui/src/hooks/useOfferExpirationDefaultTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ function stringPropertiesToNumbers(objWithStrings: OfferExpirationDefaultTimeInp
}

export default function useOfferExpirationDefaultTime() {
const defaultsCopy = { ...offerExpirationDefaultTimeDefaults };
seeden marked this conversation as resolved.
Show resolved Hide resolved
const [offerExpirationDefaultTime, setOfferExpirationDefaultTimeLocal] = usePrefs<OfferExpirationDefaultTimeOutput>(
'offerExpirationDefaultTime',
offerExpirationDefaultTimeDefaults
defaultsCopy // to avoid accidentally mutating the defaults object
);

const isOfferExpirationDefaultTimeEnabled = useMemo(
() => offerExpirationDefaultTime.enabled === true,
[offerExpirationDefaultTime]
);
const isOfferExpirationDefaultTimeEnabled = offerExpirationDefaultTime.enabled === true;

const setOfferExpirationDefaultTime = useCallback(
(offerExpirationDefaultTimeInput: OfferExpirationDefaultTimeInput) => {
Expand All @@ -68,5 +66,6 @@ export default function useOfferExpirationDefaultTime() {
() => ({ offerExpirationDefaultTime, setOfferExpirationDefaultTime, isOfferExpirationDefaultTimeEnabled }),
[offerExpirationDefaultTime, setOfferExpirationDefaultTime, isOfferExpirationDefaultTimeEnabled]
);

return toReturn;
}
Loading