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

Fix adding route hints to invoice when requesting from keypad if enabled in settings #1909

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 25 additions & 43 deletions views/Receive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ interface ReceiveState {
// LSP
needInbound: boolean;
enableLSP: boolean;
lspIsActive: boolean;
}

@inject(
Expand Down Expand Up @@ -153,7 +154,8 @@ export default class Receive extends React.Component<
rate: 0,
// LSP
needInbound: false,
enableLSP: true
enableLSP: true,
lspIsActive: false
};

async UNSAFE_componentWillMount() {
Expand All @@ -179,7 +181,8 @@ export default class Receive extends React.Component<
expiry: settings?.invoices?.expiry || '3600',
routeHints: settings?.invoices?.routeHints || false,
ampInvoice: settings?.invoices?.ampInvoice || false,
enableLSP: settings?.enableLSP
enableLSP: settings?.enableLSP,
lspIsActive: settings?.enableLSP && BackendUtils.supportsLSPs()
});

const lnOnly =
Expand Down Expand Up @@ -231,8 +234,7 @@ export default class Receive extends React.Component<
this.props.UnitsStore.resetUnits();
let needInbound = false;
if (
BackendUtils.supportsLSPs() &&
settings?.enableLSP &&
this.state.lspIsActive &&
new BigNumber(getSatAmount(lnurl.maxWithdrawable / 1000)).gt(
this.props.ChannelsStore.totalInbound
)
Expand All @@ -250,8 +252,7 @@ export default class Receive extends React.Component<
if (amount) {
let needInbound = false;
if (
BackendUtils.supportsLSPs() &&
settings?.enableLSP &&
this.state.lspIsActive &&
getSatAmount(amount) != '0' &&
new BigNumber(getSatAmount(amount)).gt(
this.props.ChannelsStore.totalInbound
Expand Down Expand Up @@ -289,9 +290,8 @@ export default class Receive extends React.Component<
}

async UNSAFE_componentWillReceiveProps(nextProps: any) {
const { navigation, InvoicesStore, SettingsStore } = nextProps;
const { navigation, InvoicesStore } = nextProps;
const { reset } = InvoicesStore;
const { settings } = SettingsStore;

reset();
const amount: string = navigation.getParam('amount');
Expand All @@ -301,8 +301,7 @@ export default class Receive extends React.Component<
if (amount) {
let needInbound = false;
if (
BackendUtils.supportsLSPs() &&
settings?.enableLSP &&
this.state.lspIsActive &&
getSatAmount(amount) != '0' &&
new BigNumber(getSatAmount(amount)).gt(
this.props.ChannelsStore.totalInbound
Expand All @@ -320,8 +319,7 @@ export default class Receive extends React.Component<
if (lnurl) {
let needInbound = false;
if (
BackendUtils.supportsLSPs() &&
settings?.enableLSP &&
this.state.lspIsActive &&
new BigNumber(getSatAmount(lnurl.maxWithdrawable / 1000)).gt(
this.props.ChannelsStore.totalInbound
)
Expand Down Expand Up @@ -368,16 +366,16 @@ export default class Receive extends React.Component<
addressType?: string
) => {
const { InvoicesStore } = this.props;
const { enableLSP } = this.state;
const { lspIsActive } = this.state;
const { createUnifiedInvoice } = InvoicesStore;

createUnifiedInvoice(
BackendUtils.supportsLSPs() && enableLSP ? '' : memo || '',
lspIsActive ? '' : memo || '',
amount || '0',
expiry || '3600',
undefined,
enableLSP ? false : ampInvoice || false,
enableLSP ? false : routeHints || false,
lspIsActive ? false : ampInvoice || false,
lspIsActive ? false : routeHints || false,
BackendUtils.supportsAddressTypeSelection()
? addressType || '1'
: undefined
Expand Down Expand Up @@ -462,7 +460,7 @@ export default class Receive extends React.Component<

validateAddress = (text: string) => {
const { navigation, InvoicesStore } = this.props;
const { enableLSP } = this.state;
const { lspIsActive } = this.state;
const { createUnifiedInvoice } = InvoicesStore;
const amount = getSatAmount(navigation.getParam('amount'));

Expand All @@ -478,9 +476,7 @@ export default class Receive extends React.Component<
// otherwise we present the user with the create invoice screen
if (Number(amount) > 0) {
createUnifiedInvoice(
BackendUtils.supportsLSPs() && enableLSP
? ''
: memo,
lspIsActive ? '' : memo,
amount.toString(),
'3600',
lnurlParams
Expand Down Expand Up @@ -868,7 +864,8 @@ export default class Receive extends React.Component<
ampInvoice,
routeHints,
needInbound,
enableLSP
enableLSP,
lspIsActive
} = this.state;

const { fontScale } = Dimensions.get('window');
Expand Down Expand Up @@ -1276,8 +1273,7 @@ export default class Receive extends React.Component<
</View>
)}
{haveInvoice &&
BackendUtils.supportsLSPs() &&
enableLSP &&
lspIsActive &&
satAmount === '0' &&
(selectedIndex === 0 ||
selectedIndex === 1) && (
Expand Down Expand Up @@ -1591,10 +1587,7 @@ export default class Receive extends React.Component<
</>
)}

{!(
BackendUtils.supportsLSPs() &&
enableLSP
) && (
{!lspIsActive && (
<>
<Text
style={{
Expand Down Expand Up @@ -1655,8 +1648,7 @@ export default class Receive extends React.Component<
) => {
let needInbound = false;
if (
BackendUtils.supportsLSPs() &&
enableLSP &&
lspIsActive &&
satAmount != '0' &&
new BigNumber(satAmount).gt(
this.props.ChannelsStore
Expand Down Expand Up @@ -1800,10 +1792,7 @@ export default class Receive extends React.Component<
)}

{BackendUtils.isLNDBased() &&
!(
BackendUtils.supportsLSPs() &&
enableLSP
) && (
!lspIsActive && (
<>
<Text
style={{
Expand Down Expand Up @@ -1839,10 +1828,7 @@ export default class Receive extends React.Component<
)}

{BackendUtils.supportsAMP() &&
!(
BackendUtils.supportsLSPs() &&
enableLSP
) && (
!lspIsActive && (
<>
<Text
style={{
Expand Down Expand Up @@ -1892,16 +1878,12 @@ export default class Receive extends React.Component<
}
onPress={() => {
createUnifiedInvoice(
BackendUtils.supportsLSPs() &&
enableLSP
? ''
: memo,
lspIsActive ? '' : memo,
satAmount.toString() ||
'0',
expiry,
lnurl,
BackendUtils.supportsLSPs() &&
enableLSP
lspIsActive
? false
: ampInvoice ||
false,
Expand Down