```class HomeViewModel: ViewModel() { private ...
# compose
j
Copy code
class HomeViewModel: ViewModel() {
    private val _uiState = MutableStateFlow(HomeUiState())
    val uiState: StateFlow<HomeUiState> = _uiState.asStateFlow()

    private val apiService = RetrofitClient.apiRepository

    suspend fun getBitcoinBRL(): BitcoinBRLModel{
        return withContext(Dispatchers.IO){
            try {
                val bitcoinCurrent = apiService.getCurrentBitcoin()
                val updateBitcoinCurrent = _uiState.value.copy(
                    bitcoinValue = bitcoinCurrent.lastPrice.toDouble(),
                    bitcoinAppreciationValue = bitcoinCurrent.priceChange.toDouble(),
                    bitcoinAppreciationPercentage = bitcoinCurrent.priceChangePercent.toDouble(),
                )
                _uiState.value = updateBitcoinCurrent
                return@withContext bitcoinCurrent
            } catch (e: Exception){
                throw Throwable("Error")
            }
        }
    }

}