Skip to content

Commit

Permalink
Merge pull request #1374 from kaloudis/settings-invoices
Browse files Browse the repository at this point in the history
Settings: Invoices
  • Loading branch information
kaloudis authored Mar 17, 2023
2 parents eb864b8 + 3f64a06 commit 2594140
Show file tree
Hide file tree
Showing 6 changed files with 478 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import PointOfSale from './views/Settings/PointOfSale';
import PointOfSaleRecon from './views/Settings/PointOfSaleRecon';
import PointOfSaleReconExport from './views/Settings/PointOfSaleReconExport';
import PaymentsSettings from './views/Settings/PaymentsSettings';
import InvoicesSettings from './views/Settings/InvoicesSettings';

// Routing
import Routing from './views/Routing/Routing';
Expand Down Expand Up @@ -263,6 +264,9 @@ const AppScenes = {
PaymentsSettings: {
screen: PaymentsSettings
},
InvoicesSettings: {
screen: InvoicesSettings
},
BumpFee: {
screen: BumpFee
}
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@
"views.Settings.Privacy.title": "Privacy settings",
"views.Settings.Payments.title": "Payments settings",
"views.Settings.Payments.defaultFeeLimit": "Default Fee Limit",
"views.Settings.Invoices.title": "Invoices settings",
"views.Settings.Privacy.blockExplorer": "Default Block explorer",
"views.Settings.Privacy.customBlockExplorer": "Custom Block explorer",
"views.Settings.Privacy.lurkerMode": "Lurker mode",
Expand Down
20 changes: 18 additions & 2 deletions stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,20 @@ interface PosSettings {
squareDevMode?: boolean;
}

interface PaymentSettings {
interface PaymentsSettings {
defaultFeeMethod?: string;
defaultFeePercentage?: string;
defaultFeeFixed?: string;
}

interface InvoicesSettings {
addressType?: string;
memo?: string;
expiry?: string;
routeHints?: boolean;
ampInvoice?: boolean;
}

export interface Settings {
nodes?: Array<Node>;
selectedNode?: number;
Expand All @@ -71,7 +79,8 @@ export interface Settings {
privacy: PrivacySettings;
display: DisplaySettings;
pos: PosSettings;
payments: PaymentSettings;
payments: PaymentsSettings;
invoices: InvoicesSettings;
isBiometryEnabled: boolean;
supportedBiometryType?: BiometryType;
lndHubLnAuthMode?: string;
Expand Down Expand Up @@ -258,6 +267,13 @@ export default class SettingsStore {
defaultFeePercentage: '0.5',
defaultFeeFixed: '100'
},
invoices: {
addressType: '1',
memo: '',
expiry: '3600',
routeHints: false,
ampInvoice: false
},
supportedBiometryType: undefined,
isBiometryEnabled: false,
scramblePin: true,
Expand Down
47 changes: 39 additions & 8 deletions views/Receive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ export default class Receive extends React.Component<
};

async UNSAFE_componentWillMount() {
const { SettingsStore } = this.props;
const { getSettings } = SettingsStore;
const settings = await getSettings();

this.setState({
addressType: settings.invoices.addressType || '1',
memo: settings.invoices.memo || '',
expiry: settings.invoices.expiry || '3600',
routeHints: settings.invoices.routeHints || false,
ampInvoice: settings.invoices.ampInvoice || false
});
}

async componentDidMount() {
const { navigation, InvoicesStore, SettingsStore } = this.props;
const { reset } = InvoicesStore;
const { settings, posStatus } = SettingsStore;
Expand All @@ -132,8 +146,10 @@ export default class Receive extends React.Component<
const amount: string = navigation.getParam('amount');
const autoGenerate: boolean = navigation.getParam('autoGenerate');

const { expiry, routeHints, ampInvoice, addressType } = this.state;

// POS
const memo: string = navigation.getParam('memo');
const memo: string = navigation.getParam('memo', this.state.memo);
const orderId: string = navigation.getParam('orderId');
const orderTotal: string = navigation.getParam('orderTotal');
const orderTip: string = navigation.getParam('orderTip');
Expand Down Expand Up @@ -170,7 +186,14 @@ export default class Receive extends React.Component<
}

if (autoGenerate)
this.autoGenerateInvoice(this.getSatAmount(amount), memo);
this.autoGenerateInvoice(
this.getSatAmount(amount),
memo,
expiry,
routeHints,
ampInvoice,
addressType
);

if (Platform.OS === 'android') {
await this.enableNfc();
Expand Down Expand Up @@ -219,19 +242,27 @@ export default class Receive extends React.Component<
});
};

autoGenerateInvoice = (amount?: string, memo?: string) => {
autoGenerateInvoice = (
amount?: string,
memo?: string,
expiry?: string,
routeHints?: boolean,
ampInvoice?: boolean,
addressType?: string
) => {
const { InvoicesStore } = this.props;
const { createUnifiedInvoice } = InvoicesStore;
const { expiry, ampInvoice, routeHints, addressType } = this.state;

createUnifiedInvoice(
memo || '',
amount || '0',
expiry,
expiry || '3600',
undefined,
ampInvoice,
routeHints,
BackendUtils.supportsAddressTypeSelection() ? addressType : null
ampInvoice || false,
routeHints || false,
BackendUtils.supportsAddressTypeSelection()
? addressType || '1'
: undefined
).then(
({
rHash,
Expand Down
Loading

0 comments on commit 2594140

Please sign in to comment.