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

New invoice setting "Display requested amount on invoice" #2582

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
22 changes: 20 additions & 2 deletions components/CollapsedQR.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import QRCode from 'react-native-qrcode-svg';

import HCESession, { NFCContentType, NFCTagType4 } from 'react-native-hce';

import Button from './../components/Button';
import Amount from './Amount';
import Button from './Button';
import CopyButton from './CopyButton';
import { localeString } from './../utils/LocaleUtils';
import { themeColor } from './../utils/ThemeUtils';
import Touchable from './Touchable';
import Conversion from './Conversion';

const defaultLogo = require('../assets/images/icon-black.png');
const defaultLogoWhite = require('../assets/images/icon-white.png');
Expand Down Expand Up @@ -68,6 +70,8 @@ interface CollapsedQRProps {
truncateLongValue?: boolean;
logo?: any;
nfcSupported?: boolean;
satAmount?: string | number;
displayAmount?: boolean;
}

interface CollapsedQRState {
Expand Down Expand Up @@ -141,13 +145,27 @@ export default class CollapsedQR extends React.Component<
expanded,
textBottom,
truncateLongValue,
logo
logo,
satAmount
} = this.props;

const { width, height } = Dimensions.get('window');

return (
<React.Fragment>
{satAmount != null && this.props.displayAmount && (
<View
style={{
flexDirection: 'column',
alignItems: 'center'
}}
>
<Amount sats={satAmount} toggleable></Amount>
<View>
<Conversion sats={satAmount} sensitive />
</View>
</View>
)}
{!hideText && !textBottom && (
<ValueText
value={value}
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@
"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.",
"views.Settings.Invoices.title": "Invoices settings",
"views.Settings.Invoices.showCustomPreimageField": "Show custom preimage field",
"views.Settings.Invoices.displayAmountOnInvoice": "Display requested amount on invoice",
"views.Settings.Channels.title": "Channels settings",
"views.Settings.Channels.lsps1ShowPurchaseButton": "Show channel purchase button",
"views.Settings.Privacy.blockExplorer": "Default Block explorer",
Expand Down
4 changes: 3 additions & 1 deletion stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ interface InvoicesSettings {
ampInvoice?: boolean;
blindedPaths: boolean;
showCustomPreimageField?: boolean;
displayAmountOnInvoice?: boolean;
}

interface ChannelsSettings {
Expand Down Expand Up @@ -1142,7 +1143,8 @@ export default class SettingsStore {
routeHints: false,
ampInvoice: false,
blindedPaths: false,
showCustomPreimageField: false
showCustomPreimageField: false,
displayAmountOnInvoice: false
},
channels: {
min_confs: 1,
Expand Down
6 changes: 4 additions & 2 deletions views/Invoice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,17 @@ export default class InvoiceView extends React.Component<
getKeysendMessage,
is_amp,
value,
getNoteKey
getNoteKey,
getAmount
} = invoice;
const privateInvoice = invoice.private;

const QRButton = () => (
<TouchableOpacity
onPress={() =>
navigation.navigate('QR', {
value: `lightning:${getPaymentRequest}`
value: `lightning:${getPaymentRequest}`,
satAmount: getAmount
})
}
>
Expand Down
3 changes: 2 additions & 1 deletion views/PaymentRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ export default class PaymentRequest extends React.Component<
<TouchableOpacity
onPress={() =>
navigation.navigate('QR', {
value: `lightning:${paymentRequest}`
value: `lightning:${paymentRequest}`,
satAmount: requestAmount
})
}
>
Expand Down
31 changes: 26 additions & 5 deletions views/QR.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ import * as React from 'react';
import { Dimensions, View } from 'react-native';
import { Route } from '@react-navigation/native';
import { StackNavigationProp } from '@react-navigation/stack';
import { inject, observer } from 'mobx-react';

import CollapsedQR from '../components/CollapsedQR';
import Header from '../components/Header';
import Screen from '../components/Screen';
import Text from '../components/Text';

import SettingsStore from '../stores/SettingsStore';

import { themeColor } from '../utils/ThemeUtils';

interface QRProps {
navigation: StackNavigationProp<any, any>;
SettingsStore?: SettingsStore;
route: Route<
'QR',
{
Expand All @@ -21,6 +25,7 @@ interface QRProps {
hideText: boolean;
jumboLabel: boolean;
logo: any;
satAmount?: string | number;
}
>;
}
Expand All @@ -32,8 +37,11 @@ interface QRState {
hideText: boolean;
jumboLabel: boolean;
logo: any;
satAmount?: string | number;
}

@inject('SettingsStore')
@observer
export default class QR extends React.PureComponent<QRProps, QRState> {
constructor(props: QRProps) {
super(props);
Expand All @@ -42,21 +50,30 @@ export default class QR extends React.PureComponent<QRProps, QRState> {
const copyValue = props.route.params?.copyValue ?? '';
const label = props.route.params?.label ?? '';
const { hideText, jumboLabel, logo } = props.route.params ?? {};
const satAmount = props.route.params?.satAmount ?? undefined;

this.state = {
value,
copyValue,
label,
hideText,
jumboLabel,
logo
logo,
satAmount
};
}

render() {
const { navigation } = this.props;
const { value, copyValue, label, hideText, jumboLabel, logo } =
this.state;
const {
value,
copyValue,
label,
hideText,
jumboLabel,
logo,
satAmount
} = this.state;

const { fontScale } = Dimensions.get('window');

Expand All @@ -71,8 +88,7 @@ export default class QR extends React.PureComponent<QRProps, QRState> {
/>
<View
style={{
top: 5,
padding: 15,
paddingHorizontal: 15,
alignItems: 'center'
}}
>
Expand All @@ -95,6 +111,11 @@ export default class QR extends React.PureComponent<QRProps, QRState> {
textBottom
hideText={hideText}
logo={logo}
satAmount={satAmount}
displayAmount={
this.props.SettingsStore?.settings?.invoices
?.displayAmountOnInvoice || false
}
/>
</View>
</Screen>
Expand Down
30 changes: 29 additions & 1 deletion views/Receive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,7 @@ export default class Receive extends React.Component<
</TouchableOpacity>
)}
{haveInvoice && !creatingInvoiceError && (
<View style={{ marginTop: 10 }}>
<View>
{selectedIndex == 0 &&
!belowDustLimit &&
haveUnifiedInvoice && (
Expand All @@ -1806,6 +1806,12 @@ export default class Receive extends React.Component<
: ZIcon
}
nfcSupported={nfcSupported}
satAmount={satAmount}
displayAmount={
settings?.invoices
?.displayAmountOnInvoice ||
false
}
/>
)}
{selectedIndex == 1 &&
Expand All @@ -1830,6 +1836,12 @@ export default class Receive extends React.Component<
: LightningIcon
}
nfcSupported={nfcSupported}
satAmount={satAmount}
displayAmount={
settings?.invoices
?.displayAmountOnInvoice ||
false
}
/>
)}
{selectedIndex == 2 &&
Expand All @@ -1854,6 +1866,16 @@ export default class Receive extends React.Component<
: OnChainIcon
}
nfcSupported={nfcSupported}
satAmount={
satAmount === '0'
? undefined
: satAmount
}
displayAmount={
settings?.invoices
?.displayAmountOnInvoice ||
false
}
/>
)}

Expand Down Expand Up @@ -1949,6 +1971,12 @@ export default class Receive extends React.Component<
textBottom
truncateLongValue
nfcSupported={nfcSupported}
satAmount={satAmount}
displayAmount={
settings?.invoices
?.displayAmountOnInvoice ||
false
}
/>
)}
{!(
Expand Down
49 changes: 46 additions & 3 deletions views/Settings/InvoicesSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface InvoicesSettingsState {
ampInvoice: boolean;
blindedPaths: boolean;
showCustomPreimageField: boolean;
displayAmountOnInvoice: boolean;
}

@inject('SettingsStore')
Expand All @@ -54,7 +55,8 @@ export default class InvoicesSettings extends React.Component<
routeHints: false,
ampInvoice: false,
blindedPaths: false,
showCustomPreimageField: false
showCustomPreimageField: false,
displayAmountOnInvoice: false
};

async UNSAFE_componentWillMount() {
Expand All @@ -72,7 +74,9 @@ export default class InvoicesSettings extends React.Component<
ampInvoice: settings?.invoices?.ampInvoice || false,
blindedPaths: settings?.invoices?.blindedPaths || false,
showCustomPreimageField:
settings?.invoices?.showCustomPreimageField || false
settings?.invoices?.showCustomPreimageField || false,
displayAmountOnInvoice:
settings?.invoices?.displayAmountOnInvoice || false
});
}

Expand All @@ -98,7 +102,8 @@ export default class InvoicesSettings extends React.Component<
routeHints,
ampInvoice,
blindedPaths,
showCustomPreimageField
showCustomPreimageField,
displayAmountOnInvoice
} = this.state;
const { implementation, updateSettings }: any = SettingsStore;

Expand Down Expand Up @@ -506,6 +511,44 @@ export default class InvoicesSettings extends React.Component<
/>
</>
)}

<>
<Text
style={{
...styles.secondaryText,
color: themeColor('secondaryText'),
top: 20
}}
>
{localeString(
'views.Settings.Invoices.displayAmountOnInvoice'
)}
{}
</Text>
<Switch
value={displayAmountOnInvoice}
onValueChange={async () => {
this.setState({
displayAmountOnInvoice:
!displayAmountOnInvoice
});
await updateSettings({
invoices: {
addressType,
memo,
expiry,
timePeriod,
expirySeconds,
routeHints,
ampInvoice,
showCustomPreimageField,
displayAmountOnInvoice:
!displayAmountOnInvoice
}
});
}}
/>
</>
</View>
<ModalBox
style={{
Expand Down