refreshBalance

fun refreshBalance(config: WalletConfig, activity: FragmentActivity, force: Boolean = false)

Bootstrap (if needed) and refresh balances. Progressive: emits Ready as soon as the SDK is built so the user sees their addresses immediately, then re-emits Ready after the full resync lands so the values catch up.

Why two emissions:

  • Addresses are deterministic from the seed and available the moment MidnightSdk.Builder.build() returns — no network round-trip needed.

  • The shielded NIGHT resync replays every zswap event the wallet has seen; on PREPROD/PREVIEW that's potentially thousands of events and takes seconds. Forcing the user to stare at "Reading balance..." for that whole window — when the addresses they need are already derivable — is the bad UX wallet-cli already avoids by showing unshielded first.

The intermediate Ready carries a busy = "Syncing balances…" so the UI can show a subtle "values are catching up" indicator without blocking the rest of the screen.

Triggers seed unlock (biometric) on first call per session; subsequent calls reuse the existing SDK as long as every field of config matches what the SDK was built with.