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

PaymentRequest: Handling payment calls from separate functions #2459

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
126 changes: 62 additions & 64 deletions views/PaymentRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,66 @@ export default class PaymentRequest extends React.Component<
navigation.navigate('SendingLightning');
};

triggerPayment = () => {
const { InvoicesStore, LnurlPayStore, SettingsStore } = this.props;
const {
enableMultiPathPayment,
maxParts,
maxShardAmt,
feeLimitSat,
outgoingChanId,
lastHopPubkey,
satAmount,
timeoutSeconds,
maxFeePercent,
enableAtomicMultiPathPayment
} = this.state;

const { paymentRequest, pay_req } = InvoicesStore;
const { implementation } = SettingsStore;

const isLnd: boolean = BackendUtils.isLNDBased();
const isCLightning: boolean =
implementation === 'c-lightning-REST' ||
implementation === 'cln-rest';

// Zaplocker
const { isZaplocker } = LnurlPayStore;

// Broadcast attestation if Zaplocker is enabled
if (isZaplocker) LnurlPayStore.broadcastAttestation();

// handle fee percents that use commas
const maxFeePercentFormatted = maxFeePercent.replace(/,/g, '.');

let lockAtomicMultiPathPayment = false;
if (
pay_req &&
pay_req.features &&
pay_req.features['30'] &&
pay_req.features['30'].is_required
) {
lockAtomicMultiPathPayment = true;
}

const enableAmp: boolean =
enableAtomicMultiPathPayment || lockAtomicMultiPathPayment;

// Call sendPayment with the freshest values
this.sendPayment({
payment_request: paymentRequest,
amount: satAmount ? satAmount.toString() : undefined,
max_parts: enableMultiPathPayment ? maxParts : null,
max_shard_amt: enableMultiPathPayment ? maxShardAmt : null,
fee_limit_sat: isLnd ? feeLimitSat : null,
max_fee_percent: isCLightning ? maxFeePercentFormatted : null,
outgoing_chan_id: outgoingChanId,
last_hop_pubkey: lastHopPubkey,
amp: enableAmp,
timeout_seconds: timeoutSeconds
});
};

render() {
const {
InvoicesStore,
Expand All @@ -283,13 +343,8 @@ export default class PaymentRequest extends React.Component<
enableAtomicMultiPathPayment,
maxParts,
maxShardAmt,
feeLimitSat,
feeOption,
maxFeePercent,
outgoingChanId,
lastHopPubkey,
customAmount,
satAmount,
zaplockerToggle,
settingsToggle,
timeoutSeconds,
Expand Down Expand Up @@ -324,9 +379,6 @@ export default class PaymentRequest extends React.Component<
const payment_hash = pay_req && pay_req.payment_hash;
const timestamp = pay_req && pay_req.timestamp;

// handle fee percents that use commas
const maxFeePercentFormatted = maxFeePercent.replace(/,/g, '.');

let lockAtomicMultiPathPayment = false;
if (
pay_req &&
Expand Down Expand Up @@ -1048,33 +1100,7 @@ export default class PaymentRequest extends React.Component<
)}
{requestAmount >= 10000 ? (
<SwipeButton
onSwipeSuccess={() => {
if (isZaplocker)
LnurlPayStore.broadcastAttestation();
this.sendPayment({
payment_request: paymentRequest,
amount: satAmount
? satAmount.toString()
: undefined,
max_parts: enableMultiPathPayment
? maxParts
: null,
max_shard_amt:
enableMultiPathPayment
? maxShardAmt
: null,
fee_limit_sat: isLnd
? feeLimitSat
: null,
max_fee_percent: isCLightning
? maxFeePercentFormatted
: null,
outgoing_chan_id: outgoingChanId,
last_hop_pubkey: lastHopPubkey,
amp: enableAmp,
timeout_seconds: timeoutSeconds
});
}}
onSwipeSuccess={this.triggerPayment}
instructionText={localeString(
'views.PaymentRequest.slideToPay'
)}
Expand All @@ -1100,35 +1126,7 @@ export default class PaymentRequest extends React.Component<
}
: undefined
}
onPress={() => {
if (isZaplocker)
LnurlPayStore.broadcastAttestation();
this.sendPayment({
payment_request: paymentRequest,
amount: satAmount
? satAmount.toString()
: undefined,
max_parts:
enableMultiPathPayment
? maxParts
: null,
max_shard_amt:
enableMultiPathPayment
? maxShardAmt
: null,
fee_limit_sat: isLnd
? feeLimitSat
: null,
max_fee_percent: isCLightning
? maxFeePercentFormatted
: null,
outgoing_chan_id:
outgoingChanId,
last_hop_pubkey: lastHopPubkey,
amp: enableAmp,
timeout_seconds: timeoutSeconds
});
}}
onPress={this.triggerPayment}
disabled={!lightningReadyToSend}
/>
</View>
Expand Down
Loading