Skip to content

fix(card): update feature flag listener on CardController#29350

Merged
Brunonascdev merged 1 commit into
mainfrom
fix/card-home-feature-flag-refresh
Apr 27, 2026
Merged

fix(card): update feature flag listener on CardController#29350
Brunonascdev merged 1 commit into
mainfrom
fix/card-home-feature-flag-refresh

Conversation

@Brunonascdev

@Brunonascdev Brunonascdev commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Description

This branch refreshes card home data and Baanx configuration when remote card feature flags change, and fixes a race where a slow unauthenticated fetchCardHomeData could overwrite state after successful submitCredentials.

Feature flags

  • app/selectors/featureFlagController/card/index.ts: exports defaultCardFeatureFlag and resolveCardFeatureFlag (empty remote payload → defaults). selectCardFeatureFlag now uses resolveCardFeatureFlag so the same resolution rules apply in Redux selectors and Engine.

BaanxProvider / init

  • BaanxProvider.ts: accepts optional getCardFeatureFlag (lazy) in addition to legacy cardFeatureFlag. A private getter resolves cardFeatureFlag on each read so URLs/constants track the latest remote flags without recreating the provider.
  • card-controller/index.ts: passes getCardFeatureFlag from RemoteFeatureFlagController:getState + resolveCardFeatureFlag into BaanxProvider.

CardController

  • Subscribes to RemoteFeatureFlagController:stateChange with a selector that serializes remoteFeatureFlags.cardFeature so only meaningful card-flag updates run the handler.
  • #handleCardFeatureFlagChange: if an EVM address is selected, invalidateFetch(), clears cardHomeData / sets cardHomeDataStatus to idle, then refetches card home data.
  • #fetchCardHomeDataWithLogging: centralizes fetchCardHomeData + Logger.error for account switch, feature-flag refresh, submitCredentials, and validateAndRefreshSession.
  • #triggerCardholderCheck (accounts API URL path): uses resolveCardFeatureFlag instead of ad-hoc casting.
  • submitCredentials: sets cardHomeData to null and status idle, calls invalidateFetch(), then fetches—so in-flight unauthenticated responses cannot win over authenticated data.

Messenger / types

Tests

  • CardController.test.ts: subscription to remote feature-flag state; handler clears state and refetches; drops in-flight unauthenticated card home data after successful auth.
  • BaanxProvider.test.ts: getCardFeatureFlag read lazily during getOnChainAssets.

Changelog

CHANGELOG entry: Card — CardController listens for RemoteFeatureFlagController:stateChange and refetches card home data when cardFeature changes; BaanxProvider resolves card feature flags lazily; shared resolveCardFeatureFlag; submitCredentials invalidates in-flight fetches and resets card home state to avoid stale unauthenticated data after login.

Related issues

Fixes: #29348

Manual testing steps

Feature: Card home and Baanx flags stay in sync with remote card feature flags

  Scenario: Remote card feature flag updates while card tab is open
    Given the user is on an EVM account with card session and card home loaded
    When remote `cardFeature` changes (e.g. rollout or config update)
    Then card home data is cleared to idle and refetched
    And Baanx-backed calls use the updated flag-derived config on subsequent requests

  Scenario: Login while an unauthenticated card home fetch is still in flight
    Given an unauthenticated card home fetch has not completed
    When the user completes submitCredentials successfully
    Then authenticated card home data wins and a late unauthenticated response does not overwrite it

  Scenario: Card feature flag change with no selected EVM address
    When RemoteFeatureFlagController emits a card-related change but no EVM address is selected
    Then the handler returns early without refetch errors

Screenshots/Recordings

Before

After

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Updates card state refresh triggers and fetch invalidation logic around auth and feature-flag changes; risk is moderate due to new event subscriptions and potential for extra network calls or missed updates if selectors are wrong.

Overview
Card home data now refreshes when remote cardFeature flags change. CardController subscribes to RemoteFeatureFlagController:stateChange, clears cardHomeData/status back to idle, invalidates any in-flight fetch, and refetches.

Fixes a race where slow unauthenticated fetches could overwrite authenticated state. After successful submitCredentials, the controller resets home data, bumps the fetch generation, and refetches via a shared #fetchCardHomeDataWithLogging helper (also used by account-switch and session refresh paths).

Feature-flag resolution and consumption were tightened. Adds resolveCardFeatureFlag (and exports defaultCardFeatureFlag) to normalize empty remote payloads to defaults; BaanxProvider can now read flags lazily via a getCardFeatureFlag callback wired in cardControllerInit, and the card-controller messenger/types allow the new remote-flag stateChange event.

Tests add coverage for the new subscription behavior, the stale-fetch drop after auth, and lazy flag reads in BaanxProvider.

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

@Brunonascdev Brunonascdev requested a review from a team as a code owner April 24, 2026 21:19
@github-actions

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbotv2 metamaskbotv2 Bot added the team-card Card Team label Apr 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeCard
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 92%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes are scoped entirely to the Card feature domain:

  1. CardController.ts: Added reactive subscription to RemoteFeatureFlagController:stateChange so the controller now refreshes card home data when feature flags change. Also refactored logging into a helper method and added invalidateFetch() before re-fetching after auth to prevent stale data races.

  2. types.ts + card-controller-messenger/index.ts: Added RemoteFeatureFlagControllerStateChangeEvent to the CardController's allowed events and messenger configuration - necessary plumbing for the new subscription.

  3. index.ts (card-controller init): Changed from reading feature flags once at initialization to a lazy getter function that reads current state dynamically - this ensures the BaanxProvider always uses the latest feature flag values.

  4. BaanxProvider.ts: Changed from a static cardFeatureFlag property to a lazy getter via getCardFeatureFlag function, enabling dynamic feature flag reads.

  5. selectors/featureFlagController/card/index.ts: Extracted resolveCardFeatureFlag as a reusable exported function and exported defaultCardFeatureFlag for use in the controller.

These changes improve the Card feature's responsiveness to remote feature flag changes and fix potential stale data issues. The SmokeCard tag covers:

  • Card home screen display
  • Add Funds button with Deposit and Swap funding options
  • Advanced Card Management
  • Card navbar button navigation
  • Card-related analytics events
  • Feature flag controlled behavior

Per the SmokeCard tag description, when selecting SmokeCard, also select SmokeTrade and SmokeConfirmations (Add Funds uses swaps which require transaction confirmations). However, the changes here are purely internal to the Card controller's feature flag handling - they don't touch swap/confirmation flows directly. Still, following the tag dependency guidance, SmokeTrade and SmokeConfirmations should be included as dependent tags.

No other feature areas (accounts, network, browser, identity, etc.) are affected by these changes.

Performance Test Selection:
The changes are behavioral improvements to the Card controller's feature flag handling - making it reactive to flag changes and using lazy getters. These are not UI rendering changes, don't affect list rendering, animations, or critical performance paths. No performance tests are warranted.

View GitHub Actions results

@Brunonascdev Brunonascdev changed the base branch from main to release/7.74.00 April 24, 2026 21:27
@Brunonascdev Brunonascdev requested review from a team as code owners April 24, 2026 21:27
@Brunonascdev Brunonascdev changed the base branch from release/7.74.00 to main April 24, 2026 21:28
@Brunonascdev Brunonascdev removed request for a team April 24, 2026 21:28
@Brunonascdev Brunonascdev removed request for a team April 24, 2026 21:28
@github-actions

Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
12 value mismatches detected (expected — fixture represents an existing user).
View details

@sonarqubecloud

Copy link
Copy Markdown

@Brunonascdev Brunonascdev added this pull request to the merge queue Apr 27, 2026
Merged via the queue into main with commit 890ac4a Apr 27, 2026
125 of 130 checks passed
@Brunonascdev Brunonascdev deleted the fix/card-home-feature-flag-refresh branch April 27, 2026 13:00
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 27, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.76.0 Issue or pull request that will be included in release 7.76.0 label Apr 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.76.0 Issue or pull request that will be included in release 7.76.0 size-M team-card Card Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Asset icons don't load and symbols appear lowercase on new SRP/social account login until app restart.

2 participants