Skip to content

Portfolio: keep editable defaults and auto-sync address from Farcaster username#1745

Open
Jhonattan2121 wants to merge 3 commits intocanaryfrom
fix/portfolio-autofill
Open

Portfolio: keep editable defaults and auto-sync address from Farcaster username#1745
Jhonattan2121 wants to merge 3 commits intocanaryfrom
fix/portfolio-autofill

Conversation

@Jhonattan2121
Copy link
Collaborator

@Jhonattan2121 Jhonattan2121 commented Feb 1, 2026

Summary

This PR improves the Portfolio fidget so it can:

  • Pre-fill from the logged-in Farcaster account when fields are empty
  • Respect explicit values (including nounspacetom) without being overwritten
  • Auto-sync the wallet address when a Farcaster username is entered

Details

  • Extracted PortfolioUsernameInput to encapsulate username -> address lookup
  • Prevented defaults from being re-applied when users clear fields in the editor
  • Added a fallback to use the Farcaster signer FID when useCurrentFid() is not available

UX behavior

  • Empty fields → auto-fill from logged-in user
  • Custom username → auto-fill address for that user
  • Manual address edits → value is kept

Summary by CodeRabbit

  • New Features

    • New portfolio username input with auto-detection of primary wallet address.
    • Auto-population of username and wallet fields based on resolved user identity.
    • Persisted "last fetched" settings to retain recent username/address choices.
  • Improvements

    • Configurable backfill behavior to avoid unwanted overwrites.
    • Safer handling of defaults to prevent replacing intentional values.
    • Reduced unnecessary saves and more reliable data restoration.

@vercel
Copy link

vercel bot commented Feb 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
space-system Ready Ready Preview, Comment Feb 4, 2026 3:52pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 1, 2026

📝 Walkthrough

Walkthrough

FidgetWrapper gains configurable backfill via dataConfig (supporting lastFetchSettings and disableBackfill) and safer default handling. Portfolio now resolves Farcaster identity and primary wallet addresses, persists last-fetch settings, and delegates username input to a new PortfolioUsernameInput component that auto-derives primary addresses.

Changes

Cohort / File(s) Summary
Backfill Configuration
src/common/fidgets/FidgetWrapper.tsx
Extract dataConfig from bundle config to compute lastFetchSettings and disableBackfill. Add memoized defaultSettingsMap, refine derivedSettings/setValue to avoid overwriting non-empty/default values, and gate backfill by disableBackfill and presence of lastFetchSettings.
Portfolio — identity & persistence
src/fidgets/token/Portfolio.tsx
Component now accepts data and saveData, resolves effective FID/username via useCurrentFid, useFarcasterSigner, useLoadFarcasterUser, useNeynarUser, derives primary wallet addresses, updates iframe URLs based on resolved values, and persists lastFetchSettings when appropriate.
Username input & address derivation
src/fidgets/token/PortfolioUsernameInput.tsx
New PortfolioUsernameInput component that normalizes Farcaster usernames, loads Farcaster/Neynar user data, derives a primary wallet address (exported as getPortfolioPrimaryAddress), and synchronizes updates to parent settings with deduplication safeguards.

Sequence Diagram

sequenceDiagram
    participant User as User
    participant Portfolio as Portfolio
    participant UsernameInput as PortfolioUsernameInput
    participant Neynar as NeynarService
    participant FidgetWrapper as FidgetWrapper

    User->>Portfolio: mount (props: data, saveData)
    Portfolio->>Portfolio: resolve effective FID, signer, identities
    Portfolio->>UsernameInput: render with current/derived username
    User->>UsernameInput: enter/modify username
    UsernameInput->>Neynar: fetch user & verifications
    Neynar-->>UsernameInput: return user + addresses
    UsernameInput->>Portfolio: updateSettings(farcasterUsername, walletAddresses)
    Portfolio->>FidgetWrapper: saveData(lastFetchSettings) (if changed & backfill allowed)
    Portfolio->>Portfolio: update iframe URL with resolved username/addresses
    Portfolio-->>User: render iframe
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nibble on usernames, hop through addresses bright,

Backfill tucked gently, defaults set just right.
A username whispers, a primary address found,
Data saved, iframe tuned — I hop without a sound.

🚥 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 accurately summarizes the main changes: keeping editable defaults and auto-syncing wallet addresses from Farcaster usernames, which are the core features added in this PR.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/portfolio-autofill

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
Contributor

@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: 3

🤖 Fix all issues with AI agents
In `@src/common/fidgets/FidgetWrapper.tsx`:
- Around line 178-184: The useMemo that computes derivedSettings is missing
backfillOverrideKeys and noDefaultOverride in its dependency array, causing
stale values; update the dependency list for the derivedSettings memo (the
useMemo that references backfillOverrideKeys and noDefaultOverride) to include
both backfillOverrideKeys and noDefaultOverride alongside the existing
dependencies (zustandSettings, bundle.config.settings, lastFetchSettings,
defaultSettingsMap, disableBackfill) so the memo recalculates whenever those
values change.

In `@src/fidgets/token/Portfolio.tsx`:
- Around line 167-201: The effect in useEffect that computes shouldAuto
currently treats meta undefined as a username change and can overwrite a
manually provided walletAddresses; modify the shouldAuto logic in Portfolio.tsx
so auto-fill runs only when walletAddresses is empty or when the existing
address matches a previous auto-filled value: check meta?.autoAddressValue and
walletAddresses (the addressInput) and only set shouldAuto = true if
addressInput is falsy OR addressInput === meta?.autoAddressValue; keep username
change handling by comparing meta?.autoAddressUsername to effectiveUsername to
decide whether to refresh the auto value, and then call saveData with
autoAddressUsername/autoAddressValue/backfillOverrideKeys/lastFetchSettings as
before.

In `@src/fidgets/token/PortfolioUsernameInput.tsx`:
- Around line 41-51: The hook in PortfolioUsernameInput.tsx currently uses
lastAppliedRef to track only primaryAddress so changing the username
(normalized) to a different form (e.g., adding/removing "@") won’t reapply
updateSettings; change the check to track both normalized and primaryAddress
(e.g., store a combined key) or perform normalization inside the onChange
handler and set lastAppliedRef to the normalized username + address before
calling updateSettings so updateSettings({ farcasterUsername: normalized,
walletAddresses: primaryAddress }) runs whenever either value meaningfully
changes.
🧹 Nitpick comments (1)
src/common/components/organisms/FidgetSettingsEditor.tsx (1)

211-216: Centralize the Portfolio skip-defaults field list.

The same field list is hard-coded here and in src/common/fidgets/FidgetWrapper.tsx; consider extracting a shared constant to avoid drift.

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