HomeScreenViewModel
ViewModel for the Home screen, responsible for fetching and exposing basic user info, account holder status, and account balance from the MTN MOMO API.
Each data-fetching method collects from a kotlinx.coroutines.flow.Flow returned by io.rekast.sdk.repository.DefaultRepository. The flow always emits io.rekast.sdk.repository.data.NetworkResult.Loading first, followed by a terminal io.rekast.sdk.repository.data.NetworkResult.Success or io.rekast.sdk.repository.data.NetworkResult.Error.
Because all four calls on the Home screen launch concurrently, showProgressBar is driven by activeRequestCount — an AtomicInteger that is incremented on each Loading emission and decremented on each terminal emission. The progress bar stays visible until the count reaches zero, preventing any single call from hiding the spinner while the others are still in-flight.
One-off UI events (snackbar messages) are emitted via snackBarStateFlow, a SharedFlow that the composable collects inside a LaunchedEffect.
All API calls are guarded by a check on CredentialStorage.getAccessToken: if no valid token is present the request is skipped and a snackbar is shown instead. In normal operation the access token is provisioned by io.rekast.sdk.sample.views.MainViewModel on first launch and refreshed automatically by TokenAuthenticator on 401.
Constructors
Properties
Holds the fetched AccountBalance for the account; null until the API responds.
Holds the fetched AccountHolderStatus for the account; null until the API responds.
Holds the fetched BasicUserInfo for the authenticated user; null until the API responds.
Controls whether the circular progress indicator is shown on the Home screen.
Flow of SnackBarComponentConfiguration events to be displayed as snackbars.
Functions
Fetches the account balance via the Collection API and posts the result to accountBalance.
Fetches basic user info from the Remittance API and posts the result to basicUserInfo.
Fetches user info with OAuth2 consent from the Remittance API and logs the result.
Validates the account holder status via the Remittance API and posts the result to accountHolderStatus.