Updated on 2026-08-14
This commit is contained in:
parent
673a68436b
commit
0991215768
5 changed files with 40 additions and 30 deletions
|
|
@ -0,0 +1,19 @@
|
|||
package com.tangem.tap.domain.extensions
|
||||
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.tap.network.moonpay.MoonpayStatus
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
fun MoonpayStatus.buyIsAllowed(blockchain: Blockchain): Boolean {
|
||||
if (blockchain == Blockchain.Unknown || blockchain == Blockchain.BSC) return false
|
||||
|
||||
return isBuyAllowed && availableToBuy.contains(blockchain.currency)
|
||||
}
|
||||
|
||||
fun MoonpayStatus.sellIsAllowed(blockchain: Blockchain): Boolean {
|
||||
if (blockchain == Blockchain.Unknown || blockchain == Blockchain.BSC) return false
|
||||
|
||||
return isSellAllowed && availableToSell.contains(blockchain.currency)
|
||||
}
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
package com.tangem.tap.features.onboarding.products.note.redux
|
||||
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.WalletManager
|
||||
import com.tangem.tap.domain.TapError
|
||||
import com.tangem.tap.domain.extensions.buyIsAllowed
|
||||
import com.tangem.tap.features.onboarding.OnboardingWalletBalance
|
||||
import com.tangem.tap.network.moonpay.MoonpayStatus
|
||||
import com.tangem.tap.store
|
||||
import org.rekotlin.StateType
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
|
|
@ -28,16 +27,10 @@ data class OnboardingNoteState(
|
|||
get() = steps.indexOf(currentStep)
|
||||
|
||||
val isBuyAllowed: Boolean by ReadOnlyProperty<Any, Boolean> { thisRef, property ->
|
||||
store.state.globalState.moonpayStatus?.canBuy(walletBalance) ?: false
|
||||
store.state.globalState.moonpayStatus?.buyIsAllowed(walletBalance.currency.blockchain) ?: false
|
||||
}
|
||||
}
|
||||
|
||||
fun MoonpayStatus.canBuy(walletBalance: OnboardingWalletBalance): Boolean {
|
||||
if (walletBalance.currency.blockchain == Blockchain.Unknown) return false
|
||||
|
||||
return isBuyAllowed && availableToBuy.contains(walletBalance.currency.currencySymbol)
|
||||
}
|
||||
|
||||
enum class OnboardingNoteStep {
|
||||
None, CreateWallet, TopUpWallet, Done
|
||||
}
|
||||
|
|
@ -2,10 +2,10 @@ package com.tangem.tap.features.onboarding.products.twins.redux
|
|||
|
||||
import com.tangem.blockchain.common.WalletManager
|
||||
import com.tangem.tap.domain.TapError
|
||||
import com.tangem.tap.domain.extensions.buyIsAllowed
|
||||
import com.tangem.tap.domain.twins.TwinCardNumber
|
||||
import com.tangem.tap.domain.twins.TwinCardsManager
|
||||
import com.tangem.tap.features.onboarding.OnboardingWalletBalance
|
||||
import com.tangem.tap.features.onboarding.products.note.redux.canBuy
|
||||
import com.tangem.tap.store
|
||||
import org.rekotlin.StateType
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
|
|
@ -57,7 +57,7 @@ data class TwinCardsState(
|
|||
get() = currentStep == TwinCardsStep.CreateSecondWallet || currentStep == TwinCardsStep.CreateThirdWallet
|
||||
|
||||
val isBuyAllowed: Boolean by ReadOnlyProperty<Any, Boolean> { thisRef, property ->
|
||||
store.state.globalState.moonpayStatus?.canBuy(walletBalance) ?: false
|
||||
store.state.globalState.moonpayStatus?.buyIsAllowed(walletBalance.currency.blockchain) ?: false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import com.tangem.tap.common.redux.StateDialog
|
|||
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.buyIsAllowed
|
||||
import com.tangem.tap.domain.extensions.sellIsAllowed
|
||||
import com.tangem.tap.domain.extensions.toSendableAmounts
|
||||
import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsState
|
||||
import com.tangem.tap.features.wallet.models.PendingTransaction
|
||||
|
|
@ -17,6 +19,7 @@ import com.tangem.tap.features.wallet.models.toPendingTransactions
|
|||
import com.tangem.tap.features.wallet.models.toPendingTransactionsForToken
|
||||
import com.tangem.tap.features.wallet.ui.BalanceStatus
|
||||
import com.tangem.tap.features.wallet.ui.BalanceWidgetData
|
||||
import com.tangem.tap.network.moonpay.MoonpayStatus
|
||||
import com.tangem.tap.store
|
||||
import org.rekotlin.StateType
|
||||
import java.math.BigDecimal
|
||||
|
|
@ -144,9 +147,9 @@ data class WalletState(
|
|||
|
||||
fun replaceSomeWallets(newWallets: List<WalletData>): List<WalletData> {
|
||||
val remainingWallets: MutableList<WalletData> = newWallets.toMutableList()
|
||||
val updatedWallets = wallets.map { wallet ->
|
||||
val updatedWallets = wallets.map { wallet ->
|
||||
val newWallet = newWallets
|
||||
.firstOrNull { wallet.currencyData.currency == it.currencyData.currency }
|
||||
.firstOrNull { wallet.currencyData.currency == it.currencyData.currency }
|
||||
if (newWallet == null) {
|
||||
wallet
|
||||
} else {
|
||||
|
|
@ -217,7 +220,16 @@ data class Artwork(
|
|||
data class TradeCryptoState(
|
||||
val sellingAllowed: Boolean = false,
|
||||
val buyingAllowed: Boolean = false,
|
||||
)
|
||||
) {
|
||||
companion object {
|
||||
fun from(moonpayStatus: MoonpayStatus?, walletData: WalletData): TradeCryptoState {
|
||||
val status = moonpayStatus ?: return walletData.tradeCryptoState
|
||||
val blockchain = walletData.currency?.blockchain ?: return walletData.tradeCryptoState
|
||||
|
||||
return TradeCryptoState(status.sellIsAllowed(blockchain), status.buyIsAllowed(blockchain))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class WalletData(
|
||||
val pendingTransactions: List<PendingTransaction> = emptyList(),
|
||||
|
|
|
|||
|
|
@ -95,14 +95,7 @@ private fun internalReduce(action: Action, state: AppState): WalletState {
|
|||
currencySymbol = wallet.currencyData.currencySymbol,
|
||||
),
|
||||
mainButton = WalletMainButton.SendButton(false),
|
||||
tradeCryptoState = TradeCryptoState(
|
||||
sellingAllowed = action.moonpayStatus?.availableToSell?.contains(
|
||||
wallet.currencyData.currencySymbol
|
||||
) ?: wallet.tradeCryptoState.sellingAllowed,
|
||||
buyingAllowed = action.moonpayStatus?.availableToBuy?.contains(
|
||||
wallet.currencyData.currencySymbol
|
||||
) ?: wallet.tradeCryptoState.buyingAllowed
|
||||
)
|
||||
tradeCryptoState = TradeCryptoState.from(action.moonpayStatus, wallet)
|
||||
)
|
||||
}
|
||||
newState = newState.copy(
|
||||
|
|
@ -123,14 +116,7 @@ private fun internalReduce(action: Action, state: AppState): WalletState {
|
|||
currencySymbol = wallet.currencyData.currencySymbol,
|
||||
),
|
||||
mainButton = WalletMainButton.SendButton(false),
|
||||
tradeCryptoState = TradeCryptoState(
|
||||
sellingAllowed = action.moonpayStatus?.availableToSell?.contains(
|
||||
wallet.currencyData.currencySymbol
|
||||
) ?: wallet.tradeCryptoState.sellingAllowed,
|
||||
buyingAllowed = action.moonpayStatus?.availableToBuy?.contains(
|
||||
wallet.currencyData.currencySymbol
|
||||
) ?: wallet.tradeCryptoState.buyingAllowed
|
||||
)
|
||||
tradeCryptoState = TradeCryptoState.from(action.moonpayStatus, wallet)
|
||||
)
|
||||
}
|
||||
val wallets = newState.replaceSomeWallets(newWallets)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue