Skip to content

fix: persist bridge recipient across preview - #222

Draft
tansawit wants to merge 5 commits into
mainfrom
fix/exp-302-recipient-reset
Draft

fix: persist bridge recipient across preview#222
tansawit wants to merge 5 commits into
mainfrom
fix/exp-302-recipient-reset

Conversation

@tansawit

@tansawit tansawit commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Summary

This fixes EXP-302, where a custom bridge recipient address was lost after navigating to the preview screen and back.

The bridge form already persisted the selected chains, denom, quantity, and slippage in localStorage, but it did not persist the recipient field. Because the form remounts when moving through the preview route, the missing recipient value was treated as invalid and the widget replaced it with the default wallet address.

This change adds a dedicated BRIDGE_RECIPIENT localStorage key, writes the recipient into storage alongside the other bridge form fields, and restores it as part of the default bridge form values. That keeps a user-entered recipient stable across the preview round-trip instead of resetting it to the connected wallet address.

Validation

  • Pre-commit hooks ran successfully on the touched files: eslint --fix --max-warnings=0 and prettier --write.

Fixes EXP-302.


Note

Low Risk
Client-side form persistence and disconnect cleanup only; recipient restore is scoped to the connected address to avoid cross-wallet reuse.

Overview
Fixes EXP-302: a custom bridge recipient was dropped when leaving the form for preview and returning, because only chains, denoms, quantity, and slippage were persisted.

The bridge form now saves BRIDGE_RECIPIENT with the other fields. Values are stored as JSON tying connected address to recipient, and are only restored when the same wallet reconnects (case-insensitive); legacy or malformed entries are ignored.

Disconnect clears all bridge form keys (including recipient) via shared clearPersistedBridgeFormValues, replacing inline localStorage removals in useDisconnect. useDefaultValues takes the connected address so the recipient can be rehydrated on remount.

Reviewed by Cursor Bugbot for commit 4d634d5. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • New Features
    • Bridge form now saves and restores the recipient address from previous sessions (only when tied to the currently connected address).
  • Chores
    • Disconnect flow now clears saved bridge form values via a centralized cleanup.
  • Tests
    • Added tests for clearing persisted bridge form data and for validating recipient restoration, including legacy/malformed and mismatched-address cases.

@linear

linear Bot commented Apr 7, 2026

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Apr 7, 2026

Copy link
Copy Markdown

Walkthrough

Bridge form persistence now stores and restores a recipient value tied to the connected address, and disconnect cleanup removes all persisted bridge form keys through a shared helper.

Changes

Bridge recipient persistence

Layer / File(s) Summary
Storage key and helpers
packages/interwovenkit-react/src/data/constants.ts, packages/interwovenkit-react/src/pages/bridge/data/form.ts
Adds LocalStorageKey.BRIDGE_RECIPIENT and recipient persistence helpers that validate stored recipient data against the active address before restoring it.
Bridge form wiring
packages/interwovenkit-react/src/pages/bridge/BridgeForm.tsx, packages/interwovenkit-react/src/pages/bridge/data/form.ts
BridgeForm now loads default values with the current address and persists recipient updates alongside the other bridge form fields.
Cleanup and tests
packages/interwovenkit-react/src/data/bridge-form-storage.ts, packages/interwovenkit-react/src/data/ui.ts, packages/interwovenkit-react/src/data/bridge-form-storage.test.ts, packages/interwovenkit-react/src/pages/bridge/data/form.test.ts
Adds shared bridge-form storage cleanup, switches disconnect handling to use it, and extends tests for both cleanup and recipient restoration behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BridgeForm
  participant useDefaultValues
  participant localStorage
  participant clearPersistedBridgeFormValues

  BridgeForm->>useDefaultValues: useDefaultValues(address)
  useDefaultValues->>localStorage: read BRIDGE_RECIPIENT
  BridgeForm->>localStorage: persist recipient and bridge fields
  BridgeForm->>clearPersistedBridgeFormValues: disconnect cleanup
  clearPersistedBridgeFormValues->>localStorage: remove bridge form keys
Loading

Poem

🐇 I hid a recipient in the burrow wall,
Then matched its address so it fits one and all.
On disconnect, sweep broom in paw,
The bridge keys vanish without a flaw.
🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main fix: persisting the bridge recipient across preview navigation.
✨ 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 fix/exp-302-recipient-reset

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

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 7, 2026

Copy link
Copy Markdown

Deploying interwovenkit-testnet with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4d634d5
Status: ✅  Deploy successful!
Preview URL: https://cd96d4fe.interwovenkit-testnet.pages.dev
Branch Preview URL: https://fix-exp-302-recipient-reset.interwovenkit-testnet.pages.dev

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 7, 2026

Copy link
Copy Markdown

Deploying interwovenkit-staging with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4d634d5
Status: ✅  Deploy successful!
Preview URL: https://f2ea697d.interwovenkit-staging.pages.dev
Branch Preview URL: https://fix-exp-302-recipient-reset.interwovenkit-staging.pages.dev

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 7, 2026

Copy link
Copy Markdown

Deploying interwovenkit with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4d634d5
Status: ✅  Deploy successful!
Preview URL: https://c2551128.interwovenkit.pages.dev
Branch Preview URL: https://fix-exp-302-recipient-reset.interwovenkit.pages.dev

View logs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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

Inline comments:
In `@packages/interwovenkit-react/src/pages/bridge/BridgeForm.tsx`:
- Line 101: The disconnect handler inside useDisconnect currently clears
source/destination/quantity/slippage but omits the persisted recipient; update
the disconnect handler in useDisconnect to remove the stored recipient by
calling localStorage.removeItem for LocalStorageKey.BRIDGE_RECIPIENT so the
recipient address is cleared on wallet disconnect and cannot persist across
sessions.
🪄 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: CHILL

Plan: Pro

Run ID: b479c51d-df22-4a53-b292-a1632c6e2f9f

📥 Commits

Reviewing files that changed from the base of the PR and between fff8722 and edc35d3.

📒 Files selected for processing (3)
  • packages/interwovenkit-react/src/data/constants.ts
  • packages/interwovenkit-react/src/pages/bridge/BridgeForm.tsx
  • packages/interwovenkit-react/src/pages/bridge/data/form.ts

Comment thread packages/interwovenkit-react/src/pages/bridge/BridgeForm.tsx Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Stale recipient not cleared on wallet disconnect
    • The disconnect cleanup now removes the persisted bridge recipient so a previous wallet address cannot be restored after reconnecting.

Create PR

Or push these changes by commenting:

@cursor push eb9ba7010a
Preview (eb9ba7010a)
diff --git a/packages/interwovenkit-react/src/data/ui.ts b/packages/interwovenkit-react/src/data/ui.ts
--- a/packages/interwovenkit-react/src/data/ui.ts
+++ b/packages/interwovenkit-react/src/data/ui.ts
@@ -80,5 +80,6 @@
     localStorage.removeItem(LocalStorageKey.BRIDGE_DST_DENOM)
     localStorage.removeItem(LocalStorageKey.BRIDGE_QUANTITY)
     localStorage.removeItem(LocalStorageKey.BRIDGE_SLIPPAGE_PERCENT)
+    localStorage.removeItem(LocalStorageKey.BRIDGE_RECIPIENT)
   }
 }

You can send follow-ups to the cloud agent here.

Comment thread packages/interwovenkit-react/src/pages/bridge/BridgeForm.tsx Outdated
…-reset

# Conflicts:
#	packages/interwovenkit-react/src/pages/bridge/data/form.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Stale recipient after wallet switch
    • I removed bridge recipient persistence so remounts after an in-widget wallet switch fall back to the current wallet's default destination address again.

Create PR

Or push these changes by commenting:

@cursor push 73573e9510
Preview (73573e9510)
diff --git a/packages/interwovenkit-react/src/pages/bridge/BridgeForm.tsx b/packages/interwovenkit-react/src/pages/bridge/BridgeForm.tsx
--- a/packages/interwovenkit-react/src/pages/bridge/BridgeForm.tsx
+++ b/packages/interwovenkit-react/src/pages/bridge/BridgeForm.tsx
@@ -100,7 +100,6 @@
     localStorage.setItem(LocalStorageKey.BRIDGE_DST_DENOM, dstDenom)
     localStorage.setItem(LocalStorageKey.BRIDGE_QUANTITY, quantity)
     localStorage.setItem(LocalStorageKey.BRIDGE_SLIPPAGE_PERCENT, slippagePercent)
-    localStorage.setItem(LocalStorageKey.BRIDGE_RECIPIENT, recipient)
   }, [
     srcChainId,
     srcDenom,
@@ -108,7 +107,6 @@
     dstDenom,
     quantity,
     slippagePercent,
-    recipient,
     isSrcDenomValid,
     isDstDenomValid,
   ])

diff --git a/packages/interwovenkit-react/src/pages/bridge/data/form.ts b/packages/interwovenkit-react/src/pages/bridge/data/form.ts
--- a/packages/interwovenkit-react/src/pages/bridge/data/form.ts
+++ b/packages/interwovenkit-react/src/pages/bridge/data/form.ts
@@ -72,7 +72,6 @@
     slippagePercent: normalizePersistedSlippage(
       localStorage.getItem(LocalStorageKey.BRIDGE_SLIPPAGE_PERCENT),
     ),
-    recipient: localStorage.getItem(LocalStorageKey.BRIDGE_RECIPIENT),
   })
 
   return {

You can send follow-ups to the cloud agent here.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3b2572b. Configure here.

Comment thread packages/interwovenkit-react/src/pages/bridge/data/form.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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)
packages/interwovenkit-react/src/pages/bridge/BridgeForm.tsx (1)

26-30: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Rehydrate the saved recipient when address arrives

useForm only reads defaultValues on the first render, so if useAddress() is still empty during mount, the saved recipient from useDefaultValues(address) never gets applied. The form then falls back to the chain default instead of the persisted recipient on reconnect/hydration. Re-run recipient initialization when address changes (for example with reset(...) or a targeted setValue("recipient", ...) effect).

🤖 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 `@packages/interwovenkit-react/src/pages/bridge/BridgeForm.tsx` around lines 26
- 30, The BridgeForm form initialization only applies useDefaultValues(address)
on first render, so the persisted recipient is missed when useAddress() resolves
later. Update BridgeForm to rehydrate the recipient when address changes by
adding an effect around useForm/reset or a targeted setValue("recipient", ...)
keyed off address, and keep the recipient in sync with the saved default instead
of falling back to the chain default.
🤖 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 `@packages/interwovenkit-react/src/pages/bridge/BridgeForm.tsx`:
- Around line 26-30: The BridgeForm form initialization only applies
useDefaultValues(address) on first render, so the persisted recipient is missed
when useAddress() resolves later. Update BridgeForm to rehydrate the recipient
when address changes by adding an effect around useForm/reset or a targeted
setValue("recipient", ...) keyed off address, and keep the recipient in sync
with the saved default instead of falling back to the chain default.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e95c5a50-6fb4-4ae6-ae11-b6fcf933d428

📥 Commits

Reviewing files that changed from the base of the PR and between 3b2572b and 4d634d5.

📒 Files selected for processing (3)
  • packages/interwovenkit-react/src/pages/bridge/BridgeForm.tsx
  • packages/interwovenkit-react/src/pages/bridge/data/form.test.ts
  • packages/interwovenkit-react/src/pages/bridge/data/form.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