Controllers manage all application state using valtio proxies. They are framework-agnostic and live in packages/controllers/.
Every controller follows this exact structure:
import { proxy, subscribe as sub } from 'valtio/vanilla'
// Always vanilla
import { subscribeKey as subKey } from 'valtio/vanilla/utils'
import { withErrorBoundary } from '../utils/withErrorBoundary.js'
// -- Types ----
export interface MyControllerState {
someValue: string
loading: boolean
}
// -- State ----
const state = proxy<MyControllerState>({
someValue: '',
loading: false
})
// -- Controller ----
const controller = {
state,
subscribe(callback: (newState: MyControllerState) => void) {
return sub(state, () => callback(state))
},
subscribeKey<K extends keyof MyControllerState>(
key: K,
callback: (value: MyControllerState[K]) => void
) {
return subKey(state, key, callback)
},
setSomeValue(value: string) {
state.someValue = value
}
}
export const MyController = withErrorBoundary(controller)DangerJS enforces these section comments in controller files:
// -- Types ----
// -- State ----
// -- Controller ----
- Always import from
valtio/vanilla, never fromvaltio - Wrap exported controller with
withErrorBoundary - Keep controller surface small: state object + pure methods that mutate state
- Do not import UI code into controllers
- Controllers depend only on foundations/utilities
- Every controller must have corresponding tests in
packages/controllers/tests/
Multi-chain state management. Tracks active chain, active network, per-namespace account data.
ChainController.state.activeChain // Current namespace: 'eip155' | 'solana' | ...
ChainController.state.activeCaipAddress // Current CAIP-10 address
ChainController.state.activeCaipNetwork // Current network
ChainController.state.chains // Map<ChainNamespace, ChainAdapter>Key methods:
switchActiveNetwork(caipNetwork)— Switch to a different networkswitchActiveChainNamespace(namespace)— Switch entire chain ecosystemgetAccountData(namespace?)— Get account state for a namespacesubscribeAccountStateProp(property, callback)— Subscribe to account state changes
Wallet connection lifecycle.
ConnectionController.state.wcUri // WalletConnect URI for QR
ConnectionController.state.wcPairingExpiry // WC pairing timeout
ConnectionController.state.recentWallets // Recently used walletsKey methods:
connect(args)— Initiate wallet connectiondisconnect()— Disconnect current walletsignMessage(message)— Request message signaturesendTransaction(args)— Send a blockchain transaction
Modal view navigation with history stack.
RouterController.state.view // Current view name
RouterController.state.history // Navigation history stack
RouterController.state.data // Data passed to current viewKey methods:
push(view, data?)— Navigate to view, push to historyreplace(view, data?)— Replace current viewreset(view, data?)— Clear history, set viewgoBack()— Pop from history
Modal visibility and loading states.
ModalController.state.open // Modal open/closed
ModalController.state.loading // Loading state
ModalController.state.shake // Shake animation triggerKey methods:
open(options?)— Open modal with optional view/namespaceclose()— Close modalshake()— Trigger shake animation
Manages available wallet connectors, filtering, and discovery.
Feature flags and SDK configuration. Manages enableEmbedded, defaultAccountTypes, allowUnsupportedChain, etc.
| Controller | Purpose |
|---|---|
ApiController |
Wallet/network data fetching from Reown Cloud API |
AccountController |
(Legacy) Account display state |
EventsController |
Event tracking and telemetry |
SendController |
Token transfer transaction state |
SwapController |
Token swap state and execution |
BlockchainApiController |
Transaction history, balance APIs |
ExchangeController |
Fund from exchange flow |
EnsController |
ENS domain resolution |
OnRampController |
Fiat on-ramp provider state |
AssetController |
Token/asset management |
PublicStateController |
Public read-only state |
ThemeController |
Theme mode and variables |
SnackController |
Toast notifications |
AlertController |
Alert dialogs |
TelemetryController |
Analytics and performance |