NetworkPreferenceStore

@Singleton
class NetworkPreferenceStore @Inject constructor(context: Context)

The single, DURABLE source of truth for the user's selected network.

Why this exists. The selected network must survive process death. The wallet panel's in-memory selection dies with the process, and a per-app SharedPreferences mirror written with apply() (asynchronous) can be LOST if the OS reclaims the process before the write flushes — the exact failure when a session lock backgrounds the app: a switch to PreProd was silently reverted to the localnet default on the next cold start, so a PreProd send bounced as an UNDEPLOYED wallet.

The fix. Every change is committed SYNCHRONOUSLY (android.content.SharedPreferences.Editor.commit — on disk before set returns, so it survives an immediate kill) and published on the observable selected flow so the panel, the SDK provider, and the host all read ONE value. Process-wide Singleton → exactly one selected StateFlow, so there is no second source to drift out of sync.

Plain prefs: the chosen network is public, not a secret.

Constructors

Link copied to clipboard
@Inject
constructor(context: Context)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val selected: StateFlow<MidnightNetwork>

The selected network — the value the whole app builds the wallet on. Survives a kill.

Functions

Link copied to clipboard

Seed the FIRST-RUN network (e.g. a host's preferred starting chain), but only when the user has never chosen one. A no-op once any choice is persisted — the user's selection always wins over a host default.

Link copied to clipboard
fun set(network: MidnightNetwork)

Persist network DURABLY and publish it. Uses commit() (synchronous), NOT apply(), so the choice is on disk before this returns — it cannot be lost to a process kill that lands between the switch and the next launch.