Skip to content

Commit

Permalink
Merge pull request #1917 from kaloudis/zeus-1900
Browse files Browse the repository at this point in the history
ZEUS-1900: In-transit payments: convert to failed payments
  • Loading branch information
kaloudis committed Dec 26, 2023
2 parents 3e51c3c + abea494 commit 91e7af4
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 12 deletions.
2 changes: 2 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@
"views.OpenChannel.private": "Private",
"views.Payment.title": "Payment",
"views.Payment.inTransitPayment": "In Transit Payment",
"views.Payment.failedPayment": "Failed Payment",
"views.Payment.fee": "Fee",
"views.Payment.paymentHash": "Payment Hash",
"views.Payment.paymentPreimage": "Payment Preimage",
Expand Down Expand Up @@ -806,6 +807,7 @@
"views.ActivityFilter.onChainPayments": "On-chain payments",
"views.ActivityFilter.minimumAmount": "Minimum Amount (sats)",
"views.ActivityFilter.inTransit": "In transit payments",
"views.ActivityFilter.isFailed": "Failed payments",
"general.clearChanges": "Clear changes",
"views.Routing.RoutingEvent.sourceChannel": "Source Channel",
"views.Routing.RoutingEvent.destinationChannel": "Destination Channel",
Expand Down
36 changes: 34 additions & 2 deletions models/Payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,45 @@ export default class Payment extends BaseModel {
return this.preimage || this.payment_preimage;
}

@computed public get isInTransit(): boolean {
@computed public get isIncomplete(): boolean {
return (
this.getPreimage ===
'0000000000000000000000000000000000000000000000000000000000000000'
);
}

@computed public get isInTransit(): boolean {
if (!this.isIncomplete) return false;
if (!this.htlcs) return false;
let inTransit = false;
for (const htlc of this.htlcs) {
if (
htlc.status === 'IN_FLIGHT' ||
htlc.status === lnrpc.HTLCAttempt.HTLCStatus.IN_FLIGHT
) {
inTransit = true;
break;
}
}
return inTransit;
}

@computed public get isFailed(): boolean {
if (!this.isIncomplete) return false;
if (!this.htlcs) return false;
let isFailed = false;
for (const htlc of this.htlcs) {
if (
htlc.status === 'FAILED' ||
htlc.status === lnrpc.HTLCAttempt.HTLCStatus.FAILED
) {
isFailed = true;
break;
}
}
return isFailed;
}

@computed public get getTimestamp(): string | number {
return this.creation_date || this.created_at || this.timestamp || 0;
}
Expand Down Expand Up @@ -142,7 +174,7 @@ export default class Payment extends BaseModel {
const route: any[] = [];
if (
htlc.status === 'SUCCEEDED' ||
htlc.status === lnrpc.HTLCAttempt.HTLCStatus['SUCCEEDED']
htlc.status === lnrpc.HTLCAttempt.HTLCStatus.SUCCEEDED
) {
htlc.route.hops &&
htlc.route.hops.forEach((hop: any) => {
Expand Down
3 changes: 3 additions & 0 deletions stores/ActivityStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Filter {
received: boolean;
unpaid: boolean;
inTransit: boolean;
isFailed: boolean;
unconfirmed: boolean;
zeusPay: boolean;
minimumAmount: number;
Expand All @@ -39,6 +40,7 @@ export const DEFAULT_FILTERS = {
received: true,
unpaid: true,
inTransit: false,
isFailed: false,
unconfirmed: true,
zeusPay: true,
minimumAmount: 0,
Expand Down Expand Up @@ -90,6 +92,7 @@ export default class ActivityStore {
received: true,
unpaid: false,
inTransit: false,
isFailed: false,
unconfirmed: true,
zeusPay: true,
minimumAmount: 0,
Expand Down
13 changes: 8 additions & 5 deletions utils/ActivityFilterUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ class ActivityFilterUtils {

if (filter.onChain == false) {
filteredActivity = filteredActivity.filter(
(activity) =>
!(
activity instanceof Transaction &&
Number(activity.getAmount) != 0
)
(activity) => !(activity instanceof Transaction)
);
}

Expand Down Expand Up @@ -66,6 +62,13 @@ class ActivityFilterUtils {
);
}

if (filter.isFailed == false) {
filteredActivity = filteredActivity.filter(
(activity) =>
!(activity instanceof Payment && activity.isFailed)
);
}

if (filter.unconfirmed == false) {
filteredActivity = filteredActivity.filter(
(activity) =>
Expand Down
6 changes: 5 additions & 1 deletion views/Activity/Activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ export default class Activity extends React.PureComponent<
item.model ===
localeString('views.Payment.title')
) {
displayName = item.isInTransit
displayName = item.isFailed
? localeString(
'views.Payment.failedPayment'
)
: item.isInTransit
? localeString(
'views.Payment.inTransitPayment'
)
Expand Down
10 changes: 9 additions & 1 deletion views/Activity/ActivityFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default class ActivityFilter extends React.Component<
received,
unpaid,
inTransit,
isFailed,
unconfirmed,
zeusPay,
minimumAmount,
Expand Down Expand Up @@ -199,7 +200,14 @@ export default class ActivityFilter extends React.Component<
value: inTransit,
var: 'inTransit',
type: 'Toggle',
condition: true
condition: BackendUtils.isLNDBased()
},
{
label: localeString('views.ActivityFilter.isFailed'),
value: isFailed,
var: 'isFailed',
type: 'Toggle',
condition: BackendUtils.isLNDBased()
},
{
label: 'ZEUS PAY',
Expand Down
10 changes: 7 additions & 3 deletions views/Payment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export default class PaymentView extends React.Component<PaymentProps> {
getPreimage,
enhancedPath,
getMemo,
isInTransit
isIncomplete,
isInTransit,
isFailed
} = payment;
const date = getDisplayTime;
const noteKey =
Expand All @@ -105,7 +107,9 @@ export default class PaymentView extends React.Component<PaymentProps> {
<Header
leftComponent="Back"
centerComponent={{
text: isInTransit
text: isFailed
? localeString('views.Payment.failedPayment')
: isInTransit
? localeString('views.Payment.inTransitPayment')
: localeString('views.Payment.title'),
style: {
Expand Down Expand Up @@ -185,7 +189,7 @@ export default class PaymentView extends React.Component<PaymentProps> {
/>
)}

{getPreimage && !isInTransit && (
{getPreimage && !isIncomplete && (
<KeyValue
keyValue={localeString(
'views.Payment.paymentPreimage'
Expand Down

0 comments on commit 91e7af4

Please sign in to comment.