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

feat(lightning): sync stored ldk txs with activity list #1171

Merged
merged 6 commits into from
Jul 27, 2023
Merged

Conversation

Jasonvdb
Copy link
Collaborator

@Jasonvdb Jasonvdb commented Jul 21, 2023

Description

  • Continues to show incoming tx animation even when invoice might not be tracked.
  • Syncs stored claimed and sent txs from react-native-ldk with activity list.
  • Removes pending invoice tracking. That functionality is now in react-native-ldk.
  • Shows incoming payment animation regardless of whether or not the pending is tracked.
  • Slashpay now checks stored claimed payments when refreshing the drive's invoice

Linked Issues/Tasks

#1007

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (improving code without creating new functionality)

Tests

  • Detox test
  • Unit test
  • No test

QA Notes

Hoping incoming animation shows up but if it doesn't at least tx history won't be missing

@Jasonvdb Jasonvdb marked this pull request as draft July 21, 2023 18:47
@Jasonvdb Jasonvdb marked this pull request as ready for review July 26, 2023 13:26
Comment on lines 1498 to 1557
export const syncLightningTxsWithActivityList = async (): Promise<
Result<string>
> => {
let items: TLightningActivityItem[] = [];

const claimedTxs = await lm.getLdkPaymentsClaimed();
for (const tx of claimedTxs) {
//Required to add in bolt11 and description
const invoice = await getPendingInvoice(tx.payment_hash);

items.push({
id: tx.payment_hash,
activityType: EActivityType.lightning,
txType: EPaymentType.received,
message: invoice?.description ?? '',
address: invoice?.to_str ?? '',
confirmed: tx.state === 'successful',
value: tx.amount_sat,
timestamp: tx.unix_timestamp * 1000,
});
}

const sentTxs = await lm.getLdkPaymentsSent();
for (const tx of sentTxs) {
const sats = tx.amount_sat;
if (!sats) {
continue;
}

items.push({
id: tx.payment_hash,
activityType: EActivityType.lightning,
txType: EPaymentType.sent,
message: '',
address: '',
confirmed: tx.state === 'successful',
value: -sats,
timestamp: tx.unix_timestamp * 1000,
});
}

//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({
type: actions.UPDATE_ACTIVITY_ITEMS,
payload: items,
});

return ok('Stored lightning transactions synced with activity list.');
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep all dispatch actions together the syncLightningTxsWithActivityList method should be moved to src/store/actions/lightning.ts

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here 230ef2d

coreyphillips
coreyphillips previously approved these changes Jul 27, 2023
@coreyphillips
Copy link
Collaborator

Not sure why the tests are failing.

@coreyphillips coreyphillips dismissed their stale review July 27, 2023 11:31

Channel seems to remain as pending in Bitkit

@coreyphillips coreyphillips self-requested a review July 27, 2023 18:14
@Jasonvdb
Copy link
Collaborator Author

Channel seems to remain as pending in Bitkit

Ah thanks might have been a race condition, channel was confirmed when I was testing receiving

@Jasonvdb Jasonvdb merged commit a8db976 into master Jul 27, 2023
4 checks passed
@Jasonvdb Jasonvdb deleted the ldk-tx-list branch July 27, 2023 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants