Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: fix onboarding case
  • Loading branch information
salimtb committed Dec 13, 2025
commit 5525b5d4c7890fdedff028878a9f3dc4e9bdb992
4 changes: 4 additions & 0 deletions packages/assets-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add support for spot prices on multiple new chains: Apechain, Lens, Plume, Flow EVM, Berachain, xrpl-evm, Fraxtal, Lukso, xdc-network, and Plasma ([#7465](https://github.com/MetaMask/core/pull/7465))
- Add `ape` to `SUPPORTED_CURRENCIES` for ApeCoin/Apechain native token ([#7465](https://github.com/MetaMask/core/pull/7465))
- Add `isOnboarded` constructor option to `TokenBalancesController` and `AccountTrackerController` ([#7469](https://github.com/MetaMask/core/pull/7469))
- When `isOnboarded()` returns `false`, balance updates are skipped to prevent unnecessary API calls during onboarding
- `TokenBalancesController.isActive` now also checks `isOnboarded()` in addition to `isUnlocked`
- `AccountTrackerController.#refreshAccounts` now checks `isOnboarded()` before fetching balances

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ export class AccountTrackerController extends StaticIntervalPollingController<Ac

readonly #fetchingEnabled: () => boolean;

readonly #isOnboarded: () => boolean;

/**
* Creates an AccountTracker instance.
*
Expand All @@ -260,6 +262,7 @@ export class AccountTrackerController extends StaticIntervalPollingController<Ac
* @param options.accountsApiChainIds - Function that returns array of chainIds that should use Accounts-API strategy (if supported by API).
* @param options.allowExternalServices - Disable external HTTP calls (privacy / offline mode).
* @param options.fetchingEnabled - Function that returns whether the controller is fetching enabled.
* @param options.isOnboarded - Whether the user has completed onboarding. If false, balance updates are skipped.
*/
constructor({
interval = 10000,
Expand All @@ -270,6 +273,7 @@ export class AccountTrackerController extends StaticIntervalPollingController<Ac
accountsApiChainIds = () => [],
allowExternalServices = () => true,
fetchingEnabled = () => true,
isOnboarded = () => true,
}: {
interval?: number;
state?: Partial<AccountTrackerControllerState>;
Expand All @@ -279,6 +283,7 @@ export class AccountTrackerController extends StaticIntervalPollingController<Ac
accountsApiChainIds?: () => ChainIdHex[];
allowExternalServices?: () => boolean;
fetchingEnabled?: () => boolean;
isOnboarded?: () => boolean;
}) {
const { selectedNetworkClientId } = messenger.call(
'NetworkController:getState',
Expand Down Expand Up @@ -318,6 +323,7 @@ export class AccountTrackerController extends StaticIntervalPollingController<Ac
];

this.#fetchingEnabled = fetchingEnabled;
this.#isOnboarded = isOnboarded;

this.setIntervalLength(interval);

Expand Down Expand Up @@ -618,7 +624,7 @@ export class AccountTrackerController extends StaticIntervalPollingController<Ac

this.syncAccounts(chainIds);

if (!this.#fetchingEnabled()) {
if (!this.#fetchingEnabled() || !this.#isOnboarded()) {
return;
}

Expand Down
14 changes: 10 additions & 4 deletions packages/assets-controllers/src/TokenBalancesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ export type TokenBalancesControllerOptions = {
platform?: 'extension' | 'mobile';
/** Polling interval when WebSocket is active and providing real-time updates */
websocketActivePollingInterval?: number;
/** Whether the user has completed onboarding. If false, balance updates are skipped. */
isOnboarded?: () => boolean;
};

const draft = <State>(base: State, fn: (draftState: State) => void): State =>
Expand Down Expand Up @@ -274,6 +276,8 @@ export class TokenBalancesController extends StaticIntervalPollingController<{

readonly #allowExternalServices: () => boolean;

readonly #isOnboarded: () => boolean;

readonly #balanceFetchers: BalanceFetcher[];

#allTokens: TokensControllerState['allTokens'] = {};
Expand Down Expand Up @@ -322,6 +326,7 @@ export class TokenBalancesController extends StaticIntervalPollingController<{
accountsApiChainIds = (): ChainIdHex[] => [],
allowExternalServices = (): boolean => true,
platform,
isOnboarded = (): boolean => true,
}: TokenBalancesControllerOptions) {
super({
name: CONTROLLER,
Expand All @@ -336,6 +341,7 @@ export class TokenBalancesController extends StaticIntervalPollingController<{
this.#queryAllAccounts = queryMultipleAccounts;
this.#accountsApiChainIds = accountsApiChainIds;
this.#allowExternalServices = allowExternalServices;
this.#isOnboarded = isOnboarded;
this.#defaultInterval = interval;
this.#websocketActivePollingInterval = websocketActivePollingInterval;
this.#chainPollingConfig = { ...chainPollingIntervals };
Expand Down Expand Up @@ -447,13 +453,13 @@ export class TokenBalancesController extends StaticIntervalPollingController<{
}

/**
* Whether the controller is active (keyring is unlocked).
* When locked, balance updates should be skipped.
* Whether the controller is active (keyring is unlocked and user is onboarded).
* When locked or not onboarded, balance updates should be skipped.
*
* @returns Whether the keyring is unlocked.
* @returns Whether the controller should perform balance updates.
*/
get isActive(): boolean {
return this.#isUnlocked;
return this.#isUnlocked && this.#isOnboarded();
}

/**
Expand Down
Loading