Skip to content

Commit 90b45d1

Browse files
committed
feat: show lnurl-pay comment in activity detail
1 parent efa2b44 commit 90b45d1

File tree

9 files changed

+64
-1
lines changed

9 files changed

+64
-1
lines changed

e2e/lnurl.e2e.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ d('LNURL', () => {
199199
.toBeVisible()
200200
.withTimeout(10000);
201201
await element(by.id('Close')).tap();
202+
// check if comment is displayed
203+
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
204+
await element(by.id('ActivityShort-1')).tap();
205+
await expect(element(by.id('InvoiceComment'))).toHaveText('test comment');
206+
await element(by.id('NavigationClose')).tap();
202207

203208
// test lnurl-pay, with min == max amount, no comment
204209
const payRequest2 = await lnurl.generateNewUrl('payRequest', {

src/screens/Activity/ActivityDetail.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import {
8181
transferSelector,
8282
} from '../../store/reselect/wallet';
8383
import {
84+
commentSelector,
8485
slashTagsUrlSelector,
8586
tagSelector,
8687
} from '../../store/reselect/metadata';
@@ -684,6 +685,7 @@ const LightningActivityDetail = ({
684685

685686
const dispatch = useAppDispatch();
686687
const tags = useAppSelector((state) => tagSelector(state, id));
688+
const comment = useAppSelector((state) => commentSelector(state, id));
687689
const slashTagsUrl = useAppSelector((state) => {
688690
return slashTagsUrlSelector(state, id);
689691
});
@@ -925,6 +927,22 @@ const LightningActivityDetail = ({
925927
</View>
926928
) : null}
927929

930+
{comment ? (
931+
<View style={styles.invoiceNote}>
932+
<Caption13Up style={styles.sText} color="secondary">
933+
{t('activity_invoice_comment')}
934+
</Caption13Up>
935+
<ThemedView color="white10">
936+
<Canvas style={styles.zRoot}>
937+
<ZigZag color={colors.background} />
938+
</Canvas>
939+
<View style={styles.note}>
940+
<Title testID="InvoiceComment">{comment}</Title>
941+
</View>
942+
</ThemedView>
943+
</View>
944+
) : null}
945+
928946
<View>
929947
<View style={styles.sectionContainer}>
930948
{slashTagsUrl ? (

src/screens/Wallets/LNURLPay/Confirm.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
settingsSelector,
2727
} from '../../../store/reselect/settings';
2828
import { addPendingPayment } from '../../../store/slices/lightning';
29+
import { updateMetaTxComment } from '../../../store/slices/metadata';
2930
import { EActivityType } from '../../../store/types/activity';
3031
import { AnimatedView, BottomSheetTextInput } from '../../../styles/components';
3132
import { Checkmark, LightningHollow } from '../../../styles/icons';
@@ -111,6 +112,15 @@ const LNURLConfirm = ({
111112

112113
setIsLoading(false);
113114

115+
if (comment) {
116+
dispatch(
117+
updateMetaTxComment({
118+
txId: decodedInvoice.payment_hash,
119+
comment,
120+
}),
121+
);
122+
}
123+
114124
if (payInvoiceResponse.isErr()) {
115125
const errorMessage = payInvoiceResponse.error.message;
116126
if (errorMessage === 'Timed Out.') {

src/store/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const persistConfig = {
3232
key: 'root',
3333
storage: reduxStorage,
3434
// increase version after store shape changes
35-
version: 46,
35+
version: 47,
3636
stateReconciler: autoMergeLevel2,
3737
blacklist: ['receive', 'ui'],
3838
migrate: createMigrate(migrations, { debug: __ENABLE_MIGRATION_DEBUG__ }),

src/store/migrations/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ const migrations = {
4545
},
4646
};
4747
},
48+
47: (state): PersistedState => {
49+
return {
50+
...state,
51+
metadata: {
52+
...state.metadata,
53+
comments: {},
54+
},
55+
};
56+
},
4857
};
4958

5059
export default migrations;

src/store/reselect/metadata.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ export const slashTagsUrlSelector = createSelector(
3333
return metadata.slashTagsUrls[id];
3434
},
3535
);
36+
export const commentSelector = createSelector(
37+
[metadataState, (_state, txId: string): string => txId],
38+
(metadata, txId): string => metadata.comments[txId] ?? '',
39+
);

src/store/slices/metadata.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const initialMetadataState: TMetadataState = {
77
lastUsedTags: [],
88
pendingInvoices: [],
99
slashTagsUrls: {},
10+
comments: {},
1011
};
1112

1213
export const metadataSlice = createSlice({
@@ -26,6 +27,16 @@ export const metadataSlice = createSlice({
2627
state.tags[action.payload.txId] = action.payload.tags;
2728
}
2829
},
30+
updateMetaTxComment: (
31+
state,
32+
action: PayloadAction<{ txId: string; comment: string }>,
33+
) => {
34+
if (action.payload.comment.length === 0) {
35+
delete state.comments[action.payload.txId];
36+
} else {
37+
state.comments[action.payload.txId] = action.payload.comment;
38+
}
39+
},
2940
addMetaTxTag: (
3041
state,
3142
action: PayloadAction<{ txId: string; tag: string }>,
@@ -120,6 +131,7 @@ const { actions, reducer } = metadataSlice;
120131
export const {
121132
updateMetadata,
122133
updateMetaTxTags,
134+
updateMetaTxComment,
123135
addMetaTxTag,
124136
deleteMetaTxTag,
125137
updatePendingInvoice,

src/store/types/metadata.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export type TTags = { [txId: string]: string[] };
22
export type TLastUsedTags = string[];
33
export type TSlashTagsUrls = { [txId: string]: string | undefined };
4+
export type TTxComments = { [txId: string]: string };
45

56
export type TPendingInvoice = {
67
id: string; // uuid used to identify the invoice 'session'
@@ -16,4 +17,5 @@ export type TMetadataState = {
1617
// Keep track of pending invoices, right now this is only used to map tags to incoming transactions
1718
pendingInvoices: TPendingInvoice[];
1819
slashTagsUrls: TSlashTagsUrls;
20+
comments: TTxComments;
1921
};

src/utils/i18n/locales/en/wallet.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,9 @@
506506
"activity_invoice_note": {
507507
"string": "Invoice note"
508508
},
509+
"activity_invoice_comment": {
510+
"string": "Comment"
511+
},
509512
"activity_invoice": {
510513
"string": "Invoice"
511514
},

0 commit comments

Comments
 (0)