Updated on 2026-08-14

This commit is contained in:
Tangem 2021-11-03 16:42:43 +03:00
parent fb3d9cd2d6
commit 939f6e87b6
17 changed files with 129 additions and 81 deletions

View file

@ -37,7 +37,7 @@ private val homeMiddleware: Middleware<AppState> = { dispatch, state ->
when (action) {
is HomeAction.Init -> {
store.dispatch(GlobalAction.RestoreAppCurrency)
store.dispatch(GlobalAction.GetMoonPayUserStatus)
store.dispatch(GlobalAction.GetMoonPayStatus)
store.dispatch(HomeAction.SetTermsOfUseState(preferencesStorage.wasDisclaimerAccepted()))
}
is HomeAction.ShouldScanCardOnResume -> {

View file

@ -26,7 +26,7 @@ data class OnboardingNoteState(
get() = steps.indexOf(currentStep)
val isBuyAllowed: Boolean by ReadOnlyProperty<Any, Boolean> { thisRef, property ->
store.state.globalState.moonPayUserStatus?.isBuyAllowed ?: false
store.state.globalState.moonpayStatus?.isBuyAllowed ?: false
}
}

View file

@ -56,7 +56,7 @@ data class TwinCardsState(
get() = currentStep == TwinCardsStep.CreateSecondWallet || currentStep == TwinCardsStep.CreateThirdWallet
val isBuyAllowed: Boolean by ReadOnlyProperty<Any, Boolean> { thisRef, property ->
store.state.globalState.moonPayUserStatus?.isBuyAllowed ?: false
store.state.globalState.moonpayStatus?.isBuyAllowed ?: false
}
}

View file

@ -9,6 +9,7 @@ import com.tangem.tap.common.redux.NotificationAction
import com.tangem.tap.domain.TapError
import com.tangem.tap.domain.configurable.warningMessage.WarningMessage
import com.tangem.tap.domain.tokens.CardCurrencies
import com.tangem.tap.network.moonpay.MoonpayStatus
import com.tangem.wallet.R
import org.rekotlin.Action
import java.math.BigDecimal
@ -25,7 +26,7 @@ sealed class WalletAction : Action {
data class LoadWallet(
val allowToSell: Boolean? = null, val allowToBuy: Boolean? = null,
val moonpayStatus: MoonpayStatus? = null,
val blockchain: Blockchain? = null,
) :
WalletAction() {

View file

@ -11,7 +11,6 @@ import com.tangem.tap.common.redux.global.CryptoCurrencyName
import com.tangem.tap.common.toggleWidget.WidgetState
import com.tangem.tap.domain.configurable.warningMessage.WarningMessage
import com.tangem.tap.domain.extensions.toSendableAmounts
import com.tangem.tap.domain.topup.TradeCryptoHelper
import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsState
import com.tangem.tap.features.wallet.models.PendingTransaction
import com.tangem.tap.features.wallet.models.toPendingTransactions
@ -38,7 +37,6 @@ data class WalletState(
val primaryBlockchain: Blockchain? = null,
val primaryToken: Token? = null,
val isTestnet: Boolean = false,
val tradeCryptoAllowed: TradeCryptoAvailability = TradeCryptoAvailability()
) : StateType {
// if you do not delegate - the application crashes on startup,
@ -221,12 +219,6 @@ data class TradeCryptoState(
val buyingAllowed: Boolean = false,
)
data class TradeCryptoAvailability(
val sellingAllowed: Boolean = false,
val buyingAllowed: Boolean = false,
val availableToSell: Set<String> = TradeCryptoHelper.AVAILABLE_TO_SELL,
)
data class WalletData(
val pendingTransactions: List<PendingTransaction> = emptyList(),
val hashesCountVerified: Boolean? = null,

View file

@ -54,7 +54,11 @@ class MultiWalletMiddleware {
}
}
store.dispatch(WalletAction.LoadFiatRate(currency = Currency.Blockchain(action.blockchain)))
store.dispatch(WalletAction.LoadWallet(blockchain = action.blockchain))
store.dispatch(WalletAction.LoadWallet(
moonpayStatus = globalState?.moonpayStatus,
blockchain = action.blockchain
)
)
}
is WalletAction.MultiWallet.SaveCurrencies -> {
val cardId = globalState?.scanResponse?.card?.cardId

View file

@ -38,11 +38,6 @@ class MultiWalletReducer {
walletAddresses = createAddressList(wallet),
mainButton = WalletMainButton.SendButton(false),
currency = Currency.Blockchain(blockchain),
tradeCryptoState = TradeCryptoState(
sellingAllowed = state.tradeCryptoAllowed.sellingAllowed &&
state.tradeCryptoAllowed.availableToSell.contains(blockchain.currency),
buyingAllowed = state.tradeCryptoAllowed.buyingAllowed
)
)
}
@ -67,11 +62,6 @@ class MultiWalletReducer {
walletAddresses = createAddressList(wallet),
mainButton = WalletMainButton.SendButton(false),
currency = Currency.Blockchain(action.blockchain),
tradeCryptoState = TradeCryptoState(
sellingAllowed = state.tradeCryptoAllowed.sellingAllowed &&
state.tradeCryptoAllowed.availableToSell.contains(action.blockchain.currency),
buyingAllowed = state.tradeCryptoAllowed.buyingAllowed
)
)
val newState = state.copy(wallets = state.replaceWalletInWallets(walletData))
if (wallet != null && wallet.amounts[AmountType.Coin]?.value != null) {
@ -173,10 +163,5 @@ fun Token.toWallet(state: WalletState): WalletData? {
walletAddresses = walletAddresses,
mainButton = WalletMainButton.SendButton(false),
currency = Currency.Token(this),
tradeCryptoState = TradeCryptoState(
sellingAllowed = state.tradeCryptoAllowed.sellingAllowed &&
state.tradeCryptoAllowed.availableToSell.contains(this.symbol),
buyingAllowed = state.tradeCryptoAllowed.buyingAllowed
)
)
}

View file

@ -96,21 +96,18 @@ private fun internalReduce(action: Action, state: AppState): WalletState {
),
mainButton = WalletMainButton.SendButton(false),
tradeCryptoState = TradeCryptoState(
sellingAllowed = action.allowToSell ?: wallet.tradeCryptoState.sellingAllowed &&
state.walletState.tradeCryptoAllowed.availableToSell.contains(wallet.currencyData.currencySymbol),
buyingAllowed = action.allowToBuy
?: wallet.tradeCryptoState.buyingAllowed
sellingAllowed = action.moonpayStatus?.availableToSell?.contains(
wallet.currencyData.currencySymbol
) ?: wallet.tradeCryptoState.sellingAllowed,
buyingAllowed = action.moonpayStatus?.availableToBuy?.contains(
wallet.currencyData.currencySymbol
) ?: wallet.tradeCryptoState.buyingAllowed
)
)
}
val tradeCryptoAllowed = TradeCryptoAvailability(
sellingAllowed = action.allowToSell ?: false,
buyingAllowed = action.allowToBuy ?: false
)
newState = newState.copy(
state = ProgressState.Loading,
wallets = wallets,
tradeCryptoAllowed = tradeCryptoAllowed
)
} else {
val walletManager = newState.getWalletManager(action.blockchain) ?: return newState
@ -127,10 +124,12 @@ private fun internalReduce(action: Action, state: AppState): WalletState {
),
mainButton = WalletMainButton.SendButton(false),
tradeCryptoState = TradeCryptoState(
sellingAllowed = action.allowToSell ?: wallet.tradeCryptoState.sellingAllowed &&
state.walletState.tradeCryptoAllowed.availableToSell.contains(wallet.currencyData.currencySymbol),
buyingAllowed = action.allowToBuy
?: wallet.tradeCryptoState.buyingAllowed
sellingAllowed = action.moonpayStatus?.availableToSell?.contains(
wallet.currencyData.currencySymbol
) ?: wallet.tradeCryptoState.sellingAllowed,
buyingAllowed = action.moonpayStatus?.availableToBuy?.contains(
wallet.currencyData.currencySymbol
) ?: wallet.tradeCryptoState.buyingAllowed
)
)
}

View file

@ -127,8 +127,6 @@ class WalletDetailsFragment : Fragment(R.layout.fragment_wallet_details), StoreS
srl_wallet_details.setOnRefreshListener {
if (selectedWallet.currencyData.status != BalanceStatus.Loading) {
store.dispatch(WalletAction.LoadWallet(
allowToBuy = selectedWallet.tradeCryptoState.buyingAllowed,
allowToSell = selectedWallet.tradeCryptoState.sellingAllowed,
blockchain = selectedWallet.currency?.blockchain
))
}