Updated on 2026-08-14
This commit is contained in:
parent
cc713f0d65
commit
f4ee8b7b88
13 changed files with 55 additions and 37 deletions
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.tangem.tap.common.extensions
|
||||||
|
|
||||||
|
/**
|
||||||
|
[REDACTED_AUTHOR]
|
||||||
|
*/
|
||||||
|
fun <T> List<T>.containsAny(list: List<T>): Boolean {
|
||||||
|
this.forEach { mainItem ->
|
||||||
|
list.forEach { if (it == mainItem) return true }
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,6 @@ package com.tangem.tap.common.redux.global
|
||||||
import com.tangem.TangemSdkError
|
import com.tangem.TangemSdkError
|
||||||
import com.tangem.common.CompletionResult
|
import com.tangem.common.CompletionResult
|
||||||
import com.tangem.tap.common.redux.AppState
|
import com.tangem.tap.common.redux.AppState
|
||||||
import com.tangem.tap.domain.configurable.warningMessage.WarningMessage
|
|
||||||
import com.tangem.tap.domain.configurable.warningMessage.WarningMessagesManager
|
import com.tangem.tap.domain.configurable.warningMessage.WarningMessagesManager
|
||||||
import com.tangem.tap.features.home.redux.HomeAction
|
import com.tangem.tap.features.home.redux.HomeAction
|
||||||
import com.tangem.tap.features.send.redux.SendAction
|
import com.tangem.tap.features.send.redux.SendAction
|
||||||
|
|
@ -45,10 +44,8 @@ val globalMiddleware: Middleware<AppState> = { dispatch, appState ->
|
||||||
store.dispatch(WalletAction.Warnings.CheckHashesCount.SaveCardId)
|
store.dispatch(WalletAction.Warnings.CheckHashesCount.SaveCardId)
|
||||||
}
|
}
|
||||||
|
|
||||||
store.dispatch(WalletAction.Warnings.SetWarnings(
|
store.dispatch(WalletAction.Warnings.Update)
|
||||||
it.getWarnings(WarningMessage.Location.MainScreen)))
|
store.dispatch(SendAction.Warnings.Update)
|
||||||
store.dispatch(SendAction.SetWarnings(
|
|
||||||
it.getWarnings(WarningMessage.Location.SendScreen)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ fun globalReducer(action: Action, state: AppState): GlobalState {
|
||||||
globalState.copy(configManager = action.configManager)
|
globalState.copy(configManager = action.configManager)
|
||||||
}
|
}
|
||||||
is GlobalAction.SetWarningManager -> globalState.copy(warningManager = action.warningManager)
|
is GlobalAction.SetWarningManager -> globalState.copy(warningManager = action.warningManager)
|
||||||
is GlobalAction.HideWarningMessage -> globalState
|
|
||||||
is GlobalAction.UpdateSecurityOptions -> {
|
is GlobalAction.UpdateSecurityOptions -> {
|
||||||
val card = when (action.securityOption) {
|
val card = when (action.securityOption) {
|
||||||
SecurityOption.LongTap -> globalState.scanNoteResponse?.card?.copy(
|
SecurityOption.LongTap -> globalState.scanNoteResponse?.card?.copy(
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,6 @@ class TapWalletManager {
|
||||||
}
|
}
|
||||||
TapWorkarounds.updateCard(data.card)
|
TapWorkarounds.updateCard(data.card)
|
||||||
store.state.globalState.feedbackManager?.infoHolder?.setCardInfo(data.card)
|
store.state.globalState.feedbackManager?.infoHolder?.setCardInfo(data.card)
|
||||||
store.state.globalState.warningManager?.setBlockchain(data.walletManager?.wallet?.blockchain)
|
|
||||||
updateConfigManager(data)
|
updateConfigManager(data)
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
|
|
@ -127,7 +126,6 @@ class TapWalletManager {
|
||||||
|
|
||||||
suspend fun loadData(data: ScanNoteResponse) {
|
suspend fun loadData(data: ScanNoteResponse) {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
store.dispatch(WalletAction.Warnings.CheckIfNeeded)
|
|
||||||
val artworkId = data.verifyResponse?.artworkInfo?.id
|
val artworkId = data.verifyResponse?.artworkInfo?.id
|
||||||
if (data.walletManager != null) {
|
if (data.walletManager != null) {
|
||||||
val config = store.state.globalState.configManager?.config ?: return@withContext
|
val config = store.state.globalState.configManager?.config ?: return@withContext
|
||||||
|
|
@ -175,6 +173,7 @@ class TapWalletManager {
|
||||||
store.dispatch(WalletAction.LoadData.Failure(TapError.UnknownBlockchain))
|
store.dispatch(WalletAction.LoadData.Failure(TapError.UnknownBlockchain))
|
||||||
store.dispatch(WalletAction.LoadArtwork(data.card, artworkId))
|
store.dispatch(WalletAction.LoadArtwork(data.card, artworkId))
|
||||||
}
|
}
|
||||||
|
store.dispatch(WalletAction.Warnings.CheckIfNeeded)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.tangem.tap.domain.configurable.warningMessage
|
||||||
|
|
||||||
import com.tangem.blockchain.common.Blockchain
|
import com.tangem.blockchain.common.Blockchain
|
||||||
import com.tangem.tangem_sdk_new.ui.animation.VoidCallback
|
import com.tangem.tangem_sdk_new.ui.animation.VoidCallback
|
||||||
|
import com.tangem.tap.common.extensions.containsAny
|
||||||
import com.tangem.wallet.R
|
import com.tangem.wallet.R
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -11,7 +12,6 @@ class WarningMessagesManager(
|
||||||
private val warningLoader: RemoteWarningLoader,
|
private val warningLoader: RemoteWarningLoader,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private var blockchain: Blockchain? = null
|
|
||||||
private val warningsList: MutableList<WarningMessage> = mutableListOf()
|
private val warningsList: MutableList<WarningMessage> = mutableListOf()
|
||||||
|
|
||||||
fun load(onComplete: VoidCallback? = null) {
|
fun load(onComplete: VoidCallback? = null) {
|
||||||
|
|
@ -23,10 +23,6 @@ class WarningMessagesManager(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setBlockchain(blockchain: Blockchain?) {
|
|
||||||
this.blockchain = blockchain
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addWarning(warning: WarningMessage) {
|
fun addWarning(warning: WarningMessage) {
|
||||||
if (findWarning(warning) == null) {
|
if (findWarning(warning) == null) {
|
||||||
warningsList.add(warning)
|
warningsList.add(warning)
|
||||||
|
|
@ -34,14 +30,14 @@ class WarningMessagesManager(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getWarnings(location: WarningMessage.Location): List<WarningMessage> {
|
fun getWarnings(location: WarningMessage.Location, forBlockchains: List<Blockchain> = emptyList()): List<WarningMessage> {
|
||||||
return warningsList
|
return warningsList
|
||||||
.filter { !it.isHidden && it.location.contains(location) }
|
.filter { !it.isHidden && it.location.contains(location) }
|
||||||
.filter {
|
.filter {
|
||||||
val blockchainList = it.blockchainList
|
val list = it.blockchainList
|
||||||
when {
|
when {
|
||||||
blockchainList == null -> true
|
list == null -> true
|
||||||
blockchainList.contains(blockchain) -> true
|
list.containsAny(forBlockchains) -> true
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -149,8 +149,13 @@ sealed class SendAction : SendScreenAction {
|
||||||
val sendAllCallback: () -> Unit,
|
val sendAllCallback: () -> Unit,
|
||||||
val reduceAmount: BigDecimal,
|
val reduceAmount: BigDecimal,
|
||||||
) : Dialog()
|
) : Dialog()
|
||||||
data class SendTransactionFails(val errorMessage: String): Dialog()
|
|
||||||
|
data class SendTransactionFails(val errorMessage: String) : Dialog()
|
||||||
object Hide : Dialog()
|
object Hide : Dialog()
|
||||||
}
|
}
|
||||||
data class SetWarnings(val warningList: List<WarningMessage>) : SendAction()
|
|
||||||
|
sealed class Warnings : SendAction() {
|
||||||
|
object Update : SendAction()
|
||||||
|
data class Set(val warningList: List<WarningMessage>) : SendAction()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -15,6 +15,7 @@ import com.tangem.tap.common.redux.global.GlobalAction
|
||||||
import com.tangem.tap.common.redux.navigation.NavigationAction
|
import com.tangem.tap.common.redux.navigation.NavigationAction
|
||||||
import com.tangem.tap.domain.TapError
|
import com.tangem.tap.domain.TapError
|
||||||
import com.tangem.tap.domain.TapWorkarounds
|
import com.tangem.tap.domain.TapWorkarounds
|
||||||
|
import com.tangem.tap.domain.configurable.warningMessage.WarningMessage
|
||||||
import com.tangem.tap.domain.extensions.minimalAmount
|
import com.tangem.tap.domain.extensions.minimalAmount
|
||||||
import com.tangem.tap.features.send.redux.*
|
import com.tangem.tap.features.send.redux.*
|
||||||
import com.tangem.tap.features.send.redux.FeeAction.RequestFee
|
import com.tangem.tap.features.send.redux.FeeAction.RequestFee
|
||||||
|
|
@ -46,6 +47,7 @@ val sendMiddleware: Middleware<AppState> = { dispatch, appState ->
|
||||||
is SendActionUi.SendAmountToRecipient ->
|
is SendActionUi.SendAmountToRecipient ->
|
||||||
verifyAndSendTransaction(action, appState(), dispatch)
|
verifyAndSendTransaction(action, appState(), dispatch)
|
||||||
is PrepareSendScreen -> setIfSendingToPayIdEnabled(appState(), dispatch)
|
is PrepareSendScreen -> setIfSendingToPayIdEnabled(appState(), dispatch)
|
||||||
|
is SendAction.Warnings.Update -> updateWarnings(dispatch)
|
||||||
}
|
}
|
||||||
nextDispatch(action)
|
nextDispatch(action)
|
||||||
}
|
}
|
||||||
|
|
@ -224,3 +226,11 @@ private fun setIfSendingToPayIdEnabled(appState: AppState?, dispatch: (Action) -
|
||||||
dispatch(AddressPayIdActionUi.ChangePayIdState(isSendingToPayIdEnabled))
|
dispatch(AddressPayIdActionUi.ChangePayIdState(isSendingToPayIdEnabled))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateWarnings(dispatch: (Action) -> Unit) {
|
||||||
|
val warningsManager = store.state.globalState.warningManager ?: return
|
||||||
|
val blockchain = store.state.sendState.walletManager?.wallet?.blockchain ?: return
|
||||||
|
|
||||||
|
val warnings = warningsManager.getWarnings(WarningMessage.Location.SendScreen, listOf(blockchain))
|
||||||
|
dispatch(SendAction.Warnings.Set(warnings))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ private class SendReducer : SendInternalReducer {
|
||||||
is SendAction.Dialog.TezosWarningDialog -> sendState.copy(dialog = action)
|
is SendAction.Dialog.TezosWarningDialog -> sendState.copy(dialog = action)
|
||||||
is SendAction.Dialog.SendTransactionFails -> sendState.copy(dialog = action)
|
is SendAction.Dialog.SendTransactionFails -> sendState.copy(dialog = action)
|
||||||
is SendAction.Dialog.Hide -> sendState.copy(dialog = null)
|
is SendAction.Dialog.Hide -> sendState.copy(dialog = null)
|
||||||
is SendAction.SetWarnings -> sendState.copy(sendWarningsList = action.warningList)
|
is SendAction.Warnings.Set -> sendState.copy(sendWarningsList = action.warningList)
|
||||||
else -> return sendState
|
else -> return sendState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ import com.tangem.tap.common.qrCodeScan.ScanQrCodeActivity
|
||||||
import com.tangem.tap.common.snackBar.MaxAmountSnackbar
|
import com.tangem.tap.common.snackBar.MaxAmountSnackbar
|
||||||
import com.tangem.tap.common.text.truncateMiddleWith
|
import com.tangem.tap.common.text.truncateMiddleWith
|
||||||
import com.tangem.tap.common.toggleWidget.*
|
import com.tangem.tap.common.toggleWidget.*
|
||||||
import com.tangem.tap.domain.configurable.warningMessage.WarningMessage
|
|
||||||
import com.tangem.tap.features.send.BaseStoreFragment
|
import com.tangem.tap.features.send.BaseStoreFragment
|
||||||
import com.tangem.tap.features.send.redux.*
|
import com.tangem.tap.features.send.redux.*
|
||||||
import com.tangem.tap.features.send.redux.AddressPayIdActionUi.*
|
import com.tangem.tap.features.send.redux.AddressPayIdActionUi.*
|
||||||
|
|
@ -249,8 +248,7 @@ class SendFragment : BaseStoreFragment(R.layout.fragment_send) {
|
||||||
rv_warning_messages.addItemDecoration(SpacesItemDecoration(rv_warning_messages.dpToPx(16f).toInt()))
|
rv_warning_messages.addItemDecoration(SpacesItemDecoration(rv_warning_messages.dpToPx(16f).toInt()))
|
||||||
rv_warning_messages.adapter = warningsAdapter
|
rv_warning_messages.adapter = warningsAdapter
|
||||||
|
|
||||||
val warnings = store.state.globalState.warningManager?.getWarnings(WarningMessage.Location.SendScreen) ?: listOf()
|
store.dispatch(SendAction.Warnings.Update)
|
||||||
store.dispatch(SendAction.SetWarnings(warnings))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun subscribeToStore() {
|
override fun subscribeToStore() {
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,8 @@ sealed class WalletAction : Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
object CheckIfNeeded : Warnings()
|
object CheckIfNeeded : Warnings()
|
||||||
data class SetWarnings(val warningList: List<WarningMessage>) : Warnings()
|
object Update : Warnings()
|
||||||
|
data class Set(val warningList: List<WarningMessage>) : Warnings()
|
||||||
|
|
||||||
object AppRating : Warnings() {
|
object AppRating : Warnings() {
|
||||||
object SetNeverToShow : Warnings()
|
object SetNeverToShow : Warnings()
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,9 @@ data class WalletState(
|
||||||
primaryWallet?.currencyData?.status != com.tangem.tap.features.wallet.ui.BalanceStatus.EmptyCard &&
|
primaryWallet?.currencyData?.status != com.tangem.tap.features.wallet.ui.BalanceStatus.EmptyCard &&
|
||||||
primaryWallet?.currencyData?.status != com.tangem.tap.features.wallet.ui.BalanceStatus.UnknownBlockchain
|
primaryWallet?.currencyData?.status != com.tangem.tap.features.wallet.ui.BalanceStatus.UnknownBlockchain
|
||||||
|
|
||||||
|
val blockchains: List<Blockchain>
|
||||||
|
get() = walletManagers.map { it.wallet.blockchain }
|
||||||
|
|
||||||
fun getWalletManager(currencyName: CryptoCurrencyName?): WalletManager? {
|
fun getWalletManager(currencyName: CryptoCurrencyName?): WalletManager? {
|
||||||
if (currencyName == null) return null
|
if (currencyName == null) return null
|
||||||
val walletManager = walletManagers.find { it.wallet.blockchain.currency == currencyName }
|
val walletManager = walletManagers.find { it.wallet.blockchain.currency == currencyName }
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import java.math.BigDecimal
|
||||||
class WarningsMiddleware {
|
class WarningsMiddleware {
|
||||||
fun handle(action: WalletAction.Warnings, globalState: GlobalState?) {
|
fun handle(action: WalletAction.Warnings, globalState: GlobalState?) {
|
||||||
when (action) {
|
when (action) {
|
||||||
|
WalletAction.Warnings.Update -> setWarningMessages()
|
||||||
is WalletAction.Warnings.CheckIfNeeded -> {
|
is WalletAction.Warnings.CheckIfNeeded -> {
|
||||||
showCardWarningsIfNeeded(globalState)
|
showCardWarningsIfNeeded(globalState)
|
||||||
val readyToShow = preferencesStorage.appRatingLaunchObserver.isReadyToShow()
|
val readyToShow = preferencesStorage.appRatingLaunchObserver.isReadyToShow()
|
||||||
|
|
@ -76,7 +77,7 @@ class WarningsMiddleware {
|
||||||
addWarningMessage(WarningMessagesManager.onlineVerificationFailed())
|
addWarningMessage(WarningMessagesManager.onlineVerificationFailed())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateWarningMessages()
|
setWarningMessages()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,11 +131,15 @@ class WarningsMiddleware {
|
||||||
|
|
||||||
private fun addWarningMessage(warning: WarningMessage, autoUpdate: Boolean = false) {
|
private fun addWarningMessage(warning: WarningMessage, autoUpdate: Boolean = false) {
|
||||||
store.state.globalState.warningManager?.addWarning(warning)
|
store.state.globalState.warningManager?.addWarning(warning)
|
||||||
if (autoUpdate) updateWarningMessages()
|
if (autoUpdate) setWarningMessages()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateWarningMessages() {
|
private fun setWarningMessages() {
|
||||||
val warningManager = store.state.globalState.warningManager ?: return
|
store.dispatch(WalletAction.Warnings.Set(getWarnings()))
|
||||||
store.dispatch(WalletAction.Warnings.SetWarnings(warningManager.getWarnings(WarningMessage.Location.MainScreen)))
|
}
|
||||||
|
|
||||||
|
private fun getWarnings(): List<WarningMessage> {
|
||||||
|
val warningManager = store.state.globalState.warningManager ?: return emptyList()
|
||||||
|
return warningManager.getWarnings(WarningMessage.Location.MainScreen, store.state.walletState.blockchains)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -294,16 +294,10 @@ fun createAddressList(wallet: Wallet?, walletAddresses: WalletAddresses? = null)
|
||||||
|
|
||||||
private fun handleCheckSignedHashesActions(action: WalletAction.Warnings, state: WalletState): WalletState {
|
private fun handleCheckSignedHashesActions(action: WalletAction.Warnings, state: WalletState): WalletState {
|
||||||
return when (action) {
|
return when (action) {
|
||||||
WalletAction.Warnings.CheckHashesCount.CheckHashesCountOnline -> state
|
|
||||||
WalletAction.Warnings.CheckHashesCount.ConfirmHashesCount -> state.copy(hashesCountVerified = true)
|
WalletAction.Warnings.CheckHashesCount.ConfirmHashesCount -> state.copy(hashesCountVerified = true)
|
||||||
WalletAction.Warnings.CheckHashesCount.NeedToCheckHashesCountOnline -> state.copy(hashesCountVerified = false)
|
WalletAction.Warnings.CheckHashesCount.NeedToCheckHashesCountOnline -> state.copy(hashesCountVerified = false)
|
||||||
WalletAction.Warnings.CheckHashesCount.SaveCardId -> state
|
is WalletAction.Warnings.Set -> state.copy(mainWarningsList = action.warningList)
|
||||||
is WalletAction.Warnings.SetWarnings -> state.copy(mainWarningsList = action.warningList)
|
else -> state
|
||||||
WalletAction.Warnings.CheckIfNeeded -> state
|
|
||||||
WalletAction.Warnings.AppRating -> state
|
|
||||||
WalletAction.Warnings.CheckHashesCount -> state
|
|
||||||
WalletAction.Warnings.AppRating.RemindLater -> state
|
|
||||||
WalletAction.Warnings.AppRating.SetNeverToShow -> state
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue