Skip to content

Commit

Permalink
fix(lightning): remove temp hacks to sync ln activity
Browse files Browse the repository at this point in the history
  • Loading branch information
pwltr committed Mar 7, 2024
1 parent 57a3502 commit 0528daa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 32 deletions.
5 changes: 1 addition & 4 deletions src/store/types/activity.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// import { TPaymentState } from '@synonymdev/react-native-ldk';
import { TPaymentState } from '@synonymdev/react-native-ldk';
import { EPaymentType } from 'beignet';

// TODO: update react-native-ldk and remove
type TPaymentState = 'pending' | 'successful' | 'failed';

export enum EActivityType {
onchain = 'onchain',
lightning = 'lightning',
Expand Down
30 changes: 2 additions & 28 deletions src/store/utils/lightning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { LNURLChannelParams } from 'js-lnurl';
import { err, ok, Result } from '@synonymdev/result';
import { ldk, TChannel, TInvoice } from '@synonymdev/react-native-ldk';
import { getLNURLParams, lnurlChannel } from '@synonymdev/react-native-lnurl';
import { EPaymentType } from 'beignet';

import { dispatch, getLightningStore, getMetaDataStore } from '../helpers';
import { updateActivityItems } from '../slices/activity';
Expand All @@ -17,12 +18,10 @@ import {
import { moveMetaIncTxTag } from '../slices/metadata';
import { updateTransfer } from '../actions/wallet';
import { EAvailableNetwork } from '../../utils/networks';
import { getActivityItemById } from '../../utils/activity';
import { getSelectedNetwork, getSelectedWallet } from '../../utils/wallet';
import {
addPeers,
createPaymentRequest,
decodeLightningInvoice,
getClaimableBalances,
getClaimedLightningPayments,
getCustomLightningPeers,
Expand All @@ -38,7 +37,6 @@ import {
} from '../types/lightning';
import { ETransferType, TWalletName } from '../types/wallet';
import { EActivityType, TLightningActivityItem } from '../types/activity';
import { EPaymentType } from 'beignet';

/**
* Attempts to update the node id for the selected wallet and network.
Expand Down Expand Up @@ -335,24 +333,12 @@ export const syncLightningTxsWithActivityList = async (): Promise<
continue;
}

// Decode invoice to get description
// TODO: Persist description in react-native-ldk so we don't have to decode here
let invoiceNote = '';
if (payment.bolt11_invoice) {
const decodeInvoiceResponse = await decodeLightningInvoice({
paymentRequest: payment.bolt11_invoice,
});
if (decodeInvoiceResponse.isOk()) {
invoiceNote = decodeInvoiceResponse.value.description ?? '';
}
}

items.push({
id: payment.payment_hash,
activityType: EActivityType.lightning,
txType: EPaymentType.sent,
status: payment.state,
message: invoiceNote,
message: payment.description ?? '',
address: payment.bolt11_invoice ?? '',
confirmed: payment.state === 'successful',
value: payment.amount_sat,
Expand All @@ -361,18 +347,6 @@ export const syncLightningTxsWithActivityList = async (): Promise<
});
}

// TODO: remove temp hack when this is complete and descriptions/bolt11 can be added from stored tx: https://github.com/synonymdev/react-native-ldk/issues/156
items.forEach((item) => {
const res = getActivityItemById(item.id);
if (res.isOk()) {
const existingItem = res.value;
if (existingItem.activityType === EActivityType.lightning) {
item.message = existingItem.message;
item.address = existingItem.address;
}
}
});

dispatch(updateActivityItems(items));

return ok('Stored lightning transactions synced with activity list.');
Expand Down

0 comments on commit 0528daa

Please sign in to comment.