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

fix: wait BT to update its database #1944

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions src/store/utils/activity.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { ok, Result } from '@synonymdev/result';
import { ICJitEntry } from '@synonymdev/blocktank-lsp-http-client';
import { TChannel } from '@synonymdev/react-native-ldk';
import { ok, Result } from '@synonymdev/result';
import { EPaymentType } from 'beignet';

import { EActivityType, TLightningActivityItem } from '../types/activity';
import { getBlocktankStore, dispatch } from '../helpers';
import { vibrate } from '../../utils/helpers';
import { getCurrentWallet } from '../../utils/wallet';
import { getChannels } from '../../utils/lightning';
import { formatBoostedActivityItems } from '../../utils/boost';
import { onChainTransactionToActivityItem } from '../../utils/activity';
import { checkPendingCJitEntries } from './blocktank';
import { formatBoostedActivityItems } from '../../utils/boost';
import { sleep, vibrate } from '../../utils/helpers';
import { getChannels } from '../../utils/lightning';
import { getCurrentWallet } from '../../utils/wallet';
import { dispatch, getBlocktankStore } from '../helpers';
import { addActivityItem, updateActivityItems } from '../slices/activity';
import { updateSettings } from '../slices/settings';
import { closeSheet } from '../slices/ui';
import { addActivityItem, updateActivityItems } from '../slices/activity';
import { EActivityType, TLightningActivityItem } from '../types/activity';
import { checkPendingCJitEntries } from './blocktank';
import { showBottomSheet } from './ui';

/**
Expand All @@ -30,13 +31,25 @@ export const addCJitActivityItem = async (channelId: string): Promise<void> => {
return; // No need to take action.
}

// Update any pending CJIT entries.
await checkPendingCJitEntries();
// Try to find the CJIT entry for this channel by funding_txid.
let cJitEntry: ICJitEntry | undefined;
let i = 0;
while (!cJitEntry && i < 5) {
await sleep(1000); // wait until Blocktank has updated its database.
await checkPendingCJitEntries(); // Update any pending CJIT entries.
cJitEntry = getBlocktankStore().cJitEntries.find((entry) => {
return entry?.channel?.fundingTx.id === channel.funding_txid;
});
i++;
}

// If not found by channel id, try to find it by channel size.
if (!cJitEntry) {
cJitEntry = getBlocktankStore().cJitEntries.find((entry) => {
return entry.channelSizeSat === channel.channel_value_satoshis;
});
}

// Check if we have a CJIT entry for this channel.
const cJitEntry = getBlocktankStore().cJitEntries.find((entry) => {
return entry?.channel?.fundingTx.id === channel.funding_txid;
});
if (!cJitEntry) {
// No CJIT entry found for this channel.
// Most likely a normal channel open.
Expand Down
Loading