Skip to content

Commit

Permalink
Merge pull request #2214 from Chia-Network/paninaro.fix_expiring_offe…
Browse files Browse the repository at this point in the history
…r_prefs

Fix accidental mutation of the expiring offers defaults object
  • Loading branch information
seeden authored Oct 27, 2023
2 parents 0ff527f + cdc146f commit ad843df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
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"
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 };
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;
}

0 comments on commit ad843df

Please sign in to comment.