Skip to content

Commit

Permalink
Merge pull request #2634 from myxmaster/keysend-msg-display
Browse files Browse the repository at this point in the history
Display keysend messages like memos in Activity and Payment
  • Loading branch information
kaloudis authored Dec 19, 2024
2 parents cd38164 + 4c92a6f commit 5a6ee43
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
20 changes: 14 additions & 6 deletions models/Payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import Base64Utils from '../utils/Base64Utils';
import { lnrpc } from '../proto/lightning';
import { notesStore } from '../stores/storeInstances';

const keySendMessageType = '34349334';

interface preimageBuffer {
data: Array<number>;
type: string;
Expand Down Expand Up @@ -79,17 +81,23 @@ export default class Payment extends BaseModel {
}

@computed public get getMemo(): string | undefined {
if (this.getPaymentRequest) {
if (
this.htlcs?.[0]?.route?.hops?.[0]?.custom_records?.[
keySendMessageType
]
) {
const customRecords = this.htlcs[0].route.hops[0].custom_records;
return Base64Utils.base64ToUtf8(customRecords[keySendMessageType]);
} else if (this.getPaymentRequest) {
try {
const decoded: any = bolt11.decode(this.getPaymentRequest);
for (let i = 0; i < decoded.tags.length; i++) {
const tag = decoded.tags[i];
switch (tag.tagName) {
case 'description':
return tag.data;
}
if (tag.tagName === 'description') return tag.data;
}
} catch (e) {}
} catch (e) {
console.log('Error decoding payment request:', e);
}
}
return undefined;
}
Expand Down
6 changes: 3 additions & 3 deletions views/Activity/Activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,12 @@ export default class Activity extends React.PureComponent<
subTitle = (
<Text>
{localeString('general.lightning')}
{item.memo ? ': ' : ''}
{item.memo ? (
{item.getMemo ? ': ' : ''}
{item.getMemo ? (
<Text
style={{ fontStyle: 'italic' }}
>
{item.memo}
{item.getMemo}
</Text>
) : (
''
Expand Down

0 comments on commit 5a6ee43

Please sign in to comment.