Skip to content

Commit

Permalink
Merge pull request #2474 from myxmaster/slide-to-pay-threshold
Browse files Browse the repository at this point in the history
Add setting "Slide to Pay Threshold"
  • Loading branch information
kaloudis authored Oct 21, 2024
2 parents 1a4e0d5 + c19d612 commit 644d91b
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 35 deletions.
40 changes: 22 additions & 18 deletions components/AmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface AmountInputProps {
locked?: boolean;
title: string;
hideConversion?: boolean;
hideUnitChangeButton?: boolean;
FiatStore?: FiatStore;
SettingsStore?: SettingsStore;
UnitsStore?: UnitsStore;
Expand Down Expand Up @@ -128,6 +129,7 @@ export default class AmountInput extends React.Component<
title,
locked,
hideConversion,
hideUnitChangeButton,
FiatStore,
UnitsStore,
SettingsStore
Expand Down Expand Up @@ -182,24 +184,26 @@ export default class AmountInput extends React.Component<
flexDirection: 'row'
}}
/>
<TouchableOpacity
onPress={() => !locked && this.onChangeUnits()}
style={{ marginTop: 22, marginLeft: 15 }}
>
{UnitsStore!.getNextUnit() === 'fiat' ? (
<ExchangeFiatSVG
fill={themeColor('text')}
width="35"
height="35"
/>
) : (
<ExchangeBitcoinSVG
fill={themeColor('text')}
width="35"
height="35"
/>
)}
</TouchableOpacity>
{!hideUnitChangeButton && (
<TouchableOpacity
onPress={() => !locked && this.onChangeUnits()}
style={{ marginTop: 22, marginLeft: 15 }}
>
{UnitsStore!.getNextUnit() === 'fiat' ? (
<ExchangeFiatSVG
fill={themeColor('text')}
width="35"
height="35"
/>
) : (
<ExchangeBitcoinSVG
fill={themeColor('text')}
width="35"
height="35"
/>
)}
</TouchableOpacity>
)}
</View>
{!hideConversion && (
<View style={{ marginBottom: 10 }}>
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@
"views.Settings.Privacy.title": "Privacy settings",
"views.Settings.Payments.title": "Payments settings",
"views.Settings.Payments.defaultFeeLimit": "Default Fee Limit",
"views.Settings.Payments.slideToPayThreshold": "Slide to Pay Threshold",
"views.Settings.Payments.timeoutSeconds": "Timeout (seconds)",
"views.Settings.Payments.preferredMempoolRate": "Preferred Mempool Rate",
"views.Settings.Payments.feeLimitMethodExplainer": "Fee limit method will default to fixed for amounts up to 1000 sats and percentage for amounts greater than 1000 sats. You'll be able to change which method and values to use though, under the Settings section of the Payment Request view.",
Expand Down
17 changes: 15 additions & 2 deletions stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ interface PaymentsSettings {
defaultFeeFixed?: string;
timeoutSeconds?: string;
preferredMempoolRate?: string;
slideToPayThreshold: number;
}

interface InvoicesSettings {
Expand Down Expand Up @@ -1085,6 +1086,8 @@ export const DEFAULT_NEUTRINO_PEERS_TESTNET = [

const STORAGE_KEY = 'zeus-settings';

const DEFAULT_SLIDE_TO_PAY_THRESHOLD = 10000;

export default class SettingsStore {
@observable settings: Settings = {
privacy: {
Expand Down Expand Up @@ -1121,7 +1124,8 @@ export default class SettingsStore {
defaultFeePercentage: '5.0',
defaultFeeFixed: '1000',
timeoutSeconds: '60',
preferredMempoolRate: 'fastestFee'
preferredMempoolRate: 'fastestFee',
slideToPayThreshold: DEFAULT_SLIDE_TO_PAY_THRESHOLD
},
invoices: {
addressType: '0',
Expand Down Expand Up @@ -1378,7 +1382,7 @@ export default class SettingsStore {
// Retrieve the settings
const settings = await EncryptedStorage.getItem(STORAGE_KEY);
if (settings) {
const newSettings = JSON.parse(settings);
const newSettings = JSON.parse(settings) as Settings;
if (!newSettings.fiatRatesSource) {
newSettings.fiatRatesSource = DEFAULT_FIAT_RATES_SOURCE;
}
Expand Down Expand Up @@ -1581,6 +1585,15 @@ export default class SettingsStore {
DEFAULT_NEUTRINO_PEERS_TESTNET;
}

if (newSettings.payments == null) {
newSettings.payments = {
slideToPayThreshold: DEFAULT_SLIDE_TO_PAY_THRESHOLD
};
} else if (newSettings.payments.slideToPayThreshold == null) {
newSettings.payments.slideToPayThreshold =
DEFAULT_SLIDE_TO_PAY_THRESHOLD;
}

if (!isEqual(this.settings, newSettings)) {
this.settings = newSettings;
}
Expand Down
12 changes: 8 additions & 4 deletions views/PaymentRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ interface InvoiceState {
settingsToggle: boolean;
zaplockerToggle: boolean;
lightningReadyToSend: boolean;
slideToPayThreshold: number;
}

@inject(
Expand Down Expand Up @@ -117,7 +118,8 @@ export default class PaymentRequest extends React.Component<
lastHopPubkey: null,
settingsToggle: false,
zaplockerToggle: false,
lightningReadyToSend: false
lightningReadyToSend: false,
slideToPayThreshold: 10000
};

async UNSAFE_componentWillMount() {
Expand All @@ -140,7 +142,8 @@ export default class PaymentRequest extends React.Component<
feeOption,
feeLimitSat: settings?.payments?.defaultFeeFixed || '100',
maxFeePercent: settings?.payments?.defaultFeePercentage || '5.0',
timeoutSeconds: settings?.payments?.timeoutSeconds || '60'
timeoutSeconds: settings?.payments?.timeoutSeconds || '60',
slideToPayThreshold: settings?.payments?.slideToPayThreshold
});

if (implementation === 'embedded-lnd') {
Expand Down Expand Up @@ -348,7 +351,8 @@ export default class PaymentRequest extends React.Component<
zaplockerToggle,
settingsToggle,
timeoutSeconds,
lightningReadyToSend
lightningReadyToSend,
slideToPayThreshold
} = this.state;
const {
pay_req,
Expand Down Expand Up @@ -1098,7 +1102,7 @@ export default class PaymentRequest extends React.Component<
<LoadingIndicator size={30} />
</>
)}
{requestAmount >= 10000 ? (
{requestAmount >= slideToPayThreshold ? (
<SwipeButton
onSwipeSuccess={this.triggerPayment}
instructionText={localeString(
Expand Down
51 changes: 40 additions & 11 deletions views/Settings/PaymentsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { localeString } from '../../utils/LocaleUtils';
import { themeColor } from '../../utils/ThemeUtils';

import TextInput from '../../components/TextInput';
import AmountInput from '../../components/AmountInput';

interface PaymentsSettingsProps {
navigation: StackNavigationProp<any, any>;
Expand All @@ -29,6 +30,7 @@ interface PaymentsSettingsState {
timeoutSeconds: string;
enableMempoolRates: boolean;
preferredMempoolRate: string;
slideToPayThreshold: string;
}

@inject('SettingsStore')
Expand All @@ -43,7 +45,8 @@ export default class PaymentsSettings extends React.Component<
feePercentage: '5.0',
timeoutSeconds: '60',
enableMempoolRates: false,
preferredMempoolRate: 'fastestFee'
preferredMempoolRate: 'fastestFee',
slideToPayThreshold: '10000'
};

async UNSAFE_componentWillMount() {
Expand All @@ -58,7 +61,9 @@ export default class PaymentsSettings extends React.Component<
enableMempoolRates: settings?.privacy?.enableMempoolRates || false,
timeoutSeconds: settings?.payments?.timeoutSeconds || '60',
preferredMempoolRate:
settings?.payments?.preferredMempoolRate || 'fastestFee'
settings?.payments?.preferredMempoolRate || 'fastestFee',
slideToPayThreshold:
settings?.payments?.slideToPayThreshold?.toString() || '10000'
});
}

Expand All @@ -79,7 +84,8 @@ export default class PaymentsSettings extends React.Component<
feePercentage,
enableMempoolRates,
timeoutSeconds,
preferredMempoolRate
preferredMempoolRate,
slideToPayThreshold
} = this.state;
const { SettingsStore } = this.props;
const { updateSettings, settings, implementation } = SettingsStore;
Expand Down Expand Up @@ -117,14 +123,6 @@ export default class PaymentsSettings extends React.Component<
'views.Settings.Payments.defaultFeeLimit'
)}
</Text>
<View
style={{
flex: 1,
flexWrap: 'wrap',
flexDirection: 'row',
justifyContent: 'flex-end'
}}
></View>
<View
style={{
flexDirection: 'row',
Expand Down Expand Up @@ -282,6 +280,37 @@ export default class PaymentsSettings extends React.Component<
</View>
)}

<AmountInput
amount={slideToPayThreshold.toString()}
title={
localeString('general.lightning') +
' - ' +
localeString(
'views.Settings.Payments.slideToPayThreshold'
)
}
onAmountChange={async (amount, _) => {
this.setState({
slideToPayThreshold: amount
});
const amountNumber = Number(amount);
if (!Number.isNaN(amountNumber)) {
await updateSettings({
payments: {
defaultFeeMethod: feeLimitMethod,
defaultFeePercentage: feePercentage,
defaultFeeFixed: feeLimit,
timeoutSeconds,
preferredMempoolRate,
slideToPayThreshold: Number(amount)
}
});
}
}}
hideConversion={true}
hideUnitChangeButton={true}
/>

{BackendUtils.isLNDBased() && (
<>
<Text
Expand Down

0 comments on commit 644d91b

Please sign in to comment.