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

Payment: display memos from payment requests you've paid #1146

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions models/Payment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { computed } from 'mobx';
import bolt11 from 'bolt11';

import BaseModel from './BaseModel';
import DateTimeUtils from './../utils/DateTimeUtils';
import { localeString } from './../utils/LocaleUtils';
Expand All @@ -17,6 +19,7 @@ export default class Payment extends BaseModel {
bolt: string;
status: string;
amount_sent_msat: string;
payment_request: string;
// c-lightning
id?: string;
// payment_hash: string;
Expand All @@ -38,6 +41,24 @@ export default class Payment extends BaseModel {
this.nodes = nodes;
}

@computed public get getPaymentRequest(): string | undefined {
return this.payment_request || this.bolt11;
}

@computed public get getMemo(): string | undefined {
if (this.getPaymentRequest) {
const decoded: any = bolt11.decode(this.payment_request);
for (let i = 0; i < decoded.tags.length; i++) {
const tag = decoded.tags[i];
switch (tag.tagName) {
case 'description':
return tag.data;
}
}
}
return undefined;
}

@computed public get model(): string {
return localeString('views.Payment.title');
}
Expand Down
11 changes: 10 additions & 1 deletion views/Payment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export default class PaymentView extends React.Component<PaymentProps> {
getFee,
payment_hash,
getPreimage,
enhancedPath
enhancedPath,
getMemo
} = payment;
const date = getDisplayTime;

Expand Down Expand Up @@ -121,6 +122,14 @@ export default class PaymentView extends React.Component<PaymentProps> {
/>
)}

{getMemo && (
<KeyValue
keyValue={localeString('views.Receive.memo')}
value={getMemo}
sensitive
/>
)}

{typeof payment_hash === 'string' && (
<KeyValue
keyValue={localeString('views.Payment.paymentHash')}
Expand Down