Skip to content

fix: dapp connect#116

Open
web3miaomiao wants to merge 2 commits intomainfrom
Falcom/fix/dapp-connect
Open

fix: dapp connect#116
web3miaomiao wants to merge 2 commits intomainfrom
Falcom/fix/dapp-connect

Conversation

@web3miaomiao
Copy link
Copy Markdown
Contributor

@web3miaomiao web3miaomiao commented May 5, 2026

修复了app升级时,老版本dapp连接历史数据库的bug(migration时没有赋值)

Summary by Sourcery

Fix migration of legacy dapp connection history when upgrading the local Dapp database.

Bug Fixes:

  • Ensure Aleo dapp connection history is correctly migrated into the unified dapp history table during database upgrades, preventing loss of old connection records.

Enhancements:

  • Remove the deprecated Aleo-specific history table property from the DappDatabase definition.

Summary by CodeRabbit

  • Chores
    • Removed a deprecated local history structure and cleaned up related declarations.
    • Improved migration logic to preserve existing history during updates and ensure records are correctly categorized to maintain continuity for users.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 5, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors the Dexie migration for dapp connection history so that legacy Aleo connection records are correctly migrated into the new dapp_history table using the migration transaction instead of an instance field, and cleans up the deprecated aleo_history table definition.

Updated class diagram for DappDatabase migration logic

classDiagram
  class Dexie {
    +version(number): Dexie
    +stores(schema): Dexie
    +upgrade(migration): Dexie
  }

  class DappDatabase {
    +dapp_history: Dexie.Table~ConnectHistory,string~
    +request: Dexie.Table~DappRequest,string~
    +constructor()
  }

  class OldDappDatabase {
    +aleo_history: Dexie.Table~AleoConnectHistory,string~
    +dapp_history: Dexie.Table~ConnectHistory,string~
    +request: Dexie.Table~DappRequest,string~
  }

  Dexie <|-- DappDatabase
  Dexie <|-- OldDappDatabase
Loading

File-Level Changes

Change Details Files
Fix migration so legacy Aleo dapp connection history is copied into dapp_history using the Dexie upgrade transaction and remove the deprecated aleo_history table field from the database class.
  • Remove the deprecated aleo_history table property from the DappDatabase class definition.
  • Change the version 3 Dexie upgrade logic to read all rows from the aleo_history table via the transaction, early-returning if empty.
  • Bulk-insert migrated Aleo history records into dapp_history within the same transaction, attaching coinType: CoinType.ALEO to each record.
  • Keep version 4 schema where aleo_history is dropped by setting its store definition to null.
app/database/DappDatabase.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In the migration, bulkAdd will throw if any record conflicts on the primary key; if this migration might run multiple times or on partially-migrated data, consider using bulkPut or handling duplicates explicitly to make it idempotent.
  • Instead of using string-based table access (tx.table("aleo_history") / tx.table("dapp_history")) with a type assertion, consider using the typed table definitions on this (or a typed helper) to avoid the as AleoConnectHistory[] cast and keep the migration strongly typed.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the migration, `bulkAdd` will throw if any record conflicts on the primary key; if this migration might run multiple times or on partially-migrated data, consider using `bulkPut` or handling duplicates explicitly to make it idempotent.
- Instead of using string-based table access (`tx.table("aleo_history")` / `tx.table("dapp_history")`) with a type assertion, consider using the typed table definitions on `this` (or a typed helper) to avoid the `as AleoConnectHistory[]` cast and keep the migration strongly typed.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 895dc292-5c85-45a6-9850-a6ee6218fcc1

📥 Commits

Reviewing files that changed from the base of the PR and between 01a10e7 and 4b71949.

📒 Files selected for processing (1)
  • app/database/DappDatabase.ts

📝 Walkthrough

Walkthrough

Removed the deprecated aleo_history Dexie table member from DappDatabase and replaced the v3 migration with a transaction-based bulk migration that reads aleo_history via tx.table("aleo_history").toArray(), maps entries to include coinType: CoinType.ALEO, and bulk-inserts into dapp_history. Also updated later migrations to drop/clear the old table and normalize missing coinType.

Changes

Database Migration Deprecation & Migration Flow

Layer / File(s) Summary
Schema Removal
app/database/DappDatabase.ts
Remove public class member aleo_history: Dexie.Table<AleoConnectHistory, string> from DappDatabase.
v3 Migration (Data read & transform)
app/database/DappDatabase.ts (version(3) upgrade)
Reads all records from tx.table("aleo_history").toArray(), returns early if none exist, maps entries to include coinType: CoinType.ALEO.
v3 Migration (Bulk write / Wiring)
app/database/DappDatabase.ts (version(3) upgrade)
Performs tx.table("dapp_history").bulkAdd(...) to insert converted entries into dapp_history. Replaces prior this.aleo_history.each(...) iteration approach.
v4 Migration (Drop/Cleanup)
app/database/DappDatabase.ts (version(4) upgrade)
Sets aleo_history to null and clears aleo_connect_history, dropping the old table representation.
v5 Migration (Normalization)
app/database/DappDatabase.ts (version(5) upgrade)
Assigns coinType for histories that lack it by inspecting address prefixes (ALEO vs ETH) and normalizes missing ETH network fields while preserving existing histories.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I hopped through rows both old and new,
Took Aleo traces, gave them hue,
Packed them tight in dapp_history's nest,
A tidy move — a rabbit's best. 🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'fix: dapp connect' is vague and generic, using non-descriptive terms that don't convey meaningful information about the specific migration fix. Consider a more specific title like 'fix: restore Aleo dapp connection history during migration' to clearly indicate the specific issue being addressed.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Microsoft Presidio Analyzer (2.2.362)
app/database/DappDatabase.ts

Microsoft Presidio Analyzer failed to scan this file

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/database/DappDatabase.ts (1)

25-43: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add a forward-fix migration for already-migrated databases.

Version 3's upgrade hook only runs during the v2→v3 transition. Users already on v3 or v4 with pre-existing dapp_history records missing coinType will not be backfilled. The index [address+coinType+network] (line 27) requires this field on all records.

Add a v5 migration to backfill missing coinType values:

Suggested patch
     this.version(4).stores({
       aleo_history: null,
       aleo_connect_history: null,
     });
+
+    this.version(5).upgrade(async (tx) => {
+      const table = tx.table("dapp_history");
+      const rows = (await table
+        .filter((row: Partial<ConnectHistory>) => !row.coinType)
+        .toArray()) as ConnectHistory[];
+
+      if (!rows.length) return;
+
+      await table.bulkPut(
+        rows.map((row) => ({
+          ...row,
+          coinType: CoinType.ALEO,
+        })),
+      );
+    });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/database/DappDatabase.ts` around lines 25 - 43, Add a forward-fix
migration (e.g., this.version(5).upgrade(...)) that scans the dapp_history table
for records missing coinType and backfills them with CoinType.ALEO;
specifically, in the new upgrade handler use tx.table("dapp_history").toArray(),
filter entries where record.coinType === undefined || record.coinType === null,
map each to {...record, coinType: CoinType.ALEO} and write them back with
tx.table("dapp_history").bulkPut(...) (preserving the primary key) so the new
index [address+coinType+network] won’t break for already-migrated v3/v4
databases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@app/database/DappDatabase.ts`:
- Around line 25-43: Add a forward-fix migration (e.g.,
this.version(5).upgrade(...)) that scans the dapp_history table for records
missing coinType and backfills them with CoinType.ALEO; specifically, in the new
upgrade handler use tx.table("dapp_history").toArray(), filter entries where
record.coinType === undefined || record.coinType === null, map each to
{...record, coinType: CoinType.ALEO} and write them back with
tx.table("dapp_history").bulkPut(...) (preserving the primary key) so the new
index [address+coinType+network] won’t break for already-migrated v3/v4
databases.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d290f8af-a347-47b5-b3a2-f77cd348503a

📥 Commits

Reviewing files that changed from the base of the PR and between 90e2f95 and 01a10e7.

📒 Files selected for processing (1)
  • app/database/DappDatabase.ts

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