Skip to content

remove sync on startup#84

Merged
keraliss merged 1 commit into
mainfrom
remove_startup_sync
Apr 18, 2026
Merged

remove sync on startup#84
keraliss merged 1 commit into
mainfrom
remove_startup_sync

Conversation

@keraliss
Copy link
Copy Markdown
Collaborator

@keraliss keraliss commented Apr 18, 2026

Summary by CodeRabbit

  • Refactor

    • Improved app startup experience: launches immediately with syncing operations running in the background, eliminating the blocking launch overlay.
  • Style

    • Removed unused CSS utilities and theme variables.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 18, 2026

📝 Walkthrough

Walkthrough

This pull request refactors wallet data fetching and application startup logic. The Wallet component no longer pre-fetches all data before caching; instead, it updates the UI directly and conditionally saves the cache. The app startup flow transitions from a blocking synchronous sync operation to background parallel execution, allowing the main app to initialize immediately while offerbook sync occurs asynchronously. Additionally, unused Tailwind CSS utilities are removed from the style output.

Changes

Cohort / File(s) Summary
Wallet Initialization & Refresh
src/components/wallet/Wallet.js
Removed pre-fetch pattern in refreshAllData; UI updates now call updateBalance/Transactions/Utxos(false) directly. Updated initial fetch to attempt window.api.taker.sync() when shouldFetchFresh is true. Cache saving is now conditional on balance being truthy rather than requiring all data types.
App Startup & Sync Flow
src/js/app.js
Replaced blocking performLaunchSync with startBackgroundOfferbookSync() that initiates offerbook sync and polls status asynchronously. Launch entry points now call startMainApp() immediately instead of awaiting sync, enabling parallel initialization. Error handling shifted to background-oriented logging without UI state changes.
CSS Utilities Cleanup
src/styles/output.css
Removed unused Tailwind utilities and theme variables: --container-3xl, .max-w-3xl, .border-[#FF6B35]/10, .border-white/5, .tracking-[0.2em], and .hover:bg-white/5.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App as app.js
    participant Wallet as Wallet Component
    participant Taker as window.api.taker
    participant UI as Main UI

    rect rgba(100, 150, 200, 0.5)
    Note over App,UI: Old Flow (Blocking Sync)
    User->>App: Initialize App
    App->>Taker: performLaunchSync()
    Taker->>Taker: Sync offerbook
    Taker-->>App: Sync complete
    App->>UI: startMainApp()
    UI->>Wallet: Mount & Initialize
    Wallet->>Taker: fetchBalance/Transactions/Utxos
    Taker-->>Wallet: Data
    Wallet->>Wallet: Cache data
    Wallet->>UI: Update UI
    UI-->>User: App ready
    end

    rect rgba(150, 200, 100, 0.5)
    Note over App,UI: New Flow (Parallel Background Sync)
    User->>App: Initialize App
    App->>UI: startMainApp()
    par Parallel
        App->>Taker: startBackgroundOfferbookSync()
        Taker->>Taker: Async sync offerbook
        Taker-->>Taker: Poll getSyncStatus()
    and
        UI->>Wallet: Mount & Initialize
        Wallet->>Taker: Conditional sync()
        Wallet->>Taker: updateBalance/Transactions/Utxos
        Taker-->>Wallet: Data
        Wallet->>Wallet: Conditional cache
        Wallet->>UI: Update UI
        UI-->>User: App ready immediately
    end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • bug fixes #75: Overlapping CSS edits removing --container-3xl and .max-w-3xl utilities from src/styles/output.css.
  • Sync update #74: Directly related offerbook sync refactoring using window.api.taker.syncOfferbookAndWait() and polling getSyncStatus() instead of the legacy launch-sync flow.
  • log on initial load, swap layout fix, spendable balance fix #77: Related modifications to wallet balance/update flow in Wallet.js and startup sync behavior in app.js affecting similar initialization paths.

Poem

🐰 The sync now hops in the background,
No longer blocking the way,
Fresh wallets dance without delay,
While offerbooks catch up at play,
A parallel path to startup's day! 🌿✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'remove sync on startup' directly and clearly describes the main change: eliminating the synchronization that occurs during application launch.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch remove_startup_sync

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/wallet/Wallet.js`:
- Line 364: The code currently calls saveWalletToCache(balance, transactions,
utxos) whenever balance exists, which can mark incomplete data (missing or
fallback transactions/utxos) as fresh cache; change the guard so you only call
saveWalletToCache when all required pieces are present and valid (e.g., balance
is defined AND transactions is an array (or has expected length) AND utxos is
defined/array), and propagate the same stricter check to the other occurrence
that uses saveWalletToCache (the similar call at the second occurrence). Use the
function/variable names balance, transactions, utxos, and saveWalletToCache to
locate and update both places.
- Around line 515-520: The startup sync block should handle non-thrown failure
responses and avoid overlapping with the background offerbook sync: call
window.api.taker.sync(), inspect its return value and treat { success: false,
error } as a failure (log via console.error('⚠️ Initial wallet sync failed:',
error) including the error object), and do not proceed to fetch/cache data when
sync failed; also guard this startup sync with the same global sync flag used by
the background offerbook sync (check/set the shared sync state used by the main
sync handler and background offerbook sync before calling
window.api.taker.sync() to prevent concurrent syncs), and ensure the flag is
cleared in all failure and success paths so subsequent background syncs can run.

In `@src/js/app.js`:
- Around line 330-346: The poll currently resolves for both failure and success
but always prints "Background offerbook sync complete"; update the logic around
window.api.taker.getSyncStatus(syncId) and the Promise resolution so you only
call console.log('✅ Background offerbook sync complete') when status.success ===
true and syncStatus === 'completed'; otherwise call console.error with context
(e.g., console.error('⚠️ Offerbook sync failed:', status) or the caught error)
and ensure the catch block uses console.error('⚠️ Sync poll error:', err)
instead of console.warn; reference the async poll using setInterval, the
variables status/syncStatus, and the final console.log to make the conditional
logging change.
- Around line 187-188: The call to startMainApp() is currently unawaited and can
produce unhandled rejections from async failures (e.g.,
SwapStateManager.getActiveSwap()); update the places where startMainApp() is
invoked (the blocks that also call startBackgroundOfferbookSync()) to await
startMainApp() (these call sites are already inside async contexts so use
await), while leaving startBackgroundOfferbookSync() invoked without awaiting so
the background sync remains non-blocking; ensure any errors from startMainApp()
propagate or are caught where appropriate.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4fe1bd57-ebee-430b-b799-3176acfa5b50

📥 Commits

Reviewing files that changed from the base of the PR and between 3cfc9e7 and e45316b.

📒 Files selected for processing (3)
  • src/components/wallet/Wallet.js
  • src/js/app.js
  • src/styles/output.css
💤 Files with no reviewable changes (1)
  • src/styles/output.css

updateUtxos(false),
]);

if (balance) saveWalletToCache(balance, transactions, utxos);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid marking partial wallet data as a fresh cache entry.

Saving when only balance exists can cache missing or fallback transactions/utxos as fresh for 15 minutes, hiding a failed transaction/UTXO refresh behind the cache.

🐛 Proposed fix
-      if (balance) saveWalletToCache(balance, transactions, utxos);
+      if (balance && Array.isArray(transactions) && Array.isArray(utxos)) {
+        saveWalletToCache(balance, transactions, utxos);
+      }
-    if (balance) saveWalletToCache(balance, transactions, utxos);
+    if (balance && Array.isArray(transactions) && Array.isArray(utxos)) {
+      saveWalletToCache(balance, transactions, utxos);
+    }

Also applies to: 526-526

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/wallet/Wallet.js` at line 364, The code currently calls
saveWalletToCache(balance, transactions, utxos) whenever balance exists, which
can mark incomplete data (missing or fallback transactions/utxos) as fresh
cache; change the guard so you only call saveWalletToCache when all required
pieces are present and valid (e.g., balance is defined AND transactions is an
array (or has expected length) AND utxos is defined/array), and propagate the
same stricter check to the other occurrence that uses saveWalletToCache (the
similar call at the second occurrence). Use the function/variable names balance,
transactions, utxos, and saveWalletToCache to locate and update both places.

Comment on lines +515 to +520
console.log('🔄 Syncing and fetching fresh data...');
try {
await window.api.taker.sync();
} catch (syncErr) {
console.warn('⚠️ Initial wallet sync failed, proceeding anyway:', syncErr.message);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Validate sync failure responses and avoid overlapping startup syncs.

window.api.taker.sync() can return { success: false, error } without throwing, so this path proceeds to fetch/cache data after a failed sync. It can also overlap with the new background offerbook sync because the main sync handler does not check global sync state.

🐛 Proposed fix
     console.log('🔄 Syncing and fetching fresh data...');
     try {
-      await window.api.taker.sync();
+      const syncState = await window.api.taker.getCurrentSyncState?.();
+      if (!syncState?.isRunning) {
+        await syncWalletState();
+      } else {
+        console.log('⏳ Sync already running, skipping initial wallet sync');
+      }
     } catch (syncErr) {
-      console.warn('⚠️ Initial wallet sync failed, proceeding anyway:', syncErr.message);
+      console.error('⚠️ Initial wallet sync failed, proceeding anyway:', syncErr);
     }

As per coding guidelines, errors should be logged with context using console.error('⚠️ Context:', error).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/wallet/Wallet.js` around lines 515 - 520, The startup sync
block should handle non-thrown failure responses and avoid overlapping with the
background offerbook sync: call window.api.taker.sync(), inspect its return
value and treat { success: false, error } as a failure (log via
console.error('⚠️ Initial wallet sync failed:', error) including the error
object), and do not proceed to fetch/cache data when sync failed; also guard
this startup sync with the same global sync flag used by the background
offerbook sync (check/set the shared sync state used by the main sync handler
and background offerbook sync before calling window.api.taker.sync() to prevent
concurrent syncs), and ensure the flag is cleared in all failure and success
paths so subsequent background syncs can run.

Comment thread src/js/app.js
Comment on lines +187 to +188
startMainApp();
startBackgroundOfferbookSync();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's explore the repository structure
git ls-files | grep -E '\.(js|ts|tsx)$' | head -20

Repository: citadel-tech/taker-app

Length of output: 603


🏁 Script executed:

# Check the file size before reading
wc -l src/js/app.js

Repository: citadel-tech/taker-app

Length of output: 83


🏁 Script executed:

# Read the specific lines mentioned in the review (187-188 and 287-288) with context
sed -n '180,195p' src/js/app.js
echo "---"
sed -n '280,295p' src/js/app.js

Repository: citadel-tech/taker-app

Length of output: 1129


🏁 Script executed:

# Find the startMainApp function definition
rg -n "^(async\s+)?function\s+startMainApp|const\s+startMainApp\s*=" src/js/app.js

Repository: citadel-tech/taker-app

Length of output: 101


🏁 Script executed:

# Search for startMainApp calls to understand the context better
rg -n "startMainApp\(" src/js/app.js

Repository: citadel-tech/taker-app

Length of output: 207


🏁 Script executed:

# Check the startBackgroundOfferbookSync function
rg -n "startBackgroundOfferbookSync" src/js/app.js | head -10

Repository: citadel-tech/taker-app

Length of output: 207


🏁 Script executed:

# Read the startMainApp function definition and implementation
sed -n '353,380p' src/js/app.js

Repository: citadel-tech/taker-app

Length of output: 1205


🏁 Script executed:

# Read the startBackgroundOfferbookSync function
sed -n '322,350p' src/js/app.js

Repository: citadel-tech/taker-app

Length of output: 1083


🏁 Script executed:

# Check all context around all startMainApp calls to see if any are awaited
sed -n '150,160p' src/js/app.js
echo "---"
sed -n '204,214p' src/js/app.js

Repository: citadel-tech/taker-app

Length of output: 589


🏁 Script executed:

# Check if there's error handling for unhandled rejections
rg -n "unhandledrejection|catch|\.then" src/js/app.js | head -20

Repository: citadel-tech/taker-app

Length of output: 342


Await startMainApp() before starting background sync.

startMainApp() is async and will reject if SwapStateManager.getActiveSwap() fails or throws, but these calls don't await it, leaving unhandled rejections. Lines 187-188 and 287-288 are in async contexts where await startMainApp() can be used. Keep startBackgroundOfferbookSync() non-blocking by not awaiting it.

Proposed fix
-        startMainApp();
-        startBackgroundOfferbookSync();
+        await startMainApp();
+        startBackgroundOfferbookSync();
-          startMainApp();
-          startBackgroundOfferbookSync();
+          await startMainApp();
+          startBackgroundOfferbookSync();

Per the **/*.{js,ts,tsx} guideline, use async/await for asynchronous operations.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
startMainApp();
startBackgroundOfferbookSync();
await startMainApp();
startBackgroundOfferbookSync();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/js/app.js` around lines 187 - 188, The call to startMainApp() is
currently unawaited and can produce unhandled rejections from async failures
(e.g., SwapStateManager.getActiveSwap()); update the places where startMainApp()
is invoked (the blocks that also call startBackgroundOfferbookSync()) to await
startMainApp() (these call sites are already inside async contexts so use
await), while leaving startBackgroundOfferbookSync() invoked without awaiting so
the background sync remains non-blocking; ensure any errors from startMainApp()
propagate or are caught where appropriate.

Comment thread src/js/app.js
Comment on lines +330 to +346
await new Promise((resolve) => {
const poll = setInterval(async () => {
try {
const status = await window.api.taker.getSyncStatus(syncId);
const syncStatus = (status.sync || {}).status || 'syncing';
if (!status.success || syncStatus === 'completed' || syncStatus === 'failed') {
clearInterval(poll);
resolve();
}
}, 1000);
});
} else {
if (statusLabel) {
statusLabel.textContent =
syncResult.error || 'Unable to start offerbook sync';
}
if (progressBar) progressBar.style.width = '100%';
}
} catch (err) {
console.warn('⚠️ Sync poll error:', err.message);
clearInterval(poll);
resolve();
}
}, 1000);
});
console.log('✅ Background offerbook sync complete');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Do not log failed offerbook syncs as complete.

The polling loop resolves on status.success === false and on syncStatus === 'failed', but line 346 still logs Background offerbook sync complete. That masks failed or missing syncs as success.

🐛 Proposed fix
-    await new Promise((resolve) => {
+    const finalSyncStatus = await new Promise((resolve) => {
       const poll = setInterval(async () => {
         try {
           const status = await window.api.taker.getSyncStatus(syncId);
           const syncStatus = (status.sync || {}).status || 'syncing';
-          if (!status.success || syncStatus === 'completed' || syncStatus === 'failed') {
+          if (!status.success) {
             clearInterval(poll);
-            resolve();
+            resolve('missing');
+            return;
+          }
+          if (syncStatus === 'completed' || syncStatus === 'failed') {
+            clearInterval(poll);
+            resolve(syncStatus);
           }
         } catch (err) {
-          console.warn('⚠️ Sync poll error:', err.message);
+          console.error('⚠️ Background offerbook sync poll error:', err);
           clearInterval(poll);
-          resolve();
+          resolve('error');
         }
       }, 1000);
     });
+    if (finalSyncStatus !== 'completed') {
+      console.error('⚠️ Background offerbook sync did not complete:', finalSyncStatus);
+      return;
+    }
     console.log('✅ Background offerbook sync complete');

As per coding guidelines, errors should be logged with context using console.error('⚠️ Context:', error).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/js/app.js` around lines 330 - 346, The poll currently resolves for both
failure and success but always prints "Background offerbook sync complete";
update the logic around window.api.taker.getSyncStatus(syncId) and the Promise
resolution so you only call console.log('✅ Background offerbook sync complete')
when status.success === true and syncStatus === 'completed'; otherwise call
console.error with context (e.g., console.error('⚠️ Offerbook sync failed:',
status) or the caught error) and ensure the catch block uses console.error('⚠️
Sync poll error:', err) instead of console.warn; reference the async poll using
setInterval, the variables status/syncStatus, and the final console.log to make
the conditional logging change.

@keraliss keraliss merged commit 3a53773 into main Apr 18, 2026
1 check passed
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.

1 participant