mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-22 23:08:07 +01:00
WIP: ldk improvements
This commit is contained in:
parent
87862ab5e7
commit
ca7930c59e
2 changed files with 16 additions and 9 deletions
|
@ -177,7 +177,7 @@ export class LightningLdkWallet extends LightningCustodianWallet {
|
|||
|
||||
async lookupNodeConnectionDetailsByPubkey(pubkey: string) {
|
||||
// first, trying cache:
|
||||
if (this._nodeConnectionDetailsCache[pubkey] && +new Date() - this._nodeConnectionDetailsCache[pubkey].ts < 2 * 14 * 24 * 3600 * 1000) {
|
||||
if (this._nodeConnectionDetailsCache[pubkey] && +new Date() - this._nodeConnectionDetailsCache[pubkey].ts < 4 * 7 * 24 * 3600 * 1000) {
|
||||
// cache hit
|
||||
return this._nodeConnectionDetailsCache[pubkey];
|
||||
}
|
||||
|
@ -307,6 +307,7 @@ export class LightningLdkWallet extends LightningCustodianWallet {
|
|||
// ok, it was sent. now, waiting for an event that it was _actually_ paid:
|
||||
for (let c = 0; c < 60; c++) {
|
||||
await new Promise(resolve => setTimeout(resolve, 500)); // sleep
|
||||
|
||||
for (const sentPayment of RnLdk.sentPayments || []) {
|
||||
const paidHash = LightningLdkWallet.preimage2hash(sentPayment.payment_preimage);
|
||||
if (paidHash === decoded.payment_hash) {
|
||||
|
@ -323,11 +324,10 @@ export class LightningLdkWallet extends LightningCustodianWallet {
|
|||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// timeout. maybe it failed? lets lookup in a list of failed payments:
|
||||
for (const failedPayment of RnLdk.failedPayments) {
|
||||
if (failedPayment.payment_hash === decoded.payment_hash) throw new Error(JSON.stringify(failedPayment));
|
||||
for (const failedPayment of RnLdk.failedPayments || []) {
|
||||
if (failedPayment.payment_hash === decoded.payment_hash) throw new Error(JSON.stringify(failedPayment));
|
||||
}
|
||||
}
|
||||
|
||||
// no? lets just throw timeout error
|
||||
|
@ -481,16 +481,19 @@ export class LightningLdkWallet extends LightningCustodianWallet {
|
|||
try {
|
||||
// exception might be in case of incompletely-started LDK
|
||||
this._listChannels = await RnLdk.listChannels();
|
||||
this._execInBackground(this.checkBlockchain);
|
||||
await this.checkBlockchain();
|
||||
// ^^^ will be executed if above didnt throw exceptions, which means ldk fully started.
|
||||
// we need this for a case when app returns from background if it was in bg for a really long time.
|
||||
// ldk needs to update it's blockchain data, and this is practically the only place where it can
|
||||
// do that (except on cold start)
|
||||
|
||||
await this.reconnectPeersWithPendingChannels();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
try {
|
||||
await this.reconnectPeersWithPendingChannels();
|
||||
} finally {
|
||||
}
|
||||
|
||||
await this.getUserInvoices(); // it internally updates paid user invoices
|
||||
}
|
||||
|
||||
|
|
|
@ -133,11 +133,15 @@ const LdkInfo = () => {
|
|||
allChannelsAmount.current = channelsAvailable;
|
||||
}, [channels, pendingChannels, inactiveChannels]);
|
||||
|
||||
// do we even need periodic sync when user stares at this screen..?
|
||||
useEffect(() => {
|
||||
refetchData().then(() => {
|
||||
refreshDataInterval.current = setInterval(() => {
|
||||
refetchData(false);
|
||||
if (wallet.timeToCheckBlockchain()) wallet.checkBlockchain();
|
||||
if (wallet.timeToCheckBlockchain()) {
|
||||
wallet.checkBlockchain();
|
||||
wallet.reconnectPeersWithPendingChannels();
|
||||
}
|
||||
}, 2000);
|
||||
});
|
||||
return () => {
|
||||
|
|
Loading…
Add table
Reference in a new issue