Updated on 2026-08-14
This commit is contained in:
parent
4bf6ea717b
commit
b07a9889f1
1 changed files with 37 additions and 49 deletions
|
|
@ -109,7 +109,6 @@ import kotlinx.coroutines.runBlocking
|
|||
import java.math.BigDecimal
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
import javax.inject.Inject
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
@Suppress("LargeClass", "TooManyFunctions", "LongParameterList")
|
||||
@Stable
|
||||
|
|
@ -121,7 +120,7 @@ internal class StakingModel @Inject constructor(
|
|||
private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase,
|
||||
private val getFeePaidCryptoCurrencyStatusSyncUseCase: GetFeePaidCryptoCurrencyStatusSyncUseCase,
|
||||
private val getMinimumTransactionAmountSyncUseCase: GetMinimumTransactionAmountSyncUseCase,
|
||||
private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase,
|
||||
getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase,
|
||||
private val getUserWalletUseCase: GetUserWalletUseCase,
|
||||
private val sendTransactionUseCase: SendTransactionUseCase,
|
||||
private val createApprovalTransactionUseCase: CreateApprovalTransactionUseCase,
|
||||
|
|
@ -204,7 +203,13 @@ internal class StakingModel @Inject constructor(
|
|||
getUserWalletUseCase(userWalletId).getOrNull(),
|
||||
) { "No wallet found for id: $userWalletId" }
|
||||
}
|
||||
private var appCurrency: AppCurrency by Delegates.notNull()
|
||||
private val currentAppCurrency = getSelectedAppCurrencyUseCase().map { maybeAppCurrency ->
|
||||
maybeAppCurrency.getOrElse { AppCurrency.Default }
|
||||
}.stateIn(
|
||||
scope = modelScope,
|
||||
started = SharingStarted.Eagerly,
|
||||
initialValue = AppCurrency.Default,
|
||||
)
|
||||
|
||||
private val balancesToShow: List<StakingBalanceEntry>
|
||||
get() {
|
||||
|
|
@ -307,10 +312,9 @@ internal class StakingModel @Inject constructor(
|
|||
private val sendTransactionJobHolder = JobHolder()
|
||||
private val stepChangesJobHolder = JobHolder()
|
||||
private val balanceHidingJobHolder = JobHolder()
|
||||
private val currencyStatusJobHolder = JobHolder()
|
||||
|
||||
init {
|
||||
subscribeOnSelectedAppCurrency()
|
||||
subscribeOnCurrencyStatusUpdates()
|
||||
stateController.initializeWithUserWallet(userWallet)
|
||||
}
|
||||
|
||||
|
|
@ -322,7 +326,6 @@ internal class StakingModel @Inject constructor(
|
|||
sendTransactionJobHolder.cancel()
|
||||
stepChangesJobHolder.cancel()
|
||||
balanceHidingJobHolder.cancel()
|
||||
currencyStatusJobHolder.cancel()
|
||||
}
|
||||
|
||||
override fun onBackClick() {
|
||||
|
|
@ -364,7 +367,7 @@ internal class StakingModel @Inject constructor(
|
|||
clickIntents = this@StakingModel,
|
||||
cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus },
|
||||
userWalletProvider = Provider { userWallet },
|
||||
appCurrencyProvider = Provider { appCurrency },
|
||||
appCurrencyProvider = Provider { currentAppCurrency.value },
|
||||
isBalanceHidden = isBalanceHiddenFlow.value,
|
||||
isAccountsModeEnabled = isAccountsModeEnabled,
|
||||
account = account,
|
||||
|
|
@ -398,7 +401,7 @@ internal class StakingModel @Inject constructor(
|
|||
stateController.update(
|
||||
SetConfirmationStateLoadingTransformer(
|
||||
integration = integration,
|
||||
appCurrency = appCurrency,
|
||||
appCurrency = currentAppCurrency.value,
|
||||
cryptoCurrency = cryptoCurrencyStatus.currency,
|
||||
),
|
||||
)
|
||||
|
|
@ -407,7 +410,7 @@ internal class StakingModel @Inject constructor(
|
|||
onStakingFee = { gasEstimate, isFeeApproximate ->
|
||||
stateController.update(
|
||||
SetConfirmationStateAssentTransformer(
|
||||
appCurrencyProvider = Provider { appCurrency },
|
||||
appCurrencyProvider = Provider { currentAppCurrency.value },
|
||||
feeCryptoCurrencyStatus = feeCryptoCurrencyStatus,
|
||||
fee = gasEstimate,
|
||||
isFeeApproximate = isFeeApproximate,
|
||||
|
|
@ -432,7 +435,7 @@ internal class StakingModel @Inject constructor(
|
|||
onApprovalFee = { fee ->
|
||||
stateController.update(
|
||||
SetConfirmationStateAssentApprovalTransformer(
|
||||
appCurrencyProvider = Provider { appCurrency },
|
||||
appCurrencyProvider = Provider { currentAppCurrency.value },
|
||||
feeCryptoCurrencyStatus = feeCryptoCurrencyStatus,
|
||||
fee = fee,
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
|
|
@ -543,7 +546,7 @@ internal class StakingModel @Inject constructor(
|
|||
stateController.updateAll(
|
||||
SetConfirmationStateResetAssentTransformer(cryptoCurrencyStatus),
|
||||
SetConfirmationStateAssentTransformer(
|
||||
appCurrencyProvider = Provider { appCurrency },
|
||||
appCurrencyProvider = Provider { currentAppCurrency.value },
|
||||
feeCryptoCurrencyStatus = feeCryptoCurrencyStatus,
|
||||
fee = increasedFee,
|
||||
isFeeApproximate = isFeeApproximate,
|
||||
|
|
@ -791,7 +794,7 @@ internal class StakingModel @Inject constructor(
|
|||
stateController.update(
|
||||
ShowApprovalBottomSheetTransformer(
|
||||
userWallet = userWallet,
|
||||
appCurrencyProvider = Provider { appCurrency },
|
||||
appCurrencyProvider = Provider { currentAppCurrency.value },
|
||||
cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus },
|
||||
feeCryptoCurrencyStatus = feeCryptoCurrencyStatus,
|
||||
) {
|
||||
|
|
@ -843,7 +846,7 @@ internal class StakingModel @Inject constructor(
|
|||
)
|
||||
stateController.update(
|
||||
SetConfirmationStateAssentApprovalTransformer(
|
||||
appCurrencyProvider = Provider { appCurrency },
|
||||
appCurrencyProvider = Provider { currentAppCurrency.value },
|
||||
feeCryptoCurrencyStatus = feeCryptoCurrencyStatus,
|
||||
fee = TransactionFee.Single(fee),
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
|
|
@ -872,7 +875,7 @@ internal class StakingModel @Inject constructor(
|
|||
)
|
||||
stateController.update(
|
||||
SetConfirmationStateAssentApprovalTransformer(
|
||||
appCurrencyProvider = Provider { appCurrency },
|
||||
appCurrencyProvider = Provider { currentAppCurrency.value },
|
||||
feeCryptoCurrencyStatus = feeCryptoCurrencyStatus,
|
||||
fee = TransactionFee.Single(fee),
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
|
|
@ -930,7 +933,7 @@ internal class StakingModel @Inject constructor(
|
|||
stateController.update(
|
||||
AddStakingNotificationsTransformer(
|
||||
cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus },
|
||||
appCurrencyProvider = Provider { appCurrency },
|
||||
appCurrencyProvider = Provider { currentAppCurrency.value },
|
||||
isAccountInitializedProvider = Provider { isAccountInitialized },
|
||||
feeCryptoCurrencyStatus = feeCryptoCurrencyStatus,
|
||||
currencyWarning = currencyWarning,
|
||||
|
|
@ -1150,7 +1153,7 @@ internal class StakingModel @Inject constructor(
|
|||
ifRight = { fee ->
|
||||
stateController.update(
|
||||
SetFeeToTonInitializeBottomSheetTransformer(
|
||||
appCurrencyProvider = Provider { appCurrency },
|
||||
appCurrencyProvider = Provider { currentAppCurrency.value },
|
||||
feeCryptoCurrencyStatus = feeCryptoCurrencyStatus,
|
||||
fee = fee.normal,
|
||||
isFeeApproximate = false,
|
||||
|
|
@ -1244,24 +1247,21 @@ internal class StakingModel @Inject constructor(
|
|||
isAnyTokenStaked = isAnyTokenStakedUseCase(userWalletId).getOrNull() == true
|
||||
}
|
||||
|
||||
private fun subscribeOnCurrencyStatusUpdatesIfNeeded() {
|
||||
if (currencyStatusJobHolder.isActive.not()) {
|
||||
val job = getAccountCurrencyStatusUseCase(
|
||||
userWalletId = params.userWalletId,
|
||||
currency = params.cryptoCurrency,
|
||||
)
|
||||
.conflate()
|
||||
.distinctUntilChanged()
|
||||
.filter { value.currentStep == StakingStep.InitialInfo || isTopHeatupCase() }
|
||||
.onEach { (maybeAccount, maybeStatus) ->
|
||||
isAccountsModeEnabled = isAccountsModeEnabledUseCase.invokeSync()
|
||||
account = maybeAccount
|
||||
onDataLoaded(maybeStatus)
|
||||
}
|
||||
.flowOn(dispatchers.main)
|
||||
.launchIn(modelScope)
|
||||
currencyStatusJobHolder.update(job)
|
||||
}
|
||||
private fun subscribeOnCurrencyStatusUpdates() {
|
||||
getAccountCurrencyStatusUseCase(
|
||||
userWalletId = params.userWalletId,
|
||||
currency = params.cryptoCurrency,
|
||||
)
|
||||
.conflate()
|
||||
.distinctUntilChanged()
|
||||
.filter { value.currentStep == StakingStep.InitialInfo || isTopHeatupCase() }
|
||||
.onEach { (maybeAccount, maybeStatus) ->
|
||||
isAccountsModeEnabled = isAccountsModeEnabledUseCase.invokeSync()
|
||||
account = maybeAccount
|
||||
onDataLoaded(maybeStatus)
|
||||
}
|
||||
.flowOn(dispatchers.main)
|
||||
.launchIn(modelScope)
|
||||
}
|
||||
|
||||
private suspend fun onDataLoaded(status: CryptoCurrencyStatus) {
|
||||
|
|
@ -1307,7 +1307,7 @@ internal class StakingModel @Inject constructor(
|
|||
transformer = HideBalanceStateTransformer(
|
||||
isBalanceHidden = settings.isBalanceHidden,
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
appCurrency = appCurrency,
|
||||
appCurrency = currentAppCurrency.value,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -1316,18 +1316,6 @@ internal class StakingModel @Inject constructor(
|
|||
.saveIn(balanceHidingJobHolder)
|
||||
}
|
||||
|
||||
private fun subscribeOnSelectedAppCurrency() {
|
||||
getSelectedAppCurrencyUseCase()
|
||||
.conflate()
|
||||
.distinctUntilChanged()
|
||||
.onEach { maybeAppCurrency ->
|
||||
appCurrency = maybeAppCurrency.getOrElse { AppCurrency.Default }
|
||||
subscribeOnCurrencyStatusUpdatesIfNeeded()
|
||||
}
|
||||
.flowOn(dispatchers.main)
|
||||
.launchIn(modelScope)
|
||||
}
|
||||
|
||||
private fun subscribeOnStepChanges(status: CryptoCurrencyStatus) {
|
||||
uiState
|
||||
.distinctUntilChangedBy { it.currentStep }
|
||||
|
|
@ -1384,7 +1372,7 @@ internal class StakingModel @Inject constructor(
|
|||
isAnyTokenStaked = isAnyTokenStaked,
|
||||
cryptoCurrencyStatus = status,
|
||||
userWalletProvider = Provider { userWallet },
|
||||
appCurrencyProvider = Provider { appCurrency },
|
||||
appCurrencyProvider = Provider { currentAppCurrency.value },
|
||||
balancesToShowProvider = Provider { balancesToShow },
|
||||
isAccountsModeEnabled = isAccountsModeEnabled,
|
||||
account = account,
|
||||
|
|
@ -1422,7 +1410,7 @@ internal class StakingModel @Inject constructor(
|
|||
clickIntents = this,
|
||||
cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus },
|
||||
userWalletProvider = Provider { userWallet },
|
||||
appCurrencyProvider = Provider { appCurrency },
|
||||
appCurrencyProvider = Provider { currentAppCurrency.value },
|
||||
isAccountsModeEnabled = isAccountsModeEnabled,
|
||||
isBalanceHidden = isBalanceHiddenFlow.value,
|
||||
account = account,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue