From 7e5bbf9a868e4f43ddc490e1812b4828d8670c4c Mon Sep 17 00:00:00 2001 From: Evan Kaloudis Date: Fri, 17 Mar 2023 01:29:11 -0400 Subject: [PATCH] Settings: Invoices + Payments: fix swipe back bug --- views/Settings/InvoicesSettings.tsx | 239 +++++++++++++++------------- views/Settings/PaymentsSettings.tsx | 192 +++++++++++----------- 2 files changed, 223 insertions(+), 208 deletions(-) diff --git a/views/Settings/InvoicesSettings.tsx b/views/Settings/InvoicesSettings.tsx index 49d393021..f9e08c571 100644 --- a/views/Settings/InvoicesSettings.tsx +++ b/views/Settings/InvoicesSettings.tsx @@ -4,7 +4,6 @@ import { Header, Icon } from 'react-native-elements'; import { inject, observer } from 'mobx-react'; import _map from 'lodash/map'; -import LoadingIndicator from '../../components/LoadingIndicator'; import ModalBox from '../../components/ModalBox'; import Switch from '../../components/Switch'; import TextInput from '../../components/TextInput'; @@ -56,22 +55,6 @@ export default class InvoicesSettings extends React.Component< }); } - handleSave = async () => { - const { addressType, memo, expiry, routeHints, ampInvoice } = - this.state; - const { SettingsStore } = this.props; - const { updateSettings } = SettingsStore; - await updateSettings({ - invoices: { - addressType, - memo, - expiry, - routeHints, - ampInvoice - } - }); - }; - renderSeparator = () => ( { - this.handleSave(); navigation.navigate('Settings', { refresh: true }); @@ -175,101 +157,133 @@ export default class InvoicesSettings extends React.Component< borderBottomWidth: 0 }} /> - {loading ? ( - - ) : ( - + - - {localeString('views.Receive.memo')} - - { - this.setState({ memo: text }); - }} - /> - - {implementation !== 'lndhub' && ( - <> - - {localeString('views.Receive.expiration')} - - - this.setState({ - expiry: text - }) - } - /> - + {localeString('views.Receive.memo')} + + { + this.setState({ memo: text }); + await updateSettings({ + invoices: { + addressType, + memo: text, + expiry, + routeHints, + ampInvoice + } + }); + }} + /> - {BackendUtils.isLNDBased() && ( - <> - - {localeString('views.Receive.routeHints')} - - - this.setState({ - routeHints: !routeHints - }) - } - /> - - )} + {implementation !== 'lndhub' && ( + <> + + {localeString('views.Receive.expiration')} + + { + this.setState({ + expiry: text + }); + await updateSettings({ + invoices: { + addressType, + memo, + expiry: text, + routeHints, + ampInvoice + } + }); + }} + /> + + )} - {BackendUtils.supportsAMP() && ( - <> - - {localeString('views.Receive.ampInvoice')} - - - this.setState({ + {BackendUtils.isLNDBased() && ( + <> + + {localeString('views.Receive.routeHints')} + + { + this.setState({ + routeHints: !routeHints + }); + await updateSettings({ + invoices: { + addressType, + memo, + expiry, + routeHints: !routeHints, + ampInvoice + } + }); + }} + /> + + )} + + {BackendUtils.supportsAMP() && ( + <> + + {localeString('views.Receive.ampInvoice')} + + { + this.setState({ + ampInvoice: !ampInvoice + }); + await updateSettings({ + invoices: { + addressType, + memo, + expiry, + routeHints, ampInvoice: !ampInvoice - }) - } - /> - - )} - - )} + } + }); + }} + /> + + )} + ( { + onPress={async () => { this.setState({ addressType: d.value }); + await updateSettings({ + invoices: { + addressType: d.value, + memo, + expiry, + routeHints, + ampInvoice + } + }); this.refs.modal.close(); }} style={{ diff --git a/views/Settings/PaymentsSettings.tsx b/views/Settings/PaymentsSettings.tsx index f65191f69..bca546cbe 100644 --- a/views/Settings/PaymentsSettings.tsx +++ b/views/Settings/PaymentsSettings.tsx @@ -6,7 +6,6 @@ import SettingsStore from '../../stores/SettingsStore'; import { localeString } from '../../utils/LocaleUtils'; import { themeColor } from '../../utils/ThemeUtils'; -import LoadingIndicator from '../../components/LoadingIndicator'; import TextInput from '../../components/TextInput'; interface PaymentsSettingsProps { @@ -44,19 +43,6 @@ export default class PaymentsSettings extends React.Component< }); } - handleSave = async () => { - const { feeLimitMethod, feeLimit, feePercentage } = this.state; - const { SettingsStore } = this.props; - const { updateSettings } = SettingsStore; - await updateSettings({ - payments: { - defaultFeeMethod: feeLimitMethod, - defaultFeePercentage: feePercentage, - defaultFeeFixed: feeLimit - } - }); - }; - renderSeparator = () => ( ( { - this.handleSave(); navigation.navigate('Settings', { refresh: true }); @@ -106,107 +92,113 @@ export default class PaymentsSettings extends React.Component< borderBottomWidth: 0 }} /> - {loading ? ( - - ) : ( + + + {`${localeString( + 'views.Settings.Payments.defaultFeeLimit' + )}`} + + + { + this.setState({ + feeLimit: text + }); + await updateSettings({ + payments: { + defaultFeeMethod: 'fixed', + defaultFeePercentage: feePercentage, + defaultFeeFixed: text + } + }); + }} + onPressIn={() => + this.setState({ + feeLimitMethod: 'fixed' + }) + } + /> - {`${localeString( - 'views.Settings.Payments.defaultFeeLimit' - )}`} + {`${localeString('general.sats')}`} - - { + this.setState({ + feePercentage: text + }); + await updateSettings({ + payments: { + defaultFeeMethod: 'percent', + defaultFeePercentage: text, + defaultFeeFixed: feeLimit + } + }); + }} + onPressIn={() => + this.setState({ + feeLimitMethod: 'percent' + }) + } + /> + - - this.setState({ - feeLimit: text - }) - } - onPressIn={() => - this.setState({ - feeLimitMethod: 'fixed' - }) - } - /> - - {`${localeString('general.sats')}`} - - - this.setState({ - feePercentage: text - }) - } - onPressIn={() => - this.setState({ - feeLimitMethod: 'percent' - }) - } - /> - - {'%'} - - + {'%'} + - )} + ); }