> ## Documentation Index
> Fetch the complete documentation index at: https://bkey.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Notifiers

> EmbeddedWalletListNotifier, EmbeddedWalletBalanceNotifier, and EmbeddedWalletTransactionsNotifier.

All three notifiers extend Riverpod's `StateNotifier`. Instantiate them inside `StateNotifierProvider` and inject your [data contracts](/wallets/data-contracts).

***

## EmbeddedWalletListNotifier

Manages the list of wallets.

### Setup

```dart theme={null}
final walletListProvider =
    StateNotifierProvider<EmbeddedWalletListNotifier, EmbeddedWalletListState>(
  (ref) => EmbeddedWalletListNotifier(
    walletDataSource: ref.watch(walletDataSourceProvider),
    storage: ref.watch(walletStorageProvider),
  ),
);
```

### Methods

```dart theme={null}
// Initial load — tries storage cache first, then network
await ref.read(walletListProvider.notifier).fetchWallets();

// Pull-to-refresh — bypasses cache and goes straight to network
await ref.read(walletListProvider.notifier).fetchWallets(isRefresh: true);
```

### State — `EmbeddedWalletListState`

```dart theme={null}
final EmbeddedWalletListState state = ref.watch(walletListProvider);

state.wallets       // List<EmbeddedWallet>? — null while loading the first time
state.isLoading     // bool
state.isRefreshing  // bool — true during pull-to-refresh
state.hasError      // bool
state.failure       // EmbeddedFailure? — non-null when hasError is true
state.errorMessage  // String — human-readable error
```

***

## EmbeddedWalletBalanceNotifier

Manages a `Map<String, double>` of walletId → current balance. Balances are updated independently of the wallet list.

### Setup

```dart theme={null}
final walletBalancesProvider =
    StateNotifierProvider<EmbeddedWalletBalanceNotifier, Map<String, double>>(
  (ref) => EmbeddedWalletBalanceNotifier(
    walletDataSource: ref.watch(walletDataSourceProvider),
    cache: ref.watch(walletBalanceCacheProvider),
  ),
);
```

### Methods

```dart theme={null}
final List<String> ids = wallets.map((w) => w.walletId).toList();

// Use cached balances on first render
await ref.read(walletBalancesProvider.notifier)
    .fetchWalletBalances(ids, isCache: true);

// Bypass cache on pull-to-refresh
await ref.read(walletBalancesProvider.notifier)
    .fetchWalletBalances(ids, isCache: false);
```

### Reading a balance

```dart theme={null}
final Map<String, double> balances = ref.watch(walletBalancesProvider);
final double balance = balances[wallet.walletId] ?? wallet.balance;
```

***

## EmbeddedWalletTransactionsNotifier

Manages cached transaction lists per wallet.

### Setup

```dart theme={null}
final walletTransactionsProvider = StateNotifierProvider<
    EmbeddedWalletTransactionsNotifier,
    EmbeddedWalletTransactionsState>(
  (ref) => EmbeddedWalletTransactionsNotifier(
    walletDataSource: ref.watch(walletDataSourceProvider),
    storage: ref.watch(walletStorageProvider),
  ),
);
```

### Methods

```dart theme={null}
// Fetch for multiple wallets at once (on initial load)
await ref
    .read(walletTransactionsProvider.notifier)
    .fetchTransactionsForWallets(ids, useCache: true);

// On pull-to-refresh
await ref
    .read(walletTransactionsProvider.notifier)
    .fetchTransactionsForWallets(ids, isRefresh: true);
```

### State — `EmbeddedWalletTransactionsState`

```dart theme={null}
final EmbeddedWalletTransactionsState txState =
    ref.watch(walletTransactionsProvider);

// Get transactions for the active wallet
final List<EmbeddedWalletTransaction> txs =
    txState.getTransactionsForWallet(wallet.walletId);

txState.isLoading  // bool
txState.hasError   // bool
txState.failure    // EmbeddedFailure?
```

***

## Wiring all three together

The example app's bootstrap pattern — fetch wallets first, then fan out to balances and transactions in parallel:

```dart theme={null}
Future<void> _bootstrap() async {
  await ref.read(walletListProvider.notifier).fetchWallets();

  final List<String> ids = ref
      .read(walletListProvider)
      .wallets
      ?.map((w) => w.walletId)
      .toList() ?? [];

  if (ids.isEmpty) return;

  await Future.wait([
    ref.read(walletBalancesProvider.notifier)
        .fetchWalletBalances(ids, isCache: true),
    ref.read(walletTransactionsProvider.notifier)
        .fetchTransactionsForWallets(ids, useCache: true),
  ]);
}
```
