Skip to content

Commit

Permalink
PaymentRequest: handling payment calls from different functions
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamkmr04 committed Oct 8, 2024
1 parent 08f50f4 commit dedd499
Showing 1 changed file with 62 additions and 64 deletions.
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

0 comments on commit dedd499

Please sign in to comment.