From 7ea87cfc150f7d1bdccf777430c5e47a0df79b1e Mon Sep 17 00:00:00 2001 From: myxmaster Date: Fri, 7 Feb 2025 01:11:01 +0100 Subject: [PATCH] use spread operator for updateSettings() --- views/Settings/ChannelsSettings.tsx | 23 +-- views/Settings/Display.tsx | 63 ++------ views/Settings/InvoicesSettings.tsx | 93 +++--------- .../LightningAddressSettings.tsx | 60 ++------ views/Settings/LightningAddress/NostrKeys.tsx | 18 +-- .../Settings/LightningAddress/NostrRelays.tsx | 29 +--- views/Settings/PointOfSale.tsx | 137 +++--------------- views/Settings/Privacy.tsx | 35 ++--- 8 files changed, 87 insertions(+), 371 deletions(-) diff --git a/views/Settings/ChannelsSettings.tsx b/views/Settings/ChannelsSettings.tsx index f766db5fb..97fdf5a99 100644 --- a/views/Settings/ChannelsSettings.tsx +++ b/views/Settings/ChannelsSettings.tsx @@ -85,7 +85,7 @@ export default class ChannelsSettings extends React.Component< simpleTaprootChannel, lsps1ShowPurchaseButton } = this.state; - const { updateSettings }: any = SettingsStore; + const { settings, updateSettings }: any = SettingsStore; return ( @@ -126,10 +126,8 @@ export default class ChannelsSettings extends React.Component< }); await updateSettings({ channels: { - min_confs: newMinConfs, - privateChannel, - scidAlias, - simpleTaprootChannel + ...settings.channels, + min_confs: newMinConfs } }); }} @@ -157,10 +155,8 @@ export default class ChannelsSettings extends React.Component< }); await updateSettings({ channels: { - min_confs, - privateChannel: !privateChannel, - scidAlias, - simpleTaprootChannel + ...settings.channels, + privateChannel: !privateChannel } }); }} @@ -194,10 +190,8 @@ export default class ChannelsSettings extends React.Component< }); await updateSettings({ channels: { - min_confs, - privateChannel, - scidAlias: !scidAlias, - simpleTaprootChannel + ...settings.channels, + scidAlias: !scidAlias } }); }} @@ -239,12 +233,11 @@ export default class ChannelsSettings extends React.Component< await updateSettings({ channels: { - min_confs, + ...settings.channels, privateChannel: !simpleTaprootChannel ? true : privateChannel, - scidAlias, simpleTaprootChannel: !simpleTaprootChannel } diff --git a/views/Settings/Display.tsx b/views/Settings/Display.tsx index e6b076a0d..5b2743ba0 100644 --- a/views/Settings/Display.tsx +++ b/views/Settings/Display.tsx @@ -99,7 +99,7 @@ export default class Display extends React.Component< showMillisatoshiAmounts, selectNodeOnStartup } = this.state; - const { updateSettings }: any = SettingsStore; + const { settings, updateSettings }: any = SettingsStore; return ( @@ -127,13 +127,8 @@ export default class Display extends React.Component< }); await updateSettings({ display: { - theme: value, - displayNickname, - bigKeypadButtons, - defaultView, - showAllDecimalPlaces, - removeDecimalSpaces, - showMillisatoshiAmounts + ...settings.display, + theme: value } }); SystemNavigationBar.setNavigationColor( @@ -158,13 +153,8 @@ export default class Display extends React.Component< }); await updateSettings({ display: { - defaultView: value, - displayNickname, - bigKeypadButtons, - theme, - showAllDecimalPlaces, - removeDecimalSpaces, - showMillisatoshiAmounts + ...settings.display, + defaultView: value } }); }} @@ -194,13 +184,8 @@ export default class Display extends React.Component< }); await updateSettings({ display: { - defaultView, - theme, - bigKeypadButtons, - displayNickname: !displayNickname, - showAllDecimalPlaces, - removeDecimalSpaces, - showMillisatoshiAmounts + ...settings.display, + displayNickname: !displayNickname } }); }} @@ -231,13 +216,8 @@ export default class Display extends React.Component< }); await updateSettings({ display: { - defaultView, - theme, - displayNickname, - bigKeypadButtons: !bigKeypadButtons, - showAllDecimalPlaces, - removeDecimalSpaces, - showMillisatoshiAmounts + ...settings.display, + bigKeypadButtons: !bigKeypadButtons } }); }} @@ -269,14 +249,9 @@ export default class Display extends React.Component< }); await updateSettings({ display: { - defaultView, - theme, - displayNickname, - bigKeypadButtons, + ...settings.display, showAllDecimalPlaces: - !showAllDecimalPlaces, - removeDecimalSpaces, - showMillisatoshiAmounts + !showAllDecimalPlaces } }); }} @@ -308,14 +283,9 @@ export default class Display extends React.Component< }); await updateSettings({ display: { - defaultView, - theme, - displayNickname, - bigKeypadButtons, - showAllDecimalPlaces, + ...settings.display, removeDecimalSpaces: - !removeDecimalSpaces, - showMillisatoshiAmounts + !removeDecimalSpaces } }); }} @@ -347,12 +317,7 @@ export default class Display extends React.Component< }); await updateSettings({ display: { - defaultView, - theme, - displayNickname, - bigKeypadButtons, - showAllDecimalPlaces, - removeDecimalSpaces, + ...settings.display, showMillisatoshiAmounts: !showMillisatoshiAmounts } diff --git a/views/Settings/InvoicesSettings.tsx b/views/Settings/InvoicesSettings.tsx index a34d0c3b5..d9ddf6ca0 100644 --- a/views/Settings/InvoicesSettings.tsx +++ b/views/Settings/InvoicesSettings.tsx @@ -98,14 +98,13 @@ export default class InvoicesSettings extends React.Component< memo, expiry, timePeriod, - expirySeconds, routeHints, ampInvoice, blindedPaths, showCustomPreimageField, displayAmountOnInvoice } = this.state; - const { implementation, updateSettings }: any = SettingsStore; + const { implementation, settings, updateSettings }: any = SettingsStore; const ADDRESS_TYPES = BackendUtils.supportsTaproot() ? [ @@ -196,15 +195,8 @@ export default class InvoicesSettings extends React.Component< this.setState({ memo: text }); await updateSettings({ invoices: { - addressType, - memo: text, - expiry, - timePeriod, - expirySeconds, - routeHints, - ampInvoice, - blindedPaths, - showCustomPreimageField + ...settings.invoices, + memo: text } }); }} @@ -256,15 +248,9 @@ export default class InvoicesSettings extends React.Component< }); await updateSettings({ invoices: { - addressType, - memo, + ...settings.invoices, expiry: text, - timePeriod, - expirySeconds, - routeHints, - ampInvoice, - blindedPaths, - showCustomPreimageField + expirySeconds } }); }} @@ -322,15 +308,9 @@ export default class InvoicesSettings extends React.Component< await updateSettings({ invoices: { - addressType, - memo, - expiry, + ...settings.invoices, timePeriod: value, - expirySeconds, - routeHints, - ampInvoice, - blindedPaths, - showCustomPreimageField + expirySeconds } }); }} @@ -376,15 +356,8 @@ export default class InvoicesSettings extends React.Component< }); await updateSettings({ invoices: { - addressType, - memo, - expiry, - timePeriod, - expirySeconds, - routeHints: !routeHints, - ampInvoice, - blindedPaths, - showCustomPreimageField + ...settings.invoices, + routeHints: !routeHints } }); }} @@ -431,14 +404,8 @@ export default class InvoicesSettings extends React.Component< }); await updateSettings({ invoices: { - addressType, - memo, - expiry, - timePeriod, - expirySeconds, - routeHints, - ampInvoice: !ampInvoice, - showCustomPreimageField + ...settings.invoices, + ampInvoice: !ampInvoice } }); }} @@ -487,15 +454,10 @@ export default class InvoicesSettings extends React.Component< await updateSettings({ invoices: { - addressType, - memo, - expiry, - timePeriod, - expirySeconds, - routeHints: false, - ampInvoice: false, + ...settings.invoices, blindedPaths: !blindedPaths, - showCustomPreimageField + routeHints: false, + ampInvoice: false } }); }} @@ -536,13 +498,7 @@ export default class InvoicesSettings extends React.Component< }); await updateSettings({ invoices: { - addressType, - memo, - expiry, - timePeriod, - expirySeconds, - routeHints, - ampInvoice, + ...settings.invoices, showCustomPreimageField: !showCustomPreimageField } @@ -582,14 +538,7 @@ export default class InvoicesSettings extends React.Component< }); await updateSettings({ invoices: { - addressType, - memo, - expiry, - timePeriod, - expirySeconds, - routeHints, - ampInvoice, - showCustomPreimageField, + ...settings.invoices, displayAmountOnInvoice: !displayAmountOnInvoice } @@ -637,14 +586,8 @@ export default class InvoicesSettings extends React.Component< this.setState({ addressType: d.value }); await updateSettings({ invoices: { - addressType: d.value, - memo, - expiry, - timePeriod, - expirySeconds, - routeHints, - ampInvoice, - showCustomPreimageField + ...settings.invoices, + addressType: d.value } }); this.modalBoxRef.current?.close(); diff --git a/views/Settings/LightningAddress/LightningAddressSettings.tsx b/views/Settings/LightningAddress/LightningAddressSettings.tsx index b6372ee50..f05bb1fb0 100644 --- a/views/Settings/LightningAddress/LightningAddressSettings.tsx +++ b/views/Settings/LightningAddress/LightningAddressSettings.tsx @@ -85,12 +85,10 @@ export default class LightningAddressSettings extends React.Component< automaticallyAcceptAttestationLevel, routeHints, allowComments, - nostrPrivateKey, nostrRelays, notifications } = this.state; const { updateSettings, settings }: any = SettingsStore; - const enabled = settings?.lightningAddress?.enabled; const { loading, update, error_msg } = LightningAddressStore; return ( @@ -151,17 +149,9 @@ export default class LightningAddressSettings extends React.Component< }); await updateSettings({ lightningAddress: { - enabled, + ...settings.lightningAddress, automaticallyAccept: - !automaticallyAccept, - automaticallyAcceptAttestationLevel, - automaticallyRequestOlympusChannels: - false, // deprecated - routeHints, - allowComments, - nostrPrivateKey, - nostrRelays, - notifications + !automaticallyAccept } }); }} @@ -183,17 +173,9 @@ export default class LightningAddressSettings extends React.Component< }); await updateSettings({ lightningAddress: { - enabled, - automaticallyAccept, + ...settings.lightningAddress, automaticallyAcceptAttestationLevel: - value, - automaticallyRequestOlympusChannels: - false, // deprecated - routeHints, - allowComments, - nostrPrivateKey, - nostrRelays, - notifications + value } }); }} @@ -237,16 +219,8 @@ export default class LightningAddressSettings extends React.Component< }); await updateSettings({ lightningAddress: { - enabled, - automaticallyAccept, - automaticallyAcceptAttestationLevel, - automaticallyRequestOlympusChannels: - false, // deprecated - routeHints: !routeHints, - allowComments, - nostrPrivateKey, - nostrRelays, - notifications + ...settings.lightningAddress, + routeHints: !routeHints } }); }} @@ -288,17 +262,9 @@ export default class LightningAddressSettings extends React.Component< }); await updateSettings({ lightningAddress: { - enabled, - automaticallyAccept, - automaticallyAcceptAttestationLevel, - automaticallyRequestOlympusChannels: - false, // deprecated - routeHints, + ...settings.lightningAddress, allowComments: - !allowComments, - nostrPrivateKey, - nostrRelays, - notifications + !allowComments } }); }); @@ -323,15 +289,7 @@ export default class LightningAddressSettings extends React.Component< }); await updateSettings({ lightningAddress: { - enabled, - automaticallyAccept, - automaticallyAcceptAttestationLevel, - automaticallyRequestOlympusChannels: - false, // deprecated - routeHints, - allowComments, - nostrPrivateKey, - nostrRelays, + ...settings.lightningAddress, notifications: value } }); diff --git a/views/Settings/LightningAddress/NostrKeys.tsx b/views/Settings/LightningAddress/NostrKeys.tsx index f2a1b0979..c51929a41 100644 --- a/views/Settings/LightningAddress/NostrKeys.tsx +++ b/views/Settings/LightningAddress/NostrKeys.tsx @@ -124,14 +124,6 @@ export default class NostrKey extends React.Component< } = this.state; const { update, error_msg, loading } = LightningAddressStore; const { updateSettings, settings } = SettingsStore; - const { lightningAddress } = settings; - const { - enabled, - automaticallyAccept, - allowComments, - nostrRelays, - notifications - } = lightningAddress; const VisibilityButton = () => ( @@ -385,14 +377,8 @@ export default class NostrKey extends React.Component< }); await updateSettings({ lightningAddress: { - enabled, - automaticallyAccept, - automaticallyRequestOlympusChannels: - false, // deprecated - allowComments, - nostrPrivateKey, - nostrRelays, - notifications + ...settings.lightningAddress, + nostrPrivateKey } }); }); diff --git a/views/Settings/LightningAddress/NostrRelays.tsx b/views/Settings/LightningAddress/NostrRelays.tsx index e4a4f8414..407adf16c 100644 --- a/views/Settings/LightningAddress/NostrRelays.tsx +++ b/views/Settings/LightningAddress/NostrRelays.tsx @@ -77,13 +77,7 @@ export default class NostrRelays extends React.Component< const { relays, addRelay, setup } = this.state; const { updateSettings, settings }: any = SettingsStore; const { lightningAddress } = settings; - const { - enabled, - automaticallyAccept, - allowComments, - nostrPrivateKey, - notifications - } = lightningAddress; + const { nostrPrivateKey } = lightningAddress; const { update, loading, error_msg } = LightningAddressStore; return ( @@ -208,15 +202,9 @@ export default class NostrRelays extends React.Component< }); await updateSettings({ lightningAddress: { - enabled, - automaticallyAccept, - automaticallyRequestOlympusChannels: - false, // deprecated - allowComments, - nostrPrivateKey, + ...settings.lightningAddress, nostrRelays: - newNostrRelays, - notifications + newNostrRelays } }); }); @@ -300,15 +288,8 @@ export default class NostrRelays extends React.Component< { lightningAddress: { - enabled, - automaticallyAccept, - automaticallyRequestOlympusChannels: - false, // deprecated - allowComments, - nostrPrivateKey, - nostrRelays: - newNostrRelays, - notifications + ...settings.lightningAddress, + relays: newNostrRelays } } ); diff --git a/views/Settings/PointOfSale.tsx b/views/Settings/PointOfSale.tsx index 3b1e7a465..9c62b066f 100644 --- a/views/Settings/PointOfSale.tsx +++ b/views/Settings/PointOfSale.tsx @@ -185,17 +185,8 @@ export default class PointOfSale extends React.Component< } await updateSettings({ pos: { - posEnabled: value, - squareAccessToken, - squareLocationId, - merchantName, - confirmationPreference, - disableTips, - squareDevMode, - showKeypad, - taxPercentage, - enablePrinter, - defaultView + ...settings.pos, + posEnabled: value } }); }} @@ -223,17 +214,8 @@ export default class PointOfSale extends React.Component< await updateSettings({ pos: { - posEnabled, - squareAccessToken: text, - squareLocationId, - merchantName, - confirmationPreference, - disableTips, - squareDevMode, - showKeypad, - taxPercentage, - enablePrinter, - defaultView + ...settings.pos, + squareAccessToken: text } }); }} @@ -258,17 +240,8 @@ export default class PointOfSale extends React.Component< await updateSettings({ pos: { - posEnabled, - squareAccessToken, - squareLocationId: text, - merchantName, - confirmationPreference, - disableTips, - squareDevMode, - showKeypad, - taxPercentage, - enablePrinter, - defaultView + ...settings.pos, + squareLocationId: text } }); }} @@ -307,18 +280,9 @@ export default class PointOfSale extends React.Component< }); await updateSettings({ pos: { - squareAccessToken, - squareLocationId, - posEnabled, - merchantName, - confirmationPreference, - disableTips, + ...settings.pos, squareDevMode: - !squareDevMode, - showKeypad, - taxPercentage, - enablePrinter, - defaultView + !squareDevMode } }); }} @@ -349,17 +313,8 @@ export default class PointOfSale extends React.Component< await updateSettings({ pos: { - posEnabled, - squareAccessToken, - squareLocationId, - merchantName: text, - confirmationPreference, - disableTips, - squareDevMode, - showKeypad, - taxPercentage, - enablePrinter, - defaultView + ...settings.pos, + merchantName: text } }); }} @@ -375,16 +330,8 @@ export default class PointOfSale extends React.Component< }); await updateSettings({ pos: { - posEnabled, - squareAccessToken, - squareLocationId, - merchantName, - confirmationPreference: value, - disableTips, - squareDevMode, - showKeypad, - taxPercentage, - defaultView + ...settings.pos, + confirmationPreference: value } }); }} @@ -404,15 +351,7 @@ export default class PointOfSale extends React.Component< }); await updateSettings({ pos: { - posEnabled, - squareAccessToken, - squareLocationId, - merchantName, - confirmationPreference, - disableTips, - squareDevMode, - showKeypad, - taxPercentage, + ...settings.pos, defaultView: value } }); @@ -453,18 +392,9 @@ export default class PointOfSale extends React.Component< }); await updateSettings({ pos: { - squareAccessToken, - squareLocationId, - posEnabled, - merchantName, - confirmationPreference, + ...settings.pos, disableTips: - !disableTips, - squareDevMode, - showKeypad, - taxPercentage, - enablePrinter, - defaultView + !disableTips } }); }} @@ -509,18 +439,9 @@ export default class PointOfSale extends React.Component< }); await updateSettings({ pos: { - squareAccessToken, - squareLocationId, - posEnabled, - merchantName, - confirmationPreference, - disableTips, - squareDevMode, - showKeypad, - taxPercentage, + ...settings.pos, enablePrinter: - !enablePrinter, - defaultView + !enablePrinter } }); }} @@ -565,16 +486,8 @@ export default class PointOfSale extends React.Component< }); await updateSettings({ pos: { - squareAccessToken, - squareLocationId, - posEnabled, - merchantName, - confirmationPreference, - disableTips, - squareDevMode, - taxPercentage, - showKeypad: !showKeypad, - defaultView + ...settings.pos, + showKeypad: !showKeypad } }); }} @@ -602,16 +515,8 @@ export default class PointOfSale extends React.Component< await updateSettings({ pos: { - posEnabled, - squareAccessToken, - squareLocationId, - merchantName, - confirmationPreference, - disableTips, - squareDevMode, - taxPercentage: text, - showKeypad, - defaultView + ...settings.pos, + taxPercentage: text } }); }} diff --git a/views/Settings/Privacy.tsx b/views/Settings/Privacy.tsx index c35960196..13c190ce7 100644 --- a/views/Settings/Privacy.tsx +++ b/views/Settings/Privacy.tsx @@ -85,7 +85,7 @@ export default class Privacy extends React.Component< lurkerMode, enableMempoolRates } = this.state; - const { updateSettings }: any = SettingsStore; + const { settings, updateSettings }: any = SettingsStore; return ( @@ -115,11 +115,8 @@ export default class Privacy extends React.Component< }); await updateSettings({ privacy: { - defaultBlockExplorer: value, - customBlockExplorer, - clipboard, - lurkerMode, - enableMempoolRates + ...settings.privacy, + defaultBlockExplorer: value } }); }} @@ -147,11 +144,8 @@ export default class Privacy extends React.Component< await updateSettings({ privacy: { - defaultBlockExplorer, - customBlockExplorer: text, - clipboard, - lurkerMode, - enableMempoolRates + ...settings.privacy, + customBlockExplorer: text } }); }} @@ -190,11 +184,8 @@ export default class Privacy extends React.Component< }); await updateSettings({ privacy: { - defaultBlockExplorer, - customBlockExplorer, - clipboard: !clipboard, - lurkerMode, - enableMempoolRates + ...settings.privacy, + clipboard: !clipboard } }); }} @@ -240,11 +231,8 @@ export default class Privacy extends React.Component< }); await updateSettings({ privacy: { - defaultBlockExplorer, - customBlockExplorer, - clipboard, - lurkerMode: !lurkerMode, - enableMempoolRates + ...settings.privacy, + lurkerMode: !lurkerMode } }); }} @@ -279,10 +267,7 @@ export default class Privacy extends React.Component< }); await updateSettings({ privacy: { - defaultBlockExplorer, - customBlockExplorer, - clipboard, - lurkerMode, + ...settings.privacy, enableMempoolRates: !enableMempoolRates }