-
Notifications
You must be signed in to change notification settings - Fork 21
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
Conversation
src/utils/lightning/index.ts
Outdated
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.'); | ||
}; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed here 230ef2d
Not sure why the tests are failing. |
Channel seems to remain as pending in Bitkit
Ah thanks might have been a race condition, channel was confirmed when I was testing receiving |
Description
Linked Issues/Tasks
#1007
Type of change
Tests
QA Notes
Hoping incoming animation shows up but if it doesn't at least tx history won't be missing