Skip to content

Commit 2ae3b2a

Browse files
authored
Merge pull request #804 from soramitsu/merge/staging-to-master
merge/staging-to-master
2 parents 675b38f + cc5d77f commit 2ae3b2a

File tree

5 files changed

+42
-37
lines changed

5 files changed

+42
-37
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ buildscript {
22
ext {
33
// App version
44
versionName = '2.1.0'
5-
versionCode = 80
5+
versionCode = 81
66

77
// SDK and tools
88
compileSdkVersion = 33

common/src/main/java/jp/co/soramitsu/common/validation/Exceptions.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@ class FeeInsufficientBalanceException(resourceManager: ResourceManager) : Valida
5656
resourceManager.getString(R.string.common_not_enough_funds_title),
5757
resourceManager.getString(R.string.common_not_enough_funds_message)
5858
)
59+
60+
class AmountTooLowToStakeException(resourceManager: ResourceManager, minimumAmount: String) : ValidationException(
61+
resourceManager.getString(R.string.common_error_general_title),
62+
resourceManager.getString(R.string.staking_setup_amount_too_low, minimumAmount)
63+
)

common/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ Derivation path: %s</string>
250250
<string name="staking_recommended_custom_title">Choose custom validators </string>
251251
<string name="fee_not_yet_loaded_title">Fee calculation is in progress</string>
252252
<string name="fee_not_yet_loaded_message">Please wait until fee is calculated</string>
253-
<string name="staking_setup_amount_too_low">Can\'t stake less than minimal value (%s)</string>
253+
<string name="staking_setup_amount_too_low">You can\'t stake less than the minimum value (%s)</string>
254254
<string name="common_confirm_title">Confirmation</string>
255255
<string name="staking_confirm_reward_destination">Rewards destination</string>
256256
<string name="staking_stash_title">Wallet account</string>

feature-staking-impl/src/main/java/jp/co/soramitsu/staking/impl/presentation/setup/pool/join/SetupStakingPoolViewModel.kt

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import jp.co.soramitsu.common.utils.applyFiatRate
2121
import jp.co.soramitsu.common.utils.format
2222
import jp.co.soramitsu.common.utils.formatAsCurrency
2323
import jp.co.soramitsu.common.utils.orZero
24+
import jp.co.soramitsu.common.validation.AmountTooLowToStakeException
2425
import jp.co.soramitsu.common.validation.StakeInsufficientBalanceException
2526
import jp.co.soramitsu.feature_staking_impl.R
2627
import jp.co.soramitsu.runtime.multiNetwork.chain.model.Chain
@@ -39,6 +40,7 @@ import kotlinx.coroutines.flow.combine
3940
import kotlinx.coroutines.flow.flow
4041
import kotlinx.coroutines.flow.map
4142
import kotlinx.coroutines.flow.stateIn
43+
import kotlinx.coroutines.launch
4244

4345
@HiltViewModel
4446
class SetupStakingPoolViewModel @Inject constructor(
@@ -144,35 +146,40 @@ class SetupStakingPoolViewModel @Inject constructor(
144146
val setupFlow = stakingPoolSharedStateProvider.requireJoinState
145147
val amount = enteredAmountFlow.value.toBigDecimalOrNull().orZero()
146148

147-
isValid(amount).fold({
148-
stakingPoolSharedStateProvider.joinFlowState.set(setupFlow.copy(amount = amount))
149-
router.openSelectPool()
150-
}, { throwable ->
151-
val message =
152-
throwable.localizedMessage ?: throwable.message ?: resourceManager.getString(R.string.common_undefined_error_message)
153-
val errorAlertViewState = (throwable as? ValidationException)?.let { (title, message) ->
154-
AlertViewState(
155-
title = title,
149+
viewModelScope.launch {
150+
isValid(amount).fold({
151+
stakingPoolSharedStateProvider.joinFlowState.set(setupFlow.copy(amount = amount))
152+
router.openSelectPool()
153+
}, { throwable ->
154+
val message =
155+
throwable.localizedMessage ?: throwable.message ?: resourceManager.getString(R.string.common_undefined_error_message)
156+
val errorAlertViewState = (throwable as? ValidationException)?.let { (title, message) ->
157+
AlertViewState(
158+
title = title,
159+
message = message,
160+
buttonText = resourceManager.getString(R.string.common_got_it),
161+
iconRes = R.drawable.ic_status_warning_16
162+
)
163+
} ?: AlertViewState(
164+
title = resourceManager.getString(R.string.common_error_general_title),
156165
message = message,
157166
buttonText = resourceManager.getString(R.string.common_got_it),
158167
iconRes = R.drawable.ic_status_warning_16
159168
)
160-
} ?: AlertViewState(
161-
title = resourceManager.getString(R.string.common_error_general_title),
162-
message = message,
163-
buttonText = resourceManager.getString(R.string.common_got_it),
164-
iconRes = R.drawable.ic_status_warning_16
165-
)
166-
router.openAlert(errorAlertViewState)
167-
})
169+
router.openAlert(errorAlertViewState)
170+
})
171+
}
168172
}
169173

170-
private fun isValid(amount: BigDecimal): Result<Any> {
174+
private suspend fun isValid(amount: BigDecimal): Result<Any> {
171175
val amountInPlanks = asset.token.planksFromAmount(amount)
172176
val transferableInPlanks = asset.token.planksFromAmount(asset.transferable)
177+
val minToJoinInPlanks = stakingPoolInteractor.getMinToJoinPool(chain.id)
178+
val minToJoinFormatted = asset.token.amountFromPlanks(minToJoinInPlanks).formatTokenAmount(asset.token.configuration)
173179

174180
return when {
175181
amountInPlanks >= transferableInPlanks -> Result.failure(StakeInsufficientBalanceException(resourceManager))
182+
amountInPlanks < minToJoinInPlanks -> Result.failure(AmountTooLowToStakeException(resourceManager, minToJoinFormatted))
176183
else -> Result.success(Unit)
177184
}
178185
}

feature-wallet-impl/src/main/java/jp/co/soramitsu/wallet/impl/domain/WalletInteractorImpl.kt

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,19 @@ class WalletInteractorImpl(
278278
}
279279

280280
override suspend fun markAssetAsHidden(chainId: ChainId, chainAssetId: String) {
281+
manageAssetHidden(chainId, chainAssetId, true)
282+
}
283+
284+
override suspend fun markAssetAsShown(chainId: ChainId, chainAssetId: String) {
285+
manageAssetHidden(chainId, chainAssetId, false)
286+
}
287+
288+
private suspend fun manageAssetHidden(chainId: ChainId, chainAssetId: String, isHidden: Boolean) {
281289
val metaAccount = accountRepository.getSelectedMetaAccount()
282290
val chain = chainRegistry.getChain(chainId)
283291
val accountId = metaAccount.accountId(chain)
284292
val chainAsset = chain.assetsById[chainAssetId] ?: return
293+
285294
val tokenChains = chainRegistry.currentChains.first().filter {
286295
it.assets.any { it.symbolToShow == chainAsset.symbolToShow }
287296
}
@@ -296,28 +305,12 @@ class WalletInteractorImpl(
296305
chainAsset = it,
297306
metaId = metaAccount.id,
298307
accountId = accountId,
299-
isHidden = true
308+
isHidden = isHidden
300309
)
301310
}
302311
}
303312
}
304313

305-
override suspend fun markAssetAsShown(chainId: ChainId, chainAssetId: String) {
306-
val metaAccount = accountRepository.getSelectedMetaAccount()
307-
val chain = chainRegistry.getChain(chainId)
308-
val accountId = metaAccount.accountId(chain)
309-
val chainAsset = chain.assetsById[chainAssetId] ?: return
310-
311-
accountId?.let {
312-
walletRepository.updateAssetHidden(
313-
chainAsset = chainAsset,
314-
metaId = metaAccount.id,
315-
accountId = it,
316-
isHidden = false
317-
)
318-
}
319-
}
320-
321314
override fun selectedMetaAccountFlow(): Flow<MetaAccount> {
322315
return accountRepository.selectedMetaAccountFlow()
323316
}

0 commit comments

Comments
 (0)